public LotInventory Get(string lotKey) { var getInventoryResult = _inventoryService.GetInventory(new FilterInventoryParameters { LotKey = lotKey, }); getInventoryResult.EnsureSuccessWithHttpResponseException(HttpVerbs.Get); var result = new LotInventory { InventoryItems = getInventoryResult.ResultingObject.Inventory.Project().To <InventoryItem>(), }; return(result); }
public void UpdateLotInventory(HOAContext context, string[] selectedInventory, Lot lotToUpdate, int?whoID) { if (selectedInventory == null) { lotToUpdate.LotInventory = new List <LotInventory>(); return; } var selectedInventoryHS = new HashSet <string>(selectedInventory); var lotInventory = new HashSet <int>(lotToUpdate.LotInventory.Select(l => l.Inventory.InventoryID)); var whoEdited = context.Owner .Include(o => o.User) .Include(o => o.Address) .Include(a => a.OwnerContactType) .ThenInclude(oc => oc.ContactType) .FirstOrDefault(u => u.OwnerID == whoID); foreach (var item in context.Inventory) { if (selectedInventoryHS.Contains(item.InventoryID.ToString())) { if (!lotInventory.Contains(item.InventoryID)) { lotToUpdate.LotInventory.Add( new LotInventory { LotsID = lotToUpdate.LotID, InventoryID = item.InventoryID, Description = "", LastModifiedBy = whoEdited != null ? whoEdited.Initials : "SYS", LastModifiedDate = DateTime.Now }); } } else { if (lotInventory.Contains(item.InventoryID)) { LotInventory itemToRemove = lotToUpdate .LotInventory .SingleOrDefault(l => l.InventoryID == item.InventoryID); context.Remove(itemToRemove); } } } }