public async Task <ResponseModel> Update(EmployeeModel model) { ResponseModel response = new ResponseModel(); try { await _context.BeginTransactionAsync().ConfigureAwait(true); Employee md = await _context.EmployeeRepository.FirstOrDefaultAsync(m => m.Id == model.Id); if (!md.RowVersion.SequenceEqual(model.RowVersion)) { response.ResponseStatus = Core.CommonModel.Enums.ResponseStatus.OutOfDateData; return(response); } md.ProbationDate = model.ProbationDate; md.StartWorkingDate = model.StartWorkingDate; md.BadgeCardNumber = model.BadgeCardNumber ?? ""; md.DateApplyBadge = model.DateApplyBadge; md.FingerSignNumber = model.FingerSignNumber ?? ""; md.DateApplyFingerSign = model.DateApplyFingerSign; md.WorkingEmail = model.WorkingEmail ?? ""; md.WorkingPhone = model.WorkingPhone ?? ""; md.EmployeeWorkingStatusId = model.EmployeeWorkingStatusId; md.BasicSalary = model.BasicSalary; md.IsActive = model.IsActive; md.UpdateBy = base.UserId; md.UpdateDate = DateTime.Now; if (model.File != null) { FileModel fileModel = new FileModel() { File = model.File, EmployeeCode = model.EmployeeCode, Id = md.AvatarFileId.HasValue ? md.AvatarFileId.Value : 0 }; response = await _imageServerService.Update(fileModel); if (response.ResponseStatus != Core.CommonModel.Enums.ResponseStatus.Success) { await _context.RollbackTransactionAsync(); return(response); } md.AvatarFileId = int.Parse(response.Result.ToString()); } _context.EmployeeRepository.Update(md); await _context.SaveChangesAsync(); response = await _employeeInfoService.UpdateName(model.Id, model.FirstName, model.LastName); if (response.ResponseStatus != Core.CommonModel.Enums.ResponseStatus.Success) { await _context.RollbackTransactionAsync(); return(response); } response = await Item(model.Id); await _context.CommitTransactionAsync(); } catch (Exception ex) { await _context.RollbackTransactionAsync(); throw ex; } return(response); }