public async Task <bool> ChangeUsername(string oldUsername, string newUsername) { var user = _context.Users.FirstOrDefault <User>(x => x.Id == _sessionService.User.Id); if (user != null) { if (string.IsNullOrEmpty(newUsername)) { return(false); } if (user.Username.ToLower() == oldUsername.ToLower()) { user.Username = newUsername; _context.Entry(user).State = System.Data.Entity.EntityState.Modified; } } return(await _context.SaveChangesAsync() > 0); }
public ActionResult EditControl(QuestionControl questionControl) { if (ModelState.IsValid) { questionControl.UpdatedDate = DateTime.Now; db.Entry(questionControl).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(questionControl)); }
public ActionResult EditQuestion(AddQuestionViewModels questionModel) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } var question = new Question(); var questionAttr = new QuestionAttribute(); question.Id = questionModel.Id; question.Label = questionModel.Label; question.Description = questionModel.Description; question.ControlId = questionModel.ControlId; question.UpdatedDate = DateTime.Now; db.Entry(question).State = EntityState.Modified; db.SaveChanges(); foreach (var item in questionModel.QuestionAttributes) { questionAttr.Name = item.Name; questionAttr.Value = item.Value; questionAttr.QuestionId = questionModel.Id; questionAttr.UpdatedDate = DateTime.Now; db.questionAttributes.Add(questionAttr); } foreach (var id in questionModel.DeletedQuestionAttributes) { var DeleteItem = db.questionAttributes.Find(id); db.questionAttributes.Remove(DeleteItem); } db.SaveChanges(); return(RedirectToAction("Index")); }
//update public void Update <T>(T entity) where T : class { _context.Entry <T>(entity).State = EntityState.Modified; }