public void UpdateCategory(User currentUser, Category cat) { var tmpCat = currentUser.Categories.First(x => x.CategoryId == cat.CategoryId); tmpCat.Name = cat.Name; tmpCat.Description = cat.Description; _context.SaveChanges(); }
public void UpdateTodo(User currentUser, Todo oldTodo,Todo newTodo) { /* var cTodo = _context.Users.First(u => u.UserId == currentUser.UserId) .Categories.First(cat => cat.CategoryId == oldTodo.Category.CategoryId) .Todos.First(todo => todo.TodoId == oldTodo.TodoId); */ if (oldTodo.Category.CategoryId != newTodo.Category.CategoryId) { oldTodo.Category.Todos.Remove(oldTodo); newTodo.Category.Todos.Add(newTodo); } else { oldTodo.ShortDescription = newTodo.ShortDescription; oldTodo.Description = newTodo.Description; oldTodo.StartDate = newTodo.StartDate; oldTodo.IsDone = newTodo.IsDone; oldTodo.EndDate = newTodo.EndDate; oldTodo.Priority = newTodo.Priority; } _context.SaveChanges(); }
public ActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { if (model.Password == model.RePassword) { var user = new User() { UserName = model.Email, Email = model.Email }; user.Initialize(); IdentityResult result = UserManager.Create(user, model.Password); if (result.Succeeded) { SignIn(user, true); return RedirectToAction("Index", "Home"); } foreach (var error in result.Errors) { ModelState.AddModelError("", error); } } ModelState.AddModelError("Password","Паролі не співпадають!"); } return View(model); }
private void SignIn(User user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, user.GenerateUserIdentity(UserManager)); }
public void DeleteCategory(User currentUser, Category cat) { currentUser.Categories.Remove(cat); _context.SaveChanges(); }
public void AddCategory(User currentUser, Category cat) { currentUser.Categories.Add(cat); _context.SaveChanges(); }