public int AddInventoryItem(string json) { InventoryItem ii = InventoryItem.FromJsonString(json); if (!Validate.NameValidation(ii.Name)) { throw new ValidationException("Invalid name"); } if (!Validate.NameValidation(ii.Description)) { throw new ValidationException("Invalid description"); } if (!Validate.NumberValidation(ii.Barcode)) { throw new ValidationException("Invalid barcode"); } InventoryItemPM item = new InventoryItemPM() { Name = ii.Name, Description = ii.Description, Barcode = ii.Barcode, Price = ii.Price, InventoryGroupIdRef = ii.InventoryGroupIdRef, }; return(_posRepository.AddInventoryItem(item, GetCurrentUserId())); }
public int AddInventoryItem(InventoryItemPM item, string credentialsId) { item.AccountNumberIdRef = _accountRepository.GetAccountForUser(credentialsId).AccountNumberId; _context.InventoryItems.Add(item); _context.SaveChanges(); return(item.InventoryItemId); }
public void DeleteInventoryItem(int id, string credentialsId) { InventoryItemPM i = GetInventoryItem(id, credentialsId); if (i == null) { throw new ValidationException("no item found"); } _context.InventoryItems.Remove(i); _context.SaveChanges(); }
public void UpdateInventoryItem(InventoryItemPM item, string credentialsId) { //will only get accounts for this user InventoryItemPM itemOld = GetInventoryItem(item.InventoryItemId, credentialsId); if (itemOld == null) { throw new ValidationException("no item found"); } //InventoryItemPM item = new InventoryItemPM() { Name = name, Description = description, Barcode = barcode, Price = price, InventoryGroupIdRef = inventoryGroupId }; itemOld.Update(item); _context.SaveChanges(); }
public string GetInventoryItem(int id) { InventoryItemPM x = _posRepository.GetInventoryItem(id, GetCurrentUserId()); return(JsonConvert.ToString(new InventoryItem() { Barcode = x.Barcode, Description = x.Description, InventoryGroupIdRef = x.InventoryGroupIdRef, InventoryItemId = x.InventoryItemId, Name = x.Name, Price = x.Price, }.ToJsonString())); }