public int Delete(int id)
        {
            Buying_History buying = this.context.Buying_History.SingleOrDefault(x => x.Id == id);

            this.context.Buying_History.Remove(buying);

            return(this.context.SaveChanges());
        }
        public int Update(Buying_History buying_history)
        {
            Buying_History buying = this.context.Buying_History.SingleOrDefault(x => x.Id == buying_history.Id);

            buying.Id = buying_history.Id;

            return(this.context.SaveChanges());
        }
 public int Insert(Buying_History buying_history)
 {
     this.context.Buying_History.Add(buying_history);
     return(this.context.SaveChanges());
 }
Exemplo n.º 4
0
 public int Update(Buying_History Buying_History)
 {
     return(this.data.Update(Buying_History));
 }
Exemplo n.º 5
0
 public int Insert(Buying_History Buying_History)
 {
     return(this.data.Insert(Buying_History));
 }
        //
        // GET: /BuyingConfimation/

        public ActionResult Index()
        {
            ViewBag.userName = Session["userName"];
            ViewBag.logged   = Session["LoggedIN"];

            iCart_Service           cart          = Service_Center.GetCart_Service();
            iProduct_Service        productAll    = Service_Center.GetProduct_Service();//
            iBuying_History_Service buyingHistory = Service_Center.GetBuying_History_Service();
            iProduct_Report_Service report        = Service_Center.GetProduct_Report_Service();

            IEnumerable <Cart> FullCart = cart.Get(Session["userName"].ToString());

            foreach (Cart c in FullCart)
            {
                Product pro = new Product();
                IEnumerable <Product> proAll = productAll.GetAllValues();

                foreach (Product p in proAll)
                {
                    if (p.Id == c.ProductID)
                    {
                        int before = productAll.Get(p.Id).Product_Quantity;
                        int after  = before - c.BuyingQuantity;

                        pro.Id = p.Id;
                        pro.Product_Quantity = after;

                        int y = productAll.Update(pro);
                    }
                }

                Buying_History buy = new Buying_History();
                Product_Report rep = new Product_Report();

                buy.Product_ID      = c.ProductID;
                buy.User_Name       = Session["userName"].ToString();
                buy.Buying_Quantity = c.BuyingQuantity;
                buy.Buying_Date     = DateTime.Now.ToLocalTime();

                IEnumerable <Product_Report> proReport = report.GetAllValues();
                bool check     = false;
                int  productID = 0;

                foreach (Product_Report r in proReport)
                {
                    if (r.Product_ID == c.ProductID)
                    {
                        check     = true;
                        productID = r.Product_ID;
                        break;
                    }
                }

                if (check == true)
                {
                    int beforeQuantity = report.Get(productID).Selling_Quantity;
                    int afterQuantity  = beforeQuantity + c.BuyingQuantity;

                    rep.Product_ID       = productID;
                    rep.Selling_Quantity = afterQuantity;

                    int p = report.Update(rep);
                }
                else
                {
                    rep.Product_ID       = c.ProductID;
                    rep.Selling_Quantity = c.BuyingQuantity;

                    int j = report.Insert(rep);
                }

                int i = buyingHistory.Insert(buy);
            }



            int de = cart.DeleteUserCart(Session["userName"].ToString());

            //ViewBag.row = cartRow;
            return(View());
        }