diff --git a/BACK_END/.vs/MY_CALS_BACKEND/v16/.suo b/BACK_END/.vs/MY_CALS_BACKEND/v16/.suo index dfc0c09..7f1cd6e 100644 Binary files a/BACK_END/.vs/MY_CALS_BACKEND/v16/.suo and b/BACK_END/.vs/MY_CALS_BACKEND/v16/.suo differ diff --git a/BACK_END/Controllers/AdminController.cs b/BACK_END/Controllers/AdminController.cs index 1be4955..8bec275 100644 --- a/BACK_END/Controllers/AdminController.cs +++ b/BACK_END/Controllers/AdminController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +using MY_CALS_BACKEND.Dto; using MY_CALS_BACKEND.Dto.Meals; using MY_CALS_BACKEND.Dto.UserAccount; using MY_CALS_BACKEND.Models; @@ -24,15 +25,17 @@ public class AdminController : ControllerBase private readonly IRepoMeals _repoMeals; private readonly IMapper _mapper; private readonly UserManager _userManager; + private readonly RoleManager _roleManager; private int userId; - public AdminController(IRepoUserAccount repoUserAccount, IMapper mapper, UserManager userManager, IHttpContextAccessor httpContextAccessor, IRepoMeals repoMeals) + public AdminController(IRepoUserAccount repoUserAccount, IMapper mapper, UserManager userManager, RoleManager roleManager, IHttpContextAccessor httpContextAccessor, IRepoMeals repoMeals) { _repoUserAccount = repoUserAccount; _repoMeals = repoMeals; _mapper = mapper; _userManager = userManager; + _roleManager = roleManager; userId = Int32.Parse(httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); } @@ -56,6 +59,7 @@ public async Task GetUsers() return Ok(usersForDisplayDTO); } + [HttpGet("users/{id}")] public async Task GetUserInfo(int id) { @@ -74,6 +78,48 @@ public async Task GetUserInfo(int id) return NotFound("This user dosen't existe 💢 "); } + [HttpPost("addmanager")] + public async Task AddManger(UserRegisterDTO userRegisterDTO) + { + var checkedEmail = await _userManager.FindByEmailAsync(userRegisterDTO.Email); + + var user = _mapper.Map(userRegisterDTO); + + if (checkedEmail != null) + { + return BadRequest("This email already exist try again"); + } + else + { + user.UserName = userRegisterDTO.Email.Split("@")[0] + userRegisterDTO.Email.Split("@")[1]; + } + + if (await _roleManager.RoleExistsAsync("Admin") == false && await _roleManager.RoleExistsAsync("Manager") == false && await _roleManager.RoleExistsAsync("User") == false) + { + var roles = new List{ + new Role{Name="Admin"}, + new Role{Name="Manager"}, + new Role{Name="User"}, + + }; + + foreach (var role in roles) + { + await _roleManager.CreateAsync(role); + } + } + + var Result = await _userManager.CreateAsync(user, userRegisterDTO.Password); + + if (Result.Succeeded) + { + //var confirmaEmailToken = await _userManager.GenerateEmailConfirmationTokenAsync(user); + await _userManager.AddToRoleAsync(user, userRegisterDTO.Role); + return Ok("User Created Successfully"); + } + return BadRequest(Result.Errors); + } + [HttpGet("users/{id}/meals")] public async Task GetUserMeals(int id) @@ -98,7 +144,6 @@ public async Task GetUserMeals(int id) } [HttpGet("users/{id}/meals/{id_meal}")] - public async Task GetUserMeal(int id, int id_meal) { var user = await _repoUserAccount.GetUserById(id); @@ -120,7 +165,6 @@ public async Task GetUserMeal(int id, int id_meal) } [HttpDelete("users/{id}/meals/{id_meal}/delete")] - public async Task DeleteUserMeal(int id, int id_meal) { var user = await _repoUserAccount.GetUserById(id); @@ -142,7 +186,6 @@ public async Task DeleteUserMeal(int id, int id_meal) } [HttpPut("users/{id}/meals/{id_meal}/edit")] - public async Task EditUserMeal(int id, int id_meal,MealForEditDTO mealForEditDTO) { var user = await _repoUserAccount.GetUserById(id); @@ -152,11 +195,7 @@ public async Task EditUserMeal(int id, int id_meal,MealForEditDTO { await _repoMeals.EditMeal(id_meal,mealForEditDTO) ; var result = await _repoMeals.SaveMeal(); - if (result) - { - return Ok("This Meal has been updated successfully 👍 !!!"); - } - return NotFound("This meal dosen't existe 💢!!!"); + return result ? Ok("This Meal has been updated successfully 👍 !!!") : (IActionResult)NotFound("This meal dosen't existe 💢!!!"); } return BadRequest("Bad Action 😑 !!!"); } diff --git a/BACK_END/appsettings.json b/BACK_END/appsettings.json index 6ac6b4f..10a2392 100644 --- a/BACK_END/appsettings.json +++ b/BACK_END/appsettings.json @@ -6,9 +6,9 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "ConnectionStrings": { - "SqlConnection": "Server=DESKTOP-6DGS6FK;Initial Catalog=MyCalcsDB; Integrated Security=true;" - }, + "ConnectionStrings": { + "SqlConnection": "Server=DESKTOP-3C9CT52;Initial Catalog=MyCalcsDB; Integrated Security=true;" + }, "AllowedHosts": "*", "AppSettings": { diff --git a/BACK_END/bin/Debug/netcoreapp3.1/MY_CALS_BACKEND.dll b/BACK_END/bin/Debug/netcoreapp3.1/MY_CALS_BACKEND.dll index 53a0e2f..59191f1 100644 Binary files a/BACK_END/bin/Debug/netcoreapp3.1/MY_CALS_BACKEND.dll and b/BACK_END/bin/Debug/netcoreapp3.1/MY_CALS_BACKEND.dll differ diff --git a/BACK_END/bin/Debug/netcoreapp3.1/MY_CALS_BACKEND.exe b/BACK_END/bin/Debug/netcoreapp3.1/MY_CALS_BACKEND.exe index 46767c3..9252b6d 100644 Binary files a/BACK_END/bin/Debug/netcoreapp3.1/MY_CALS_BACKEND.exe and b/BACK_END/bin/Debug/netcoreapp3.1/MY_CALS_BACKEND.exe differ diff --git a/BACK_END/bin/Debug/netcoreapp3.1/MY_CALS_BACKEND.pdb b/BACK_END/bin/Debug/netcoreapp3.1/MY_CALS_BACKEND.pdb index dda02fa..4081cce 100644 Binary files a/BACK_END/bin/Debug/netcoreapp3.1/MY_CALS_BACKEND.pdb and b/BACK_END/bin/Debug/netcoreapp3.1/MY_CALS_BACKEND.pdb differ diff --git a/BACK_END/bin/Debug/netcoreapp3.1/appsettings.json b/BACK_END/bin/Debug/netcoreapp3.1/appsettings.json index 6ac6b4f..10a2392 100644 --- a/BACK_END/bin/Debug/netcoreapp3.1/appsettings.json +++ b/BACK_END/bin/Debug/netcoreapp3.1/appsettings.json @@ -6,9 +6,9 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "ConnectionStrings": { - "SqlConnection": "Server=DESKTOP-6DGS6FK;Initial Catalog=MyCalcsDB; Integrated Security=true;" - }, + "ConnectionStrings": { + "SqlConnection": "Server=DESKTOP-3C9CT52;Initial Catalog=MyCalcsDB; Integrated Security=true;" + }, "AllowedHosts": "*", "AppSettings": { diff --git a/BACK_END/obj/Debug/netcoreapp3.1/MY_CALS_BACKEND.dll b/BACK_END/obj/Debug/netcoreapp3.1/MY_CALS_BACKEND.dll index 53a0e2f..59191f1 100644 Binary files a/BACK_END/obj/Debug/netcoreapp3.1/MY_CALS_BACKEND.dll and b/BACK_END/obj/Debug/netcoreapp3.1/MY_CALS_BACKEND.dll differ diff --git a/BACK_END/obj/Debug/netcoreapp3.1/MY_CALS_BACKEND.pdb b/BACK_END/obj/Debug/netcoreapp3.1/MY_CALS_BACKEND.pdb index dda02fa..4081cce 100644 Binary files a/BACK_END/obj/Debug/netcoreapp3.1/MY_CALS_BACKEND.pdb and b/BACK_END/obj/Debug/netcoreapp3.1/MY_CALS_BACKEND.pdb differ diff --git a/BACK_END/obj/Debug/netcoreapp3.1/apphost.exe b/BACK_END/obj/Debug/netcoreapp3.1/apphost.exe index 46767c3..9252b6d 100644 Binary files a/BACK_END/obj/Debug/netcoreapp3.1/apphost.exe and b/BACK_END/obj/Debug/netcoreapp3.1/apphost.exe differ diff --git a/BACK_END/obj/MY_CALS_BACKEND.csproj.nuget.dgspec.json b/BACK_END/obj/MY_CALS_BACKEND.csproj.nuget.dgspec.json index 48853c6..295e8aa 100644 --- a/BACK_END/obj/MY_CALS_BACKEND.csproj.nuget.dgspec.json +++ b/BACK_END/obj/MY_CALS_BACKEND.csproj.nuget.dgspec.json @@ -109,7 +109,7 @@ "privateAssets": "all" } }, - "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.301\\RuntimeIdentifierGraph.json" + "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.302\\RuntimeIdentifierGraph.json" } } } diff --git a/BACK_END/obj/project.assets.json b/BACK_END/obj/project.assets.json index 16081d4..3dbfa1e 100644 --- a/BACK_END/obj/project.assets.json +++ b/BACK_END/obj/project.assets.json @@ -8298,7 +8298,7 @@ "privateAssets": "all" } }, - "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.301\\RuntimeIdentifierGraph.json" + "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.302\\RuntimeIdentifierGraph.json" } } } diff --git a/BACK_END/obj/project.nuget.cache b/BACK_END/obj/project.nuget.cache index 525ebe1..e037ed3 100644 --- a/BACK_END/obj/project.nuget.cache +++ b/BACK_END/obj/project.nuget.cache @@ -1,6 +1,6 @@ { "version": 2, - "dgSpecHash": "p2yO5o88DbyD1rcPceRN4QN4HkG6vfwvtBs/JX60N4UromIzpoPcoZr2yd/y4wHS22umijnDlYtNh1rY1gJVIA==", + "dgSpecHash": "NShQTHv1wkbakI/OgyLobEcYfF+8ptlpARym0cYOeF9YDtDDaz3YJLoR/yqZq/XhZbZm24G/rbMNZj/qabkQcQ==", "success": true, "projectFilePath": "E:\\User_ID\\Data\\Dev\\Builds .NET\\.NET Core\\MyCals\\BACK_END\\MY_CALS_BACKEND.csproj", "expectedPackageFiles": [