public async Task <ActionResult> Edit(UserViewModel userModel) { if (!await _userService.CanChangeEmail(userModel.Email, userModel.Id)) { ModelState.AddModelError("", "پست الکترنیکی وارد شده قبلا در سیستم ثبت شده است."); return(this.JsonValidationErrors()); } var user = new DomainClasses.User() { Id = userModel.Id, Email = userModel.Email, FirstName = userModel.FirstName, LastName = userModel.LastName, Role = userModel.Role }; if (!string.IsNullOrEmpty(userModel.Password)) { user.Password = EncryptionHelper.Encrypt(userModel.Password, EncryptionHelper.Key); } _userService.Edit(user); await _dbContext.SaveChangesAsync(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public async Task<ActionResult> Edit(UserViewModel userModel) { if (!await _userService.CanChangeEmail(userModel.Email, userModel.Id)) { ModelState.AddModelError("", "پست الکترنیکی وارد شده قبلا در سیستم ثبت شده است."); return this.JsonValidationErrors(); } var user = new DomainClasses.User() { Id = userModel.Id, Email = userModel.Email, FirstName = userModel.FirstName, LastName = userModel.LastName, Role = userModel.Role }; if (!string.IsNullOrEmpty(userModel.Password)) user.Password = EncryptionHelper.Encrypt(userModel.Password, EncryptionHelper.Key); _userService.Edit(user); await _dbContext.SaveChangesAsync(); return new HttpStatusCodeResult(HttpStatusCode.OK); }
public void Edit(DomainClasses.User user) { _users.Attach(user); if (!string.IsNullOrEmpty(user.Password)) { _dbContext.Entry(user).Property(u => u.Password).IsModified = true; } _dbContext.Entry(user).Property(u => u.Email).IsModified = true; _dbContext.Entry(user).Property(u => u.FirstName).IsModified = true; _dbContext.Entry(user).Property(u => u.LastName).IsModified = true; _dbContext.Entry(user).Property(u => u.Role).IsModified = true; }
public void Add(DomainClasses.User user) { _users.Add(user); }