Example #1
0
        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);
        }
Example #2
0
        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);
        }