public ActionResult Oder(ProductOder product)
 {
     try
     {
         if (db.Products.FirstOrDefault(u => u.id == product.id_product) != null &&
             db.Products.FirstOrDefault(u => u.id == product.id_product).count >= product.count)
         {
             db.Products.FirstOrDefault(u => u.id == product.id_product).count -= product.count;
             db_oder.Add(new ProductOder {
                 count = product.count, id_product = product.id_product, user = product.user, is_odered = false
             });
             db_oder.SaveChanges();
             db.SaveChanges();
             ModelState.AddModelError("", "Продукт заказан");
         }
         else
         {
             ModelState.AddModelError("", "Продукт " + product.id_product + " не может быть заказан, не хватает товара");
         }
         return(View(product));
     }
     catch
     {
         ModelState.AddModelError("", "Продукт " + product.id + " не может быть заказан");
         return(View(product));
     }
 }
Esempio n. 2
0
 public Detail(SanPham productOder, ProductOder tempProduct)
 {
     this.productOrder      = productOder;
     this.tempProduct       = tempProduct;
     this.tempProduct.Count = 1;
     InitializeComponent();
 }
        public ActionResult Oder(int id)
        {
            ProductOder prod = new ProductOder();

            prod.user       = User.Identity.Name;
            prod.id_product = id;
            return(View(prod));
        }
Esempio n. 4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            var index  = (button.Tag as Tuple <int>).Item1;

            bool exist = false;

            ProductOder tempProduct = new ProductOder();
            //var productOrder = new ProductOder();
            var screen = new Detail(dsSanPham[index], tempProduct);

            if (screen.ShowDialog() == true)
            {
                int indexOrder = 0;

                for (int i = 0; i < listProductOrder.Count; i++)
                {
                    if (dsSanPham[index].MaSanPham.CompareTo(listProductOrder[i].CodeProduct) == 0)
                    {
                        exist      = true;
                        indexOrder = i;
                        break;
                    }
                }

                if (exist == false)
                {
                    ProductOder productOrder = new ProductOder()
                    {
                        CodeProduct = dsSanPham[index].MaSanPham, Cost = dsSanPham[index].Gia, NameProduct = dsSanPham[index].TenSanPham, Count = tempProduct.Count, Total = tempProduct.Count * dsSanPham[index].Gia
                    };
                    listProductOrder.Add(productOrder);
                    TotalMoney   += tempProduct.Count * dsSanPham[index].Gia;
                    TongTien.Text = TotalMoney.ToString();
                }
                else
                {
                    listProductOrder[indexOrder].Count += tempProduct.Count;
                    TotalMoney += tempProduct.Count * listProductOrder[indexOrder].Cost;
                    listProductOrder[indexOrder].Total += tempProduct.Count * listProductOrder[indexOrder].Cost;
                    TongTien.Text = TotalMoney.ToString();
                }
            }
        }
Esempio n. 5
0
        private void ButtonCombo_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            var index  = (button.Tag as Tuple <int>).Item1;


            var screen = new DetailCombo(dsComBo[index - current]);

            if (screen.ShowDialog() == true)
            {
                List <ProductOder> newList = new List <ProductOder>();

                for (int i = 0; i < comBoInfos.Count; i++)
                {
                    if (comBoInfos[i].MaComBo.CompareTo(dsComBo[index - current].MaComBo) == 0)
                    {
                        for (int j = 0; j < dsSanPham.Count; j++)
                        {
                            if (comBoInfos[i].MaSanPham.CompareTo(dsSanPham[j].MaSanPham) == 0)
                            {
                                ProductOder productOrder = new ProductOder()
                                {
                                    CodeProduct = dsSanPham[j].MaSanPham, Cost = dsSanPham[j].Gia, NameProduct = dsSanPham[j].TenSanPham, Count = 1, Total = dsSanPham[j].Gia
                                };
                                newList.Add(productOrder);
                                break;
                            }
                        }
                    }
                }

                for (int i = 0; i < newList.Count; i++)
                {
                    int  indexOrder = 0;
                    bool exist      = false;
                    for (int j = 0; j < listProductOrder.Count; j++)
                    {
                        if (newList[i].CodeProduct.CompareTo(listProductOrder[j].CodeProduct) == 0)
                        {
                            exist      = true;
                            indexOrder = j;
                            break;
                        }
                    }

                    if (exist == false)
                    {
                        listProductOrder.Add(newList[i]);
                        TotalMoney   += newList[i].Cost;
                        TongTien.Text = TotalMoney.ToString();
                    }
                    else
                    {
                        listProductOrder[indexOrder].Count++;
                        TotalMoney += listProductOrder[indexOrder].Cost;
                        listProductOrder[indexOrder].Total += listProductOrder[indexOrder].Cost;
                        TongTien.Text = TotalMoney.ToString();
                    }
                }
            }
        }