/// <summary> /// Update an existing Inventory record for an implement. /// </summary> /// <param name="details"></param> /// <param name="jobsiteId"></param> /// <param name="authUserId"></param> /// <param name="_context"></param> /// <returns>The ID of the updated inventory record.</returns> public int UpdateInventoryRecord(ImplementDetails details, int jobsiteId, long authUserId, GETContext _context) { int result = -1; try { GET_INVENTORY inventoryRecord = _context.GET_INVENTORY.Where(w => w.get_auto == details.Id).FirstOrDefault(); if (inventoryRecord != null) { inventoryRecord.modified_date = DateTime.Now; inventoryRecord.modified_user = (int)authUserId; inventoryRecord.ltd = (int)details.ImplementHoursAtSetup; int _changesSaved = _context.SaveChanges(); if (_changesSaved > 0) { result = inventoryRecord.inventory_auto; } } } catch (Exception ex1) { } return(result); }
/// <summary> /// Create a new inventory record for an implement. /// </summary> /// <param name="details"></param> /// <param name="jobsiteId"></param> /// <param name="authUserId"></param> /// <param name="_context"></param> /// <returns>The ID of the created inventory record.</returns> public int InsertIntoInventory(ImplementDetails details, int jobsiteId, long authUserId, GETContext _context) { int result = -1; try { GET_INVENTORY newGETinInventory = new GET_INVENTORY(); newGETinInventory.get_auto = details.Id; newGETinInventory.jobsite_auto = jobsiteId; newGETinInventory.status_auto = (int)GETInterfaces.Enum.InventoryStatus.Ready_for_Use; newGETinInventory.modified_date = DateTime.Now; newGETinInventory.modified_user = (int)authUserId; newGETinInventory.ltd = (int)details.ImplementHoursAtSetup; newGETinInventory.workshop_auto = null; _context.GET_INVENTORY.Add(newGETinInventory); int _changesSaved = _context.SaveChanges(); if (_changesSaved > 0) { result = newGETinInventory.inventory_auto; } } catch (Exception ex1) { } return(result); }
/// <summary> /// Update the GET_INVENTORY record for a specified implement. /// </summary> /// <param name="details"></param> /// <param name="jobsiteId"></param> /// <param name="authUserId"></param> /// <param name="_context"></param> /// <returns>The ID of the GET_INVENTORY record that was inserted or updated.</returns> public int UpdateImplementInInventory(ImplementDetails details, int jobsiteId, long authUserId, GETContext _context) { int result = 0; // Check if the record already exists in inventory. var inventoryRecordExists = _context.GET_INVENTORY.Where(w => w.get_auto == details.Id).Any(); if (!inventoryRecordExists) { // Add a new inventory record for this implement. result = InsertIntoInventory(details, jobsiteId, authUserId, _context); } else { // Update the existing inventory record for this implement. result = UpdateInventoryRecord(details, jobsiteId, authUserId, _context); } return(result); }