protected virtual async Task Create(CreateOrEditAssetDto input) { var asset = ObjectMapper.Map <Asset>(input); if (AbpSession.TenantId != null) { asset.TenantId = (int?)AbpSession.TenantId; } await _assetRepository.InsertAsync(asset); await CurrentUnitOfWork.SaveChangesAsync(); CreateLocation(input.Location); // Create an AssetOwnership var tenantInfo = TenantManager.GetTenantInfo().Result; int assetOwnerId = 0; int tenantId = 0; AssetOwner assetOwner = new AssetOwner(); switch (tenantInfo.Tenant.TenantType) { case "H": // Host is creating this Asset, so just assign it to the first (probably only) AssetOwner assetOwner = _assetOwnerRepository.GetAllListAsync().Result.FirstOrDefault(); assetOwnerId = assetOwner.Id; tenantId = (int)assetOwner.TenantId; break; case "A": assetOwnerId = tenantInfo.AssetOwner.Id; tenantId = tenantInfo.Tenant.Id; break; default: throw new Exception($"This Tenant ({tenantInfo.Tenant.Name}) is not entitled to create an Asset!"); } if (assetOwnerId != 0) { AssetOwnership assetOwnership = new AssetOwnership() { AssetId = asset.Id, AssetOwnerId = assetOwnerId, FinishDate = DateTime.Now.AddYears(50), StartDate = DateTime.Now, PercentageOwnership = 100, TenantId = tenantId }; await _assetOwnershipRepository.InsertAsync(assetOwnership); } else { throw new Exception($"Couldn't figure out the assetOwnerId"); } }
protected virtual async Task Update(CreateOrEditAssetDto input) { var asset = await _assetRepository.FirstOrDefaultAsync((int)input.Id); ObjectMapper.Map(input, asset); CreateLocation(input.Location); }
public async Task CreateOrEdit(CreateOrEditAssetDto input) { if (input.Id == null) { await Create(input); } else { await Update(input); } }