Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions Application/Commands/CreateItemCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,68 @@ await _context

return item.Id;
}

public async Task<long> ExecuteDuplicationAsync(CreateItemCommandParams createItemCommandParams)
{
var itemTypeIdDoesNotExistWithinTenant = await _context
.QueryableWithinTenant<ItemType>()
.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<long> ExecuteDuplication2Async(CreateItemCommandParams createItemCommandParams)
{
var itemTypeIdDoesNotExistWithinTenant = await _context
.QueryableWithinTenant<ItemType>()
.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;
}
}