Ejemplo n.º 1
0
        static void TestProductListRemove()
        {
            ProductList pList = new ProductList();
            Product     p1    = new Product("T100", "This is a test product", 100M);
            Product     p3    = new Product("T300", "Third test product", 300M);

            pList.Add(p1);
            pList.Add("T200", "Second test product", 200M);
            pList += p3;

            Console.WriteLine("Testing Remove");
            Console.WriteLine("Remove with same object");
            pList.Remove(p1);
            Console.WriteLine("Expecting count of 2 " + pList.Count);
            Console.WriteLine("Expecting list of 2 products.  T100 is not in the list:\n" + pList);
            pList -= p3;
            Console.WriteLine("- operator");
            Console.WriteLine("Expecting count of 1 " + pList.Count);
            Console.WriteLine("Expecting list of 1 products.  T300 is not in the list:\n" + pList);
            Console.WriteLine();
            pList.Remove(new Product("T200", "Second test product", 200M));
            Console.WriteLine("Remove with object that has the same attributes but NOT the same object.\n" +
                              "WON'T WORK AT THIS POINT.  CHAPTER 14 will talk about the method Equals.");
            Console.WriteLine("Expecting count of 0 " + pList.Count);
            Console.WriteLine("Expecting list of 0 products.  T200 should not be in the list:\n" + pList);
        }
Ejemplo n.º 2
0
        static void TestProductListIndexers()
        {
            ProductList pList = new ProductList();
            Product     p1    = new Product("T100", "This is a test product", 100M);
            Product     p3    = new Product("T300", "Third test product", 300M);

            pList.Add(p1);
            pList.Add("T200", "Second test product", 200M);
            pList += p3;

            Console.WriteLine("Testing indexer");
            Console.WriteLine("Get product with index 0");
            Product p4 = pList[0];

            Console.WriteLine("Expecting T100. " + p4);
            Console.WriteLine("Shouldn't alter the list. Expecting count of 3 " + pList.Count);
            Console.WriteLine("Expecting list of 3 products.  T100 is the first element in list:\n" + pList);

            Console.WriteLine("Get product with code T200");
            Product p5 = pList["T200"];

            Console.WriteLine("Expecting T200. " + p5);
            Console.WriteLine("Shouldn't alter the list. Expecting count of 3 " + pList.Count);
            Console.WriteLine("Expecting list of 3 products.  T200 is the second element in list:\n" + pList);

            Console.WriteLine("Set product with index 0");
            pList[0] = p3;
            Console.WriteLine("Shouldn't alter the length of the list. Expecting count of 3 " + pList.Count);
            Console.WriteLine("Expecting list of 3 products.  T300 is the first element in list as well as the last:\n" + pList);

            // I didn't test the indexer with a number < 0 or > the length of the list, but I should have
            // I didn't test the indexer with a product code that's not in the list, but I should have.
        }
        public void BusinessListBaaseFactory_Save_New_items()
        {
            ProductList list = new ProductList();
            list.Add(new Product() { Name = "Test" });
            list.Add(new Product() { Name = "Test1" });
            list.Add(new Product() { Name = "Test2" });

            ProductList products = _factory.Create();

            products = _factory.Update(list);

            _repository.AssertWasCalled(x => x.Save(null), r => r.IgnoreArguments().Repeat.Times(3));
            unitOfWorkStub.AssertWasCalled(x => x.TransactionalFlush());
        }
Ejemplo n.º 4
0
        public Product(string name, int price, bool active, bool canBeBoughtOnCredit)
        {
            if (name != null) // name cant be null, if it is throw an exception
            {
                Name = name;
            }
            else
            {
                throw new ArgumentNullException("Product name in constructor is null");
            }
            Price  = price;
            Active = active;
            CanBeBoughtOnCredit = canBeBoughtOnCredit;
            ID = ProductCount++;

            if (ID > 1) // this logic will make sure, that the product list "Starts" at index 1
            {
                ProductList.Add(this);
            }
            else
            {
                ProductList.Add(null);
                ProductList.Add(this);
            }

            Logger.ProductLog(ToString()); // logs this instance of the product class
        }
Ejemplo n.º 5
0
        private async void LoadData()
        {
            try
            {
                var json = await client.GetStringAsync(new Uri("http://localhost:5000/api/Product"));

                var productslist = JsonConvert.DeserializeObject <IList <Product> >(json);
                if (productslist.Count == 0)
                {
                    ErrorMessage = "There are no products available.";
                }
                else
                {
                    foreach (var Product in productslist)
                    {
                        ProductList.Add(Product);
                    }
                    FillCategoryListProductList();
                    ErrorMessage = null;
                }
            }
            catch (Exception)
            {
                ErrorMessage = "Something went wrong! Please try again later.";
            }
        }
Ejemplo n.º 6
0
        public void CreateProductList()
        {
            ProductList.Clear();

            SqlConnection  con      = Methods.AccessDatabase();
            SqlDataAdapter autoNode = new SqlDataAdapter("SELECT * From [PRODUCT]", con);
            DataTable      dt       = new DataTable();

            autoNode.Fill(dt);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                PRODUCT newProduct = new PRODUCT();

                newProduct.ProductID           = Convert.ToInt16(dt.Rows[i]["Product_ID"]);
                newProduct.ProductName         = dt.Rows[i]["Product_Name"].ToString();
                newProduct.ProductType         = dt.Rows[i]["Product_Type"].ToString();
                newProduct.ProductQuantity     = Convert.ToInt16(dt.Rows[i]["Quantity"]);
                newProduct.ProductColor        = dt.Rows[i]["Color"].ToString();
                newProduct.ProductBuyingPrice  = Convert.ToInt16(dt.Rows[i]["Buying_Price"]);
                newProduct.ProductSellingPrice = Convert.ToInt16(dt.Rows[i]["Selling_Price"]);

                ProductList.Add(newProduct);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 加载所有产品
        /// </summary>
        internal void RefreshProduct(List <Product> products)
        {
            ProductList.Clear();

            foreach (var item in products)
            {
                ProductStateModel newProductStateModel = new ProductStateModel()
                {
                    Product = item, DetectProductIsSelected = DetectProductIsSelected, ProductChange = ProductChange, Operate = Operate
                };

                DetailsModel model = DetectProductIsSelected(newProductStateModel.Product);
                if (null != model)
                {
                    newProductStateModel.IsSelected   = true;
                    newProductStateModel.DetailsModel = model;
                }
                else
                {
                    newProductStateModel.IsSelected   = false;
                    newProductStateModel.DetailsModel = null;
                }


                ProductList.Add(newProductStateModel);
            }

            ResetPage();
        }
Ejemplo n.º 8
0
        protected void lnkSaveProductEdit_OnCommand(object sender, CommandEventArgs e)
        {
            //hide the modal popup
            this.mPopupEdit_Product.Hide();

            //get the new values from the form
            product.UnitCost  = Convert.ToDouble((fviewEditProduct.FindControl("txtUnitCost") as TextBox).Text.Trim());
            product.UnitPrice = Convert.ToDouble((fviewEditProduct.FindControl("txtUnitPrice") as TextBox).Text.Trim());
            if ((fviewEditProduct.FindControl("txtUnitsOnHand") as TextBox).Text.Trim() == "")
            {
                product.UnitsOnHand = 0;
            }
            else
            {
                product.UnitsOnHand = Convert.ToInt32((fviewEditProduct.FindControl("txtUnitsOnHand") as TextBox).Text.Trim());
            }
            if ((fviewEditProduct.FindControl("txtReorderLevel") as TextBox).Text.Trim() == "")
            {
                product.ReorderLevel = 0;
            }
            else
            {
                product.ReorderLevel = Convert.ToInt32((fviewEditProduct.FindControl("txtReorderLevel") as TextBox).Text.Trim());
            }
            product.ItemUrl = (fviewEditProduct.FindControl("txtItemUrl") as TextBox).Text.Trim();

            //save the changes
            ProductManager.Save(product);

            // dislay the product details
            ProductList p = new ProductList();

            p.Add(product);
            PopulateDetailsview(p);
        }
Ejemplo n.º 9
0
        public async void Init()
        {
            try
            {
                if (!Tools.IsNetConnective())
                {
                    CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Long);
                    return;
                }
                IndicatorIsRunning = true;
                ProductList.Clear();

                RestSharpService _restSharpService = new RestSharpService();
                ProductListRD    productListRD     = await _restSharpService.GetCollections();

                if (productListRD.result.total > 0)
                {
                    foreach (var item in productListRD.result.data)
                    {
                        ProductList.Add(item);
                    }
                    ProductNum = productListRD.result.total;
                    Visible    = false;
                }
                else
                {
                    Visible = true;
                }
                IndicatorIsRunning = false;
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 10
0
		public ProductList GetProducts()
		{
			string connectionString = Properties.Settings.Default.Store;
			SqlConnection con = new SqlConnection(connectionString);
			SqlCommand cmd = new SqlCommand("GetProducts", con);
			cmd.CommandType = CommandType.StoredProcedure;

			ProductList products = new ProductList();
			try
			{
				con.Open();
				SqlDataReader reader = cmd.ExecuteReader();
				while (reader.Read())
				{
					// Create a Product object that wraps the 
					// current record.
					Product product = new Product((string)reader["ModelNumber"],
						(string)reader["ModelName"], (decimal)reader["UnitCost"],
						(string)reader["Description"]);

					// Add to collection
					products.Add(product);
				}
			}
			finally
			{
				con.Close();
			}

			return products;
		}
Ejemplo n.º 11
0
        /// <summary>
        /// Adds an item to order's product list, increasing quantity if it already exists
        /// </summary>
        /// <param name="item"></param>
        public void Add(Item item)
        {
            // Validate quantity
            if (item.Quantity < 1)
            {
                throw new ArgumentException("Quantity added should be 1 or more.", nameof(item.Quantity));
            }

            // Cannot add a null product
            if (item.Product == null)
            {
                throw new ArgumentNullException("Product cannot be null.", nameof(item.Product));
            }

            // Fetch the item with specified  product from inventory's list
            Library.Item listItem = GetItem(item.Product);

            // If inventory does not have the item, add a new item with that product and quantity
            if (listItem == null)
            {
                listItem = new Library.Item
                {
                    Product  = item.Product,
                    Quantity = item.Quantity
                };
                ProductList.Add(listItem);
            }
            // If inventory already has product, increase quantity of that product
            else
            {
                listItem.Quantity += item.Quantity;
            }
        }
Ejemplo n.º 12
0
        public void FillProductList()
        {
            int             i           = 0;
            List <string[]> productData = DataLayer.GetTableData("STLProduct");

            foreach (String[] row in productData)
            {
                Guid uid = Guid.NewGuid();
                DataLayer.RemoveCriteria();
                DataLayer.SetCriteria("RawMaterial_ID", "RawMaterial_RawMaterial_ID");
                DataLayer.SetCriteria("STLProduct_STLProduct_ID", row[0]);
                List <string[]> rawMaterials = DataLayer.GetTableData("STLProduct_has_RawMaterial", "RawMaterial", new string[] { "materialName", "Quantity" });
                string[,] materials = new string[rawMaterials.Count, 2];
                foreach (String[] mat in rawMaterials)
                {
                    materials[i, 0] = mat[0];
                    materials[i, 1] = mat[1];
                    i++;
                }
                GenericFactory <IProduct> .Register(uid, () => new Product(Convert.ToInt16(row[0]), row[1], row[2], Convert.ToDouble(row[3]), Convert.ToDouble(row[4]), materials));

                IProduct product = GenericFactory <IProduct> .Create(uid);

                ProductList.Add(product);
                i = 0;
            }
        }
Ejemplo n.º 13
0
        public static ProductList GetTop5ProductsByCategory(string productCategory)
        {
            ProductList    aList  = null;
            MyDBConnection myConn = new MyDBConnection();
            SqlConnection  conn   = new SqlConnection();
            SqlDataReader  dr     = null;
            SqlCommand     cmd    = new SqlCommand();

            try
            {
                conn            = myConn.OpenDB();
                cmd.Connection  = conn;
                cmd.CommandText = "Select top 5 * from Product where ProductCategory = @ProductCategory order by newID();";

                cmd.Parameters.Add("@ProductCategory", SqlDbType.VarChar).Value = productCategory;
                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                if (dr.HasRows)
                {
                    aList = new ProductList();
                    while (dr.Read())
                    {
                        aList.Add(FillDataRecord(dr));
                    }
                }

                cmd.Dispose();
                dr.Close();
            }
            finally
            {
                myConn.CloseDB(conn);
            }
            return(aList);
        }
Ejemplo n.º 14
0
        public WeMerchantGroup(string product)
            : this()
        {
            TkDebug.AssertArgumentNullOrEmpty(product, "product", null);

            ProductList.Add(product);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 加载所有产品
        /// </summary>
        internal void RefreshProduct(List <Product> products)
        {
            // 产品类型全部取消选中
            foreach (var item in resultListType)
            {
                item.IsSelected = false;
            }


            ProductList.Clear();

            foreach (var item in products)
            {
                ProductStateModel newProductStateModel = new ProductStateModel()
                {
                    IsImport = IsImport, Product = item, DetectProductIsSelected = DetectProductIsSelected, ProductChange = ProductChange, Operate = Operate
                };

                DetailsModel model = DetectProductIsSelected(newProductStateModel.Product);
                if (null != model)
                {
                    newProductStateModel.IsSelected   = true;
                    newProductStateModel.DetailsModel = model;
                }
                else
                {
                    newProductStateModel.IsSelected   = false;
                    newProductStateModel.DetailsModel = null;
                }


                ProductList.Add(newProductStateModel);
            }
        }
Ejemplo n.º 16
0
        public void GetProducts()
        {
            try
            {
                //connection.Open();
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    Products.Clear();
                    ProductList.Clear();

                    connection.Open();
                    StringBuilder sb = new StringBuilder();

                    //sb.Append("SELECT * FROM JoelProducts");
                    sb.Append("SELECT * FROM Sheet1$ WHERE GRP_ID IS NULL;");
                    String sql = sb.ToString();

                    Console.WriteLine(sb.ToString());

                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Material material = new Material
                                {
                                    Name = reader.GetString(0),
                                    //Material_Cost = (float)reader.GetDouble(1),
                                    Material_Cost = reader.IsDBNull(1) ? 0 : (float)reader.GetDouble(1),
                                    //Setup_Hr = (float)reader.GetDouble(2),
                                    //Setup_Cost = (UInt32)reader.GetDouble(3),
                                    //Operation_Hr = (float)reader.GetDouble(4),
                                    //Operation_Cost = (UInt32)reader.GetDouble(5),
                                    //Markup = (float)reader.GetDouble(6),
                                    Setup_Hr       = reader.IsDBNull(2) ? 0 : (float)reader.GetDouble(2),
                                    Setup_Cost     = reader.IsDBNull(3) ? 0 : (UInt32)reader.GetDouble(3),
                                    Operation_Hr   = reader.IsDBNull(4) ? 0 : (float)reader.GetDouble(4),
                                    Operation_Cost = reader.IsDBNull(5) ? 0 : (UInt32)reader.GetDouble(5),
                                    Markup         = reader.IsDBNull(6) ? 0 : (float)reader.GetDouble(6),
                                    Qty            = 1,
                                    Id             = (float)reader.GetInt32(7),
                                    Grp_Id         = reader.IsDBNull(8) ? 0 : (float)reader.GetInt32(8)
                                };

                                material.SetSubTotal();
                                material.SetPricePerPiece();

                                Products.Add(material);
                                ProductList.Add(material);
                            }
                        }
                    }
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + ex.Source);
            }
        }
Ejemplo n.º 17
0
        public static void AddProduct(ref int id)
        {
            Console.Clear();

            var product = new Product();

            Console.WriteLine("Enter Name Of The Product: ");
            product.Name = Console.ReadLine();

            Console.WriteLine("Enter The Ammount Of The Product: ");
            product.Ammount = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter The Buy Price Of The Product: ");
            product.BuyPrice = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter The Sale Price The Product: ");
            product.SellPrice = Convert.ToInt32(Console.ReadLine());

            ProductList.Add(product);

            id++;
            product.Id = id;

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Product Named [{0}] Has Been Add Successfully!", product.Name);

            Console.ResetColor();
            Console.WriteLine("Press Any Key To Continue...");
            Console.ReadKey();
        }
Ejemplo n.º 18
0
 void CloseAddNewRecordHandler(bool?close)
 {
     if (close != null && (bool)close)
     {
         products.Add(control.DataContext as Product);
     }
     control = null;
 }
        public void BusinessListBaseFactory_Fetch_No_Criteria()
        {
            ProductList list = new ProductList();
            list.Add(new Product() { Name = "Test" });
            list.Add(new Product() { Name = "Test1" });
            list.Add(new Product() { Name = "Test2" });

            ProductList products = _factory.Create();

            _repository.Expect(x => x.FindAll(DetachedCriteria.For(typeof (Product)))).IgnoreArguments().Return(list);
            _repository.Replay();

            products = _factory.Fetch();

            _repository.AssertWasCalled(x => x.FindAll(DetachedCriteria.For(typeof(Product))), r => r.IgnoreArguments());
            Assert.AreEqual(3, products.Count);
        }
        public async Task Init()
        {
            if (ProductList.Count == 0)
            {
                var products = await _service.Get <List <EToolService.Model.Models.Product> >(null);

                products.ForEach((Product product) => ProductList.Add(new KeyValuePair <Product, decimal>(product, product.Price * (1 - product.Discount))));
            }
        }
Ejemplo n.º 21
0
 public bool AddProduct(Product product)
 {
     if (SearchProduct(product.ModelNo) == null)
     {
         ProductList.Add(product);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 22
0
        private void UpdateGuiWithNewMessage(string message)
        {
            string[] receivedMessage = message.Split(',');

            App.Current.Dispatcher.Invoke(() =>
            {
                ProductList.Add(new ProductVM(receivedMessage[0], receivedMessage[1], Double.Parse(receivedMessage[2]), receivedMessage[3]));
            });
        }
Ejemplo n.º 23
0
        private void InitViewModels()
        {
            var productList = controller.GetAllProducts();

            ProductList.Clear();
            foreach (var product in productList)
            {
                ProductList.Add(new ProductViewModel(product));
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Load all Products, and product properties (Supplier, OrderList, ProductReturnList)
        /// from the DB into the app ProductList
        /// </summary>
        public async void LoadProductsAsync()
        {
            List <Product> products = null;

            try
            {
                products = await PersistencyService.LoadProductsAsync();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                throw;
            }

            if (products != null)
            {
                foreach (Product p in products)
                {
                    // Set the Supplier, Orders, and ProductReturns for the current Product
                    // Product has a required supplier
                    try
                    {
                        // Find the single supplier matching the supplier foreign key on the product
                        p.Supplier = SupplierList.Single(s => s.Id.Equals(p.SupplierId));
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                        throw;
                    }


                    // Get Orders in the OrderList with a foreign key to the current Product in the foreach
                    List <Order> productOrderList = OrderList.Where(o => o.ProductId.Equals(p.Id)).ToList();
                    if (productOrderList != null && productOrderList.Count > 0)
                    {
                        p.FillOrderList(productOrderList);
                    }

                    // Get ProductReturns in the prList with a foreign key to the current Product in the foreach
                    List <ProductReturn> prList = ProductReturnList.Where(pr => pr.ProductId.Equals(p.Id)).ToList();
                    if (prList != null && prList.Count > 0)
                    {
                        p.FillProductReturnList(prList);
                    }

                    // At last, add the product the productList
                    ProductList.Add(p);
                }
            }
            else
            {
                throw new ArgumentNullException("Products list null");
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 加载所有产品
        /// </summary>
        internal void RefreshProduct(bool OnlyRefreshState)
        {
            // 指刷新, 不重新添加(为了平板上不影响切换快速响应)
            if (OnlyRefreshState)
            {
                foreach (var item in ProductList)
                {
                    DetailsModel model = DetectProductIsSelected(item.Product);
                    if (null != model)
                    {
                        item.IsSelected   = true;
                        item.DetailsModel = model;
                    }
                    else
                    {
                        item.IsSelected   = false;
                        item.DetailsModel = null;
                    }
                }
            }
            else
            {
                ProductList.Clear();



                IEnumerable <Product> models = Resources.GetRes().Products.Where(x => x.HideType == 0 || x.HideType == 2);


                models = models.OrderByDescending(x => x.Order).ThenByDescending(x => x.ProductId);
                foreach (var item in models)
                {
                    ProductStateModel newProductStateModel = new ProductStateModel()
                    {
                        Product = item, DetectProductIsSelected = DetectProductIsSelected, ProductChange = ProductChange, Operate = Operate
                    };

                    DetailsModel model = DetectProductIsSelected(newProductStateModel.Product);
                    if (null != model)
                    {
                        newProductStateModel.IsSelected   = true;
                        newProductStateModel.DetailsModel = model;
                    }
                    else
                    {
                        newProductStateModel.IsSelected   = false;
                        newProductStateModel.DetailsModel = null;
                    }


                    ProductList.Add(newProductStateModel);
                }
            }
        }
Ejemplo n.º 26
0
    public ListProduct AddProducts(SqlString sqlString)
    {
        var product = Product.Parse(sqlString);

        if (Count < list_Length)
        {
            ProductList.Add(product);
            Count++;
        }
        return(this);
    }
Ejemplo n.º 27
0
        protected void lnkEditProductInformation_OnCommand(object sender, CommandEventArgs e)
        {
            ProductList el = new ProductList();

            el.Add(ProductManager.GetProductByID(product.ProductID));

            fviewEditProduct.DataSource = el;
            fviewEditProduct.DataBind();

            this.mPopupEdit_Product.Show();
        }
Ejemplo n.º 28
0
        private void GetAllContainers()
        {
            var all_Containers = GetProductRepository().GetAllContainerProducts();

            foreach (var container in all_Containers)
            {
                ProductList.Add(new Product {
                    Id = container.Id, ProductName = container.Name
                });
            }
        }
Ejemplo n.º 29
0
        public IProductList GetAll()
        {
            var result = new ProductList();

            var ids = _repo.All();

            foreach (var i in ids)
            {
                result.Add(_repo.Get(i));
            }
            return(result);
        }
Ejemplo n.º 30
0
        static void TestProductListAdd()
        {
            ProductList pList = new ProductList();
            Product     p1    = new Product("T100", "This is a test product", 100M);
            Product     p3    = new Product("T300", "Third test product", 300M);

            Console.WriteLine("Testing Add");
            pList.Add(p1);
            Console.WriteLine("Add that takes a product parameter");
            Console.WriteLine("Expecting count of 1 " + pList.Count);
            Console.WriteLine("Expecting list of 1 products:\n" + pList);
            pList.Add("T200", "Second test product", 200M);
            Console.WriteLine("Add that takes individual product attributes and constructs a product");
            Console.WriteLine("Expecting count of 2 " + pList.Count);
            Console.WriteLine("Expecting list of 2 products:\n" + pList);
            pList += p3;
            Console.WriteLine("+ operator");
            Console.WriteLine("Expecting count of 3 " + pList.Count);
            Console.WriteLine("Expecting list of 3 products:\n" + pList);
            Console.WriteLine();
        }
Ejemplo n.º 31
0
        public void CreateProduct(Product p)
        {
            // TODO check if varenr og navn eksisterer i forvejen
            // if check here


            if (p.Supplier == null)
            {
                // Supplier or any of suppliers properties are null
                throw new ArgumentNullException("Some supplier information is missing");
            }

            if (p.Supplier.Id != 0)
            {
                // If the supplier is not 0, that means the Supplier was selected from the dropdownlist

                // Set the SupplierId on the Product
                p.SupplierId = p.Supplier.Id;
            }
            else
            {
                // The supplier id is zero, which means it was typed in and not selected
                // should now check if a supplier already exists with that name or create a new one

                // Check if the Supplier already exists in the list
                if (SupplierList.Where(s => s.Id.Equals(p.SupplierId)).Count() > 0)
                {
                    // Exists in the list update the Supplier instead
                    UpdateSupplier(p.Supplier);
                    new MessageDialog("Updating Supplier").ShowAsync();
                }
                else
                {
                    // Does not exist in the list, create a new one
                    CreateSupplier(p.Supplier);
                    new MessageDialog("Creating Supplier").ShowAsync();
                }
            }

            try
            {
                // Add in DB1
                PersistencyService.InsertProductAsync(p);

                // Add to ProductList
                ProductList.Add(p);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
Ejemplo n.º 32
0
        public IProductList FindByName(string name)
        {
            var result = new ProductList();

            var ids = _repo.ByName(name);

            foreach (var i in ids)
            {
                result.Add(_repo.Get(i));
            }

            return(result);
        }
        public void Init()
        {
            ProductList.Clear();
            var items = OrderService.Cart;

            foreach (var item in items)
            {
                decimal priceWithDiscount = item.Value.Price * (1 - item.Value.Discount);
                ProductList.Add(new Tuple <Product, int, decimal>(item.Value, item.Count, Math.Round(item.Count * priceWithDiscount, 2)));
            }

            Total = ProductList.Sum(x => x.Item3);
        }
        public void BusinessListBaseFactory_Fetch_WithCriteria_ReturnsObject()
        {
            _criteria = MockRepository.GenerateStub<NHibernate.ICriteria>();

            ProductList list = new ProductList();
            list.Add(new Product() { Name = "Test" });
            list.Add(new Product() { Name = "Test1" });
            list.Add(new Product() { Name = "Test2" });

            NHibernate.Criterion.SimpleExpression expression = Restrictions.Eq("Name", "Test");
            _criteria.Expect(c => c.Add(expression)).Return(_criteria);
            _repository.Expect(r => r.CreateCriteria()).Return(_criteria);
            _criteria.Expect(c => c.List<Product>()).Return(list);

            ProductList products = _factory.Fetch(new SingleCriteria<ProductList, string>("Test"));

            _repository.AssertWasCalled(r => r.CreateCriteria());
            _criteria.AssertWasCalled(c => c.List<Product>());
            Assert.AreEqual(3, products.Count);
        }