//Create Userrole must be deleted after initialisation, I've let it stand because it's a testCase with a local db private async Task CreateUserRoles(IServiceProvider serviceProvider) { RoleManager <IdentityRole> roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >(); FoodiesContext foodiesContext = serviceProvider.GetRequiredService <FoodiesContext>(); IdentityResult roleResult; //Adding Admin Role bool roleCheck = await roleManager.RoleExistsAsync("Admin"); if (!roleCheck) { // create roles and seed them to the datebase roleResult = await roleManager.CreateAsync(new IdentityRole("Admin")); } bool loggedInUserRoleCheck = await roleManager.RoleExistsAsync("LoggedInUser"); if (!loggedInUserRoleCheck) { roleResult = await roleManager.CreateAsync(new IdentityRole("LoggedInUser")); } // Assign Admin Role to the main user ApplicationUser user = new ApplicationUser(); user.UserName = "******"; user.Email = "*****@*****.**"; PasswordHasher <ApplicationUser> password = new PasswordHasher <ApplicationUser>(); user.PasswordHash = password.HashPassword(user, "Test1234!"); user.EmailConfirmed = true; user.NormalizedEmail = user.Email.ToUpper(); user.NormalizedUserName = user.UserName.ToUpper(); user.EndUser = new EndUser { NickName = "LazyJay", Name = "Lazy", LastName = "Jay" }; foodiesContext.Users.Add(user); if (user != null) { DbSet <IdentityUserRole <string> > roles = foodiesContext.UserRoles; IdentityRole adminRole = foodiesContext.Roles.FirstOrDefault(roles => roles.Name == "Admin"); if (adminRole != null) { if (!roles.Any(Uri => Uri.UserId == user.Id && Uri.RoleId == adminRole.Id)) { roles.Add(new IdentityUserRole <string> { UserId = user.Id, RoleId = adminRole.Id }); foodiesContext.SaveChanges(); } } } }
public RegisterModel( UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, ILogger <RegisterModel> logger, IEmailSender emailSender, FoodiesContext context) { _userManager = userManager; _signInManager = signInManager; _logger = logger; _emailSender = emailSender; _context = context; }
public MealIngredientController(FoodiesContext context) { _context = context; }
public UnitController(FoodiesContext context) { _context = context; }
public HomeController(FoodiesContext context) { _context = context; }
public CategoryController(FoodiesContext context) { _context = context; }
public UnitOfWork(FoodiesContext context) { _context = context; }
public EndUserController(FoodiesContext context) { _context = context; }
public LevelPreperationController(FoodiesContext context) { _context = context; }
public PreperationTimeController(FoodiesContext context) { _context = context; }
//https://www.c-sharpcorner.com/article/upload-and-display-image-in-asp-net-core-3-1/ public MealController(FoodiesContext context, UserManager <ApplicationUser> userManager, IWebHostEnvironment hostEnvironment) { _context = context; _userManager = userManager; webHostEnvironment = hostEnvironment; }