private void AddItemForPOS(PostItemBindingModel item) { var posInterface = _posProvider.GetAllInterfaces() .FirstOrDefault(i => i.AccountID.Equals(item.AccountId)); if (posInterface == null) { throw new ArgumentException("The POS account with ID " + item.AccountId + " could not be found."); } if (!posInterface.CanMakeRequest()) { posInterface.RefreshToken(); if (!posInterface.CanMakeRequest()) { return; } } var allProducts = posInterface.GetAllProducts(); Object product; if (item.ItemPosId != null) { product = allProducts.FirstOrDefault(i => i.PosID.Equals(item.ItemPosId)); } else { product = allProducts.FirstOrDefault(i => i.Name.Equals(item.ItemName)); } if (product == null) //The name could not be found { throw new ArgumentException("The product with name " + item.ItemName + " could not be found in the specified POS system register.\n" + "Valid products include : [" + string.Join(",", allProducts.Select(p => p.Name).ToArray()) + "]"); } var itemToInsert = new Object() { EcommerceID = item.ItemEcommerceId, POS = posInterface, PosID = product.PosID, Quantity = product.Quantity, Name = product.Name, LimitQuantitySale = item.LimitQuantity }; _ecommerceDatabase.AddNewProduct(itemToInsert); }
public string PostStart([FromBody] PostItemBindingModel item) { if (item?.ItemName == null && item?.ItemPosId == null || item?.AccountId == null) { Response.StatusCode = 400; return("invalid request"); } var jobID = BackgroundJob.Enqueue(() => AddNewItem(item)); Response.StatusCode = 202; return("pending added. Location : itemstask/" + jobID); }
public void AddNewItem(PostItemBindingModel item) { try { if (item.IsMobileClient) { AddItemForMobileClient(item); } else { AddItemForPOS(item); } } catch (Exception e) { Console.Write(e.ToString()); throw; } }
private void AddItemForMobileClient(PostItemBindingModel item) { var posInterface = _posProvider.GetAllInterfaces() .FirstOrDefault(i => i.AccountID.Equals(item.AccountId)); if (posInterface == null) { throw new ArgumentException("The POS account with ID " + item.AccountId + " could not be found."); } var itemToInsert = new Object() { EcommerceID = item.ItemEcommerceId, POS = posInterface, PosID = item.ItemPosId, Quantity = item.Quantity, Name = item.ItemName, LimitQuantitySale = item.LimitQuantity }; _ecommerceDatabase.AddNewProduct(itemToInsert); }