コード例 #1
0
        public ActionResult Edit(EditUserViewModel user)
        {
            if(!ModelState.IsValid)
            {
                var results = ModelState
                    .Where(m => m.Value.Errors.Count > 0)
                    .Select(m => new { Field = m.Key, Message = m.Value.Errors[0].ErrorMessage }).ToArray();

                //ModelState.AddModelError("", "error message");

                Response.StatusCode = 400;

                return Json(results);
            }

            SaveUser(user);

            Response.StatusCode = 200;

            return Json("OK");
        }
コード例 #2
0
        private void SaveUser(EditUserViewModel user)
        {
            UserModel dbUser = usersRepository.GetByID(user.UserId);

            dbUser.FirstName = user.FirstName;
            dbUser.LastName = user.LastName;
            dbUser.Email = user.Email;

            usersRepository.Save();
        }
コード例 #3
0
        public ActionResult Manage(EditUserViewModel user)
        {
            UserModel currentUser = GetCurrentUser();

            if (!currentUser.IsAdmin && currentUser.UserId != user.UserId)
            {
                return RedirectToAction("index", "home");
            }

            if (!ModelState.IsValid)
            {
                return Manage(user.UserId);
            }

            SaveUser(user);

            return RedirectToAction("index", "home");
        }