コード例 #1
0
        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);
        }
コード例 #2
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));
 }
コード例 #3
0
        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"));
        }
コード例 #4
0
 //update
 public void Update <T>(T entity) where T : class
 {
     _context.Entry <T>(entity).State = EntityState.Modified;
 }