public async Task <IActionResult> Patch(int id, UserToEditDto userDto) { try { if (!await _serviceManager.User.Update(id, userDto)) { return(BadRequest()); } return(Ok()); } catch (System.Exception e) { return(HandleException(e)); } }
public async Task <bool> Update(int id, UserToEditDto entity) { var entityToUpdate = await this._unitOfWork.User.GetAll() .Include(x => x.UserRole) .Where(x => x.Id == id) .SingleOrDefaultAsync(); if (entityToUpdate == null) { throw new Exception("Not Found."); } entityToUpdate.UserRole = new List <UserRole>(); if (entity.UserRole.Count() > 0) { foreach (var userRole in entity.UserRole) { entityToUpdate.UserRole.Add(new UserRole { RoleId = userRole, UserId = id }); } } entityToUpdate.UserName = entity.Username; entityToUpdate.IsActive = entity.IsActive; entityToUpdate.Phone = entity.Phone; entityToUpdate.Email = entity.Email; entityToUpdate.Name = entity.Name; _unitOfWork.User.Update(entityToUpdate); if (_unitOfWork.Complete() > 0) { return(true); } return(false); }
public async Task <bool> Update(int id, UserToEditDto entity) { var entityToUpdate = await this._unitOfWork.User.Get(id); if (entityToUpdate == null) { throw new Exception("Not Found."); } entityToUpdate.Username = entity.Username; entityToUpdate.IsActive = entity.IsActive; entityToUpdate.Gender = entity.Gender; entityToUpdate.Email = entity.Email; entityToUpdate.Name = entity.Name; _unitOfWork.User.Update(entityToUpdate); if (_unitOfWork.Complete() > 0) { return(true); } return(false); }