示例#1
0
        public ActionResult ProductAddToCart(int ProductID)
        {
            string sms            = "";
            string getLogInUser   = User.Identity.Name;
            string memberId       = db.tbl_members.FirstOrDefault(x => x.Phone1 == getLogInUser).MemberID;
            var    isAlreadyAdded = db.tbl_add_to_cart.FirstOrDefault(x => x.ProductID == ProductID && x.MemberID == memberId);

            if (isAlreadyAdded == null)
            {
                var getProduct = db.tbl_products_master.FirstOrDefault(x => x.ProductID == ProductID);
                if (getProduct != null)
                {
                    tbl_add_to_cart adc = new tbl_add_to_cart();
                    adc.MemberID       = memberId;
                    adc.ProductID      = getProduct.ProductID;
                    adc.ProductName    = getProduct.ProductName;
                    adc.Category       = getProduct.Category;
                    adc.Type           = getProduct.Type;
                    adc.Code           = getProduct.Code;
                    adc.MRP            = getProduct.MRP;
                    adc.DP             = getProduct.DP;
                    adc.MRP            = getProduct.MRP;
                    adc.WP             = getProduct.WP;
                    adc.PP             = getProduct.PP;
                    adc.RB             = getProduct.RB;
                    adc.BP             = getProduct.BP;
                    adc.Quantity       = 1;
                    adc.ProductDetails = getProduct.ProductDetails;
                    adc.UserName       = User.Identity.Name;
                    adc.Vat            = getProduct.Vat * (decimal)adc.Quantity;
                    db.tbl_add_to_cart.Add(adc);
                    db.SaveChanges();

                    sms = "Successfully Added To Cart.";
                    return(RedirectToAction("ProductPurchase", new { sms = sms }));
                }
                else
                {
                    sms = "Add To Cart Failed.";
                    return(RedirectToAction("ProductPurchase", new { sms = sms }));
                }
            }
            else
            {
                isAlreadyAdded.Quantity = isAlreadyAdded.Quantity + 1;
                db.SaveChanges();
                return(RedirectToAction("ProductPurchase", new { sms = sms }));
            }
            //else
            //{
            //    sms = "Already Added To Cart.";
            //    return RedirectToAction("ProductPurchase", new { sms = sms });
            //}
        }
示例#2
0
        public ActionResult PostOrder(OrderViewModel orderViewModel)
        {
            ViewBag.PageTitle = "ORDER MANAGEMENT";
            Dictionary <string, string> PanelTitles = new Dictionary <string, string>();

            PanelTitles["AddNewOrder"] = "ADD NEW ORDER";
            ViewBag.PanelTitles        = PanelTitles;
            var isAlreadyAdded = db.tbl_add_to_cart.FirstOrDefault(x => x.Code == orderViewModel.ProductCode && x.MemberID == orderViewModel.MemberID);

            if (isAlreadyAdded == null)
            {
                var getProduct = db.tbl_products_master.FirstOrDefault(x => x.Code == orderViewModel.ProductCode);
                if (getProduct != null)
                {
                    tbl_add_to_cart adc = new tbl_add_to_cart();
                    adc.MemberID       = orderViewModel.MemberID;
                    adc.ProductID      = getProduct.ProductID;
                    adc.ProductName    = getProduct.ProductName;
                    adc.Category       = getProduct.Category;
                    adc.Type           = getProduct.Type;
                    adc.Code           = getProduct.Code;
                    adc.DP             = getProduct.DP;     //* (int)orderViewModel.Quantity;
                    adc.MRP            = getProduct.MRP;    // * (int)orderViewModel.Quantity;
                    adc.WP             = getProduct.WP;     // *(int)orderViewModel.Quantity;
                    adc.PP             = getProduct.PP;     // * (int)orderViewModel.Quantity;
                    adc.RB             = orderViewModel.RB; // * (int)orderViewModel.Quantity;
                    adc.BP             = orderViewModel.BP; // * (int)orderViewModel.Quantity;
                    adc.Quantity       = (int)orderViewModel.Quantity;
                    adc.ProductDetails = getProduct.ProductDetails;
                    adc.UserName       = User.Identity.Name;
                    adc.Vat            = getProduct.Vat; // * (decimal)orderViewModel.Quantity;
                    db.tbl_add_to_cart.Add(adc);
                    db.SaveChanges();
                    return(Json(adc, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(0, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                var getProduct = db.tbl_products_master.FirstOrDefault(x => x.Code == orderViewModel.ProductCode);
                if (getProduct != null)
                {
                    isAlreadyAdded.MemberID        = orderViewModel.MemberID;
                    isAlreadyAdded.ProductID       = getProduct.ProductID;
                    isAlreadyAdded.ProductName     = getProduct.ProductName;
                    isAlreadyAdded.Category        = getProduct.Category;
                    isAlreadyAdded.Type            = getProduct.Type;
                    isAlreadyAdded.Code            = getProduct.Code;
                    isAlreadyAdded.MRP             = getProduct.MRP;
                    isAlreadyAdded.WP              = getProduct.WP;
                    isAlreadyAdded.PP              = getProduct.PP;
                    isAlreadyAdded.RB              = orderViewModel.RB;
                    isAlreadyAdded.BP              = orderViewModel.BP;
                    isAlreadyAdded.Quantity        = (int)orderViewModel.Quantity;
                    isAlreadyAdded.ProductDetails  = getProduct.ProductDetails;
                    isAlreadyAdded.UserName        = User.Identity.Name;
                    isAlreadyAdded.Vat             = getProduct.Vat * (decimal)orderViewModel.Quantity;
                    db.Entry(isAlreadyAdded).State = EntityState.Modified;
                    db.SaveChanges();
                    return(Json(isAlreadyAdded, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(0, JsonRequestBehavior.AllowGet));
                }
            }
        }