public ActionResult Edit([Bind(Include = "PRODUCT_ID,NAME,CATEGORY_ID,BRAND,TOTAL_UNIT,TOTAL_COST,COST_PER_UNIT,SELL_PRICE_PER_UNIT,PURCHASED_ON,PURCHASED_THROUGH,PAID_BY,UNIT_LEFT,IS_ACT,IS_DEL,CREATED_AT,UPDATED_AT")] STORE_PRODUCTS sTORE_PRODUCTS)
        {
            if (ModelState.IsValid)
            {
                STORE_PRODUCTS sTORE_PRODUCTS_UPD = db.STORE_PRODUCTS.Find(sTORE_PRODUCTS.PRODUCT_ID);
                sTORE_PRODUCTS_UPD.NAME                = sTORE_PRODUCTS.NAME;
                sTORE_PRODUCTS_UPD.CATEGORY_ID         = sTORE_PRODUCTS.CATEGORY_ID;
                sTORE_PRODUCTS_UPD.BRAND               = sTORE_PRODUCTS.BRAND;
                sTORE_PRODUCTS_UPD.TOTAL_UNIT          = sTORE_PRODUCTS.TOTAL_UNIT;
                sTORE_PRODUCTS_UPD.TOTAL_COST          = sTORE_PRODUCTS.TOTAL_COST;
                sTORE_PRODUCTS_UPD.COST_PER_UNIT       = sTORE_PRODUCTS.COST_PER_UNIT;
                sTORE_PRODUCTS_UPD.SELL_PRICE_PER_UNIT = sTORE_PRODUCTS.SELL_PRICE_PER_UNIT;
                sTORE_PRODUCTS_UPD.PURCHASED_ON        = sTORE_PRODUCTS.PURCHASED_ON;
                sTORE_PRODUCTS_UPD.PURCHASED_THROUGH   = sTORE_PRODUCTS.PURCHASED_THROUGH;
                sTORE_PRODUCTS_UPD.PAID_BY             = sTORE_PRODUCTS.PAID_BY;
                sTORE_PRODUCTS_UPD.UNIT_LEFT           = sTORE_PRODUCTS.UNIT_LEFT;
                sTORE_PRODUCTS_UPD.IS_ACT              = sTORE_PRODUCTS.IS_ACT;
                sTORE_PRODUCTS.UPDATED_AT              = DateTime.Now;
                db.Entry(sTORE_PRODUCTS).State         = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("ViewAll"));
            }
            ViewBag.CATEGORY_ID       = new SelectList(db.STORE_CATEGORY, "ID", "NAME", sTORE_PRODUCTS.CATEGORY_ID);
            ViewBag.PURCHASED_THROUGH = sTORE_PRODUCTS.PURCHASED_THROUGH;
            ViewBag.PAID_BY           = sTORE_PRODUCTS.PAID_BY;
            DateTime PDate = Convert.ToDateTime(sTORE_PRODUCTS.PURCHASED_ON);

            ViewBag.PURCHASED_ON = PDate.ToString("dd/mm/yyyy");
            return(View(sTORE_PRODUCTS));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            STORE_PRODUCTS sTORE_PRODUCTS = db.STORE_PRODUCTS.Find(id);

            sTORE_PRODUCTS.IS_DEL          = "Y";
            sTORE_PRODUCTS.IS_ACT          = "N";
            sTORE_PRODUCTS.UPDATED_AT      = DateTime.Now;
            db.Entry(sTORE_PRODUCTS).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("ViewAll"));
        }
        // GET: Store/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            STORE_PRODUCTS sTORE_PRODUCTS = db.STORE_PRODUCTS.Find(id);

            if (sTORE_PRODUCTS == null)
            {
                return(HttpNotFound());
            }
            return(View(sTORE_PRODUCTS));
        }
        public ActionResult Create([Bind(Include = "PRODUCT_ID,NAME,CATEGORY_ID,BRAND,TOTAL_UNIT,TOTAL_COST,COST_PER_UNIT,SELL_PRICE_PER_UNIT,PURCHASED_ON,PURCHASED_THROUGH,PAID_BY,UNIT_LEFT,IS_ACT,IS_DEL,CREATED_AT,UPDATED_AT")] STORE_PRODUCTS sTORE_PRODUCTS)
        {
            if (ModelState.IsValid)
            {
                sTORE_PRODUCTS.IS_DEL     = "N";
                sTORE_PRODUCTS.CREATED_AT = DateTime.Now;
                sTORE_PRODUCTS.UPDATED_AT = DateTime.Now;
                db.STORE_PRODUCTS.Add(sTORE_PRODUCTS);
                db.SaveChanges();
                return(RedirectToAction("ViewAll"));
            }

            ViewBag.CATEGORY_ID = new SelectList(db.STORE_CATEGORY, "ID", "NAME", sTORE_PRODUCTS.CATEGORY_ID);
            return(View(sTORE_PRODUCTS));
        }
        // GET: Student
        public ActionResult CleanCart()
        {
            var pURcART = (from res in db.STORE_PURCHAGE_CART
                           select res).ToList();

            foreach (var PurCarList in pURcART)
            {
                STORE_PRODUCTS sTOREpRODUCT = db.STORE_PRODUCTS.Find(PurCarList.PRODUCT_ID);
                sTOREpRODUCT.UPDATED_AT      = DateTime.Now;
                sTOREpRODUCT.UNIT_LEFT       = sTOREpRODUCT.UNIT_LEFT + PurCarList.UNIT_SOLD;
                db.Entry(sTOREpRODUCT).State = EntityState.Modified;
                db.SaveChanges();
            }

            db.Database.ExecuteSqlCommand("TRUNCATE TABLE STORE_PURCHAGE_CART");
            return(RedirectToAction("ViewAll"));
        }
        // GET: Store/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            STORE_PRODUCTS sTORE_PRODUCTS = db.STORE_PRODUCTS.Find(id);

            if (sTORE_PRODUCTS == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CATEGORY_ID       = new SelectList(db.STORE_CATEGORY, "ID", "NAME", sTORE_PRODUCTS.CATEGORY_ID);
            ViewBag.PURCHASED_THROUGH = sTORE_PRODUCTS.PURCHASED_THROUGH;
            ViewBag.PAID_BY           = sTORE_PRODUCTS.PAID_BY;
            DateTime PDate = Convert.ToDateTime(sTORE_PRODUCTS.PURCHASED_ON);

            ViewBag.PURCHASED_ON = PDate.ToShortDateString();
            return(View(sTORE_PRODUCTS));
        }
        public ActionResult Purchase([Bind(Include = "ID,PRODUCT_ID,UNIT_SOLD,SOLD_PRICE,SOLD_BY,SOLD_ON,STUDENT_NAME,STUDENT_CONTACT_NO,MONEY_RECEIVED_BY,IS_DEPOSITED,IS_ACT,IS_DEL,CREATED_AT,UPDATED_AT")] STORE_PURCHAGE_CART sTORE_PURCHAGE_cART)
        {
            if (ModelState.IsValid)
            {
                sTORE_PURCHAGE_cART.IS_DEL     = "N";
                sTORE_PURCHAGE_cART.CREATED_AT = DateTime.Now;
                sTORE_PURCHAGE_cART.UPDATED_AT = DateTime.Now;
                db.STORE_PURCHAGE_CART.Add(sTORE_PURCHAGE_cART);
                db.SaveChanges();
                STORE_PRODUCTS sTOREpRODUCT = db.STORE_PRODUCTS.Find(sTORE_PURCHAGE_cART.PRODUCT_ID);
                sTOREpRODUCT.UPDATED_AT      = DateTime.Now;
                sTOREpRODUCT.UNIT_LEFT       = sTOREpRODUCT.UNIT_LEFT - sTORE_PURCHAGE_cART.UNIT_SOLD;
                db.Entry(sTOREpRODUCT).State = EntityState.Modified;
                db.SaveChanges();

                ViewBag.CartItems = (from t in db.STORE_PURCHAGE_CART
                                     select t).Count();
                return(RedirectToAction("ViewAll"));
            }

            ViewBag.PRODUCT_ID = new SelectList(db.STORE_PRODUCTS, "PRODUCT_ID", "NAME", sTORE_PURCHAGE_cART.PRODUCT_ID);
            return(View(sTORE_PURCHAGE_cART));
        }
        // GET: Purchase/Create
        public ActionResult Purchase(int?id)
        {
            //ViewBag.PRODUCT_ID = new SelectList(db.STORE_PRODUCTS.Where(o => o.PRODUCT_ID == id).ToList(), "PRODUCT_ID", "NAME");
            //ViewBag.CartItems = (from t in db.STORE_PURCHAGE_CART
            //                    select t).Count();

            STORE_PRODUCTS sTOREpRODUCT        = db.STORE_PRODUCTS.Find(id);
            var            sTORE_PURCHAGE_cART = new STORE_PURCHAGE_CART()
            {
                PRODUCT_ID = sTOREpRODUCT.PRODUCT_ID, UNIT_SOLD = 1, SOLD_PRICE = sTOREpRODUCT.SELL_PRICE_PER_UNIT, SOLD_BY = this.Session["UserId"].ToString(), SOLD_ON = DateTime.Now, STUDENT_NAME = null, STUDENT_CONTACT_NO = null, MONEY_RECEIVED_BY = null, IS_DEPOSITED = null, IS_ACT = null, IS_DEL = null, CREATED_AT = DateTime.Now, UPDATED_AT = DateTime.Now
            };

            db.STORE_PURCHAGE_CART.Add(sTORE_PURCHAGE_cART);
            db.SaveChanges();

            sTOREpRODUCT.UPDATED_AT      = DateTime.Now;
            sTOREpRODUCT.UNIT_LEFT       = sTOREpRODUCT.UNIT_LEFT - 1;
            db.Entry(sTOREpRODUCT).State = EntityState.Modified;
            db.SaveChanges();

            ViewBag.CartItems = (from t in db.STORE_PURCHAGE_CART
                                 select t).Count();
            return(RedirectToAction("ViewAll"));
        }