public async Task <ReturnModel <EEntity123Model> > CreateEEntity123([FromBody] EEntity123CreateModel eentity123Model) { return(await wipService.CreateEEntity123Async(eentity123Model)); }
public async Task <ReturnModel <EEntity123Model> > CreateEEntity123Async(EEntity123CreateModel eentity123) { try { if (eentity123 == null) { return(log.ErrorAndReturnModel <EEntity123Model>($"Unable to create EEntity123", new ReturnErrorItem("", "EEntity123 information is not valid"))); } var(resultValue, canAssign, errorStr) = await permissionService.GetCanManageEEntity123PermissionParamsAsync(eentity123.TenantId, eentity123.TenantEntityId); if (resultValue == false) { return(log.ErrorAndReturnModel <EEntity123Model>(errorStr)); } if (canAssign) { eentity123.TenantId = await currentSessionService.GetCurrentTenantIdAsync(); //eentity123.TenantEntityId = await currentSessionService.GetCurrentTenantEntityIdAsNullableAsync(); } var errorList = await IsEEntity123ModelValidForCreateAsync(eentity123); if (errorList != null) { return(log.ErrorAndReturnModel <EEntity123Model>($"Unable to create eentity123", errorList)); } eentity123.EEntity123Guid = Guid.NewGuid(); eentity123.IsDeleted = false; EEntity123 item; using (var trx = await transactionManager.BeginTransactionAsync()) { item = await wipRepository.CreateEEntity123Async(eentity123, currentUser.GetCurrentUserName()); if (item == null) { throw new Exception($"Unable to create eentity123"); } await trx.CompleteAsync(); } await auditService.EEntity123CreatedAsync(item.EEntity123Id); var view = await wipRepository.GetEEntity123ViewByIdAsync(item.EEntity123Id); if (view == null) { return(log.ErrorAndReturnModel <EEntity123Model>($"Unable to find the eentity123 for {item.EEntity123Guid}")); } return(this.ConvertToItem <EEntity123View, EEntity123Model>(view)); } catch (RollbackException ex) { return(log.ErrorAndReturnModel <EEntity123Model>($"Rollbacking the transaction when creating EEntity123 {eentity123?.EEntity123Guid}", ex)); } catch (Exception ex) { return(log.ErrorAndReturnModel <EEntity123Model>($"Unexpected error when creating EEntity123 {eentity123?.EEntity123Guid}", ex)); } }