public async Task <ReturnModel <EEntity123Model> > UpdateEEntity123([FromBody] EEntity123UpdateModel eentity123Model) { return(await wipService.UpdateEEntity123Async(eentity123Model)); }
public async Task <ReturnModel <EEntity123Model> > UpdateEEntity123Async(EEntity123UpdateModel eentity123) { try { if (eentity123 == null) { return(log.ErrorAndReturnModel <EEntity123Model>($"Unable to update EEntity123", new ReturnErrorItem("", "EEntity123 information is not valid"))); } var existingEEntity123 = await wipRepository.GetEEntity123ViewFromAnyByGuidAndIdAsync(eentity123.EEntity123Id, eentity123.EEntity123Guid); if (existingEEntity123 == null) { return(log.ErrorAndReturnModel <EEntity123Model>($"Unable to find the eentity123 for {eentity123.EEntity123Id} and {eentity123.EEntity123Guid}")); } var(resultValue, canAssign, errorStr) = await permissionService.GetCanManageEEntity123PermissionParamsAsync(existingEEntity123.TenantId, existingEEntity123.TenantEntityId); if (resultValue == false) { return(log.ErrorAndReturnModel <EEntity123Model>(errorStr)); } if (canAssign) { eentity123.TenantId = await currentSessionService.GetCurrentTenantIdAsync(); //eentity123.TenantEntityId = await currentSessionService.GetCurrentTenantEntityIdAsNullableAsync(); } eentity123.CreatedBy = existingEEntity123.CreatedBy; eentity123.CreatedDate = existingEEntity123.CreatedDate; eentity123.IsDeleted = existingEEntity123.IsDeleted; var errorList = await IsEEntity123ModelValidForUpdateAsync(eentity123); if (errorList != null) { return(log.ErrorAndReturnModel <EEntity123Model>($"Unable to update eentity123", errorList)); } bool result; using (var trx = await transactionManager.BeginTransactionAsync()) { result = await wipRepository.UpdateEEntity123Async(eentity123, currentUser.GetCurrentUserName()); if (result == false) { throw new RollbackException($"Unable to update eentity123"); } await trx.CompleteAsync(); } await auditService.EEntity123UpdatedAsync(eentity123.EEntity123Id); var view = await wipRepository.GetEEntity123ViewByIdAsync(eentity123.EEntity123Id); if (view == null) { return(log.ErrorAndReturnModel <EEntity123Model>($"Unable to find the eentity123 for {eentity123.EEntity123Guid}")); } return(this.ConvertToItem <EEntity123View, EEntity123Model>(view)); } catch (Exception ex) { return(log.ErrorAndReturnModel <EEntity123Model>($"Unexpected error when updating EEntity123 {eentity123?.EEntity123Guid}", ex)); } }