Esempio n. 1
0
        public ActionResult Edit(UserEditViewModel viewModel, int id)
        {
            if (!ModelState.IsValid)
            {
                TempData.SetStatusMessage(GetModelErrorMessage(), UtilityEnum.StatusMessageType.Danger);
                return View(viewModel);
            }

            var result = UserBusiness.Edit(viewModel, id);
            if (!result.IsSuccess)
            {
                TempData.SetStatusMessage(result.Message, UtilityEnum.StatusMessageType.Danger);
                return View(viewModel);
            }

            TempData.SetStatusMessage(result.Message);
            return RedirectToAction("Index");
        }
Esempio n. 2
0
 public void InitEditViewModel(UserEditViewModel viewModel, int id)
 {
     var user = UserRepository.GetById(id);
     if (user == null || user.IsDeleted)
     {
         return;
     }
     viewModel.Email = user.Email;
     viewModel.FirstName = user.FirstName;
     viewModel.LastName = user.LastName;
     viewModel.IsActive = user.IsActive;
     viewModel.RoleId = user.RoleId;
     viewModel.Roles = RoleRepository.GetAll();
 }
Esempio n. 3
0
        public BaseModel Edit(UserEditViewModel viewModel, int id)
        {
            try
            {
                var user = UserRepository.GetById(id);
                if (user == null || user.IsDeleted)
                {
                    return new BaseModel(false, (int) HttpStatusCode.BadRequest, string.Format(Constants.Message.IsNotExists, "user"));
                }

                var isExistsEmail = UserRepository.Any(x => x.IsDeleted == false && x.Email == viewModel.Email && x.Id != id);
                if (isExistsEmail)
                {
                    return new BaseModel(false, (int)HttpStatusCode.BadRequest, string.Format(Constants.Message.IsExists, viewModel.Email));
                }

                user.Email = viewModel.Email;
                user.FirstName = viewModel.FirstName;
                user.LastName = viewModel.LastName;
                user.IsActive = viewModel.IsActive;
                user.RoleId = viewModel.RoleId;
                user.ModifiedDate = DateTimeHelper.UTCNow();

                UserRepository.Update(user);
                DbContext.SaveChanges();

                return new BaseModel(true, (int) HttpStatusCode.OK, string.Format(Constants.Message.SuccessToEdit, "user"));
            }
            catch (Exception ex)
            {
               Provider.Instance.LogError(ex);
               return new BaseModel(false, (int)HttpStatusCode.InternalServerError, ex.InnerException?.Message ?? ex.Message);
            }
        }
Esempio n. 4
0
 public ActionResult Edit(int id)
 {
     var viewModel = new UserEditViewModel();
     return View(viewModel);
 }