Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        // 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"));
        }