internal void Edit(RecipeEditViewModel model) { var userService = new UserService(_context, _httpContext); var cleranceLevel = userService.GetCurrentUserCleranceLevel(); var recipe = GetById(model.Id); if (cleranceLevel.Level < recipe.ClassificationLevel.Level) { return; } var controlLevelService = new ControlLevelService(_context); var classificationLevelId = controlLevelService.GetIdByLevel(model.ClassificationLevel); var authorId = userService.GetCurrentUserId(); recipe.Id = model.Id; recipe.Name = model.Name; recipe.Text = model.Text; recipe.ClassificationLevelId = classificationLevelId; recipe.AuthorId = authorId; _context.Entry(recipe).State = EntityState.Modified; }
public async Task <IdentityResult> Add(UserCreateViewModel model) { var controlLevelService = new ControlLevelService(_context); var cleranceLevelId = controlLevelService.GetIdByLevel(model.CleranceLevel); var userInfo = new User { Name = model.Username, Email = model.Email, CleranceLevelId = cleranceLevelId }; var user = new ApplicationUser { UserName = model.Username, Email = model.Email, UserInfo = userInfo }; var userManager = _httpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); return(await userManager.CreateAsync(user, model.Password)); }
public void Add(RecipeCreateViewModel model) { var controlLevelService = new ControlLevelService(_context); var classificationLevelId = controlLevelService.GetIdByLevel(model.ClassificationLevel); var userService = new UserService(_context, _httpContext); var authorId = userService.GetCurrentUserId(); var recipe = new Recipe { Name = model.Name, Text = model.Text, ClassificationLevelId = classificationLevelId, AuthorId = authorId }; _context.Recipes.Add(recipe); }