diff --git a/Application/Commands/CreateItemCommand.cs b/Application/Commands/CreateItemCommand.cs index 91ba52e..d9ffdf3 100644 --- a/Application/Commands/CreateItemCommand.cs +++ b/Application/Commands/CreateItemCommand.cs @@ -66,4 +66,68 @@ await _context return item.Id; } + + public async Task ExecuteDuplicationAsync(CreateItemCommandParams createItemCommandParams) + { + var itemTypeIdDoesNotExistWithinTenant = await _context + .QueryableWithinTenant() + .AllAsync(x => x.Id != createItemCommandParams.ItemTypeId); + + if (itemTypeIdDoesNotExistWithinTenant) + { + throw new Exception($"Passed item type where id={createItemCommandParams.ItemTypeId} is not found within tenant where id={_claimsProvider.TenantId}"); + } + + var item = new Item + { + TenantId = _claimsProvider.TenantId, + Name = createItemCommandParams.Name, + SerialNumber = createItemCommandParams.SerialNumber, + ItemTypeId = createItemCommandParams.ItemTypeId, + Price = createItemCommandParams.Price, + Description = createItemCommandParams.Description, + PurchaseDate = createItemCommandParams.PurchaseDate, + HolderEmployeeId = createItemCommandParams.HolderEmployeeId + }; + + await _context + .Items + .AddAsync(item); + + await _context.SaveChangesAsync(); + + return item.Id; + } + + public async Task ExecuteDuplication2Async(CreateItemCommandParams createItemCommandParams) + { + var itemTypeIdDoesNotExistWithinTenant = await _context + .QueryableWithinTenant() + .AllAsync(x => x.Id != createItemCommandParams.ItemTypeId); + + if (itemTypeIdDoesNotExistWithinTenant) + { + throw new Exception($"Passed item type where id={createItemCommandParams.ItemTypeId} is not found within tenant where id={_claimsProvider.TenantId}"); + } + + var item = new Item + { + TenantId = _claimsProvider.TenantId, + Name = createItemCommandParams.Name, + SerialNumber = createItemCommandParams.SerialNumber, + ItemTypeId = createItemCommandParams.ItemTypeId, + Price = createItemCommandParams.Price, + Description = createItemCommandParams.Description, + PurchaseDate = createItemCommandParams.PurchaseDate, + HolderEmployeeId = createItemCommandParams.HolderEmployeeId + }; + + await _context + .Items + .AddAsync(item); + + await _context.SaveChangesAsync(); + + return item.Id; + } }