public ActionResult Checkout()
        {
            if (Session["customerName"] == null && Session["customerID"] == null)
            {
                return(RedirectToAction("Login", "Customer"));
            }

            float       totalPrice = 0;
            int         VendorID   = 0;
            List <Cart> cart_list  = Session["my_cart"] != null ? (List <Cart>)Session["my_cart"] : new List <Cart>();

            tblOrder order = new tblOrder();
            List <tblOrderDetail> orderDetailList = new List <tblOrderDetail>();

            foreach (var item in cart_list)
            {
                tblOrderDetail orderDetails = new tblOrderDetail();

                orderDetails.productID         = item.productID;
                orderDetails.productTotalPrice = item.productTotalPrice;
                orderDetails.productUnitPrice  = item.productUnitPrice;
                orderDetails.productQty        = item.productQty;

                VendorID = item.vendorID;

                orderDetailList.Add(orderDetails);

                totalPrice += item.productTotalPrice;
            }

            int         custID   = Convert.ToInt32(Session["customerID"]);
            tblCustomer customer = db.tblCustomers.Where(x => x.customerID == custID).FirstOrDefault();

            order.vendorID              = VendorID;
            order.orderStatus           = 1;
            order.customerID            = Convert.ToInt32(Session["customerID"]);
            order.totalOrderPrice       = totalPrice;
            order.orderDelieveryAddress = customer.customerAddress;
            order.orderPlacedTime       = DateTime.Now;
            order.tblOrderDetails       = orderDetailList;

            db.tblOrders.Add(order);
            db.SaveChanges();

            int orderID = order.orderID;

            foreach (tblOrderDetail order_det in order.tblOrderDetails)
            {
                order_det.orderID         = orderID;
                db.Entry(order_det).State = EntityState.Modified;
            }
            db.SaveChanges();

            Session.Remove("my_cart");

            return(RedirectToAction("DashBoard", "Customer"));
        }
        public ActionResult AddProduct_Post([Bind(Include = "productName, productDescription, productPrice, productCategory, productQuantity")] tblProduct tblProduct, List <HttpPostedFileBase> file)
        {
            List <tblImage> prodImages = new List <tblImage>();
            // prodImages = null;
            var path = "";

            foreach (var item in file)
            {
                if (item != null)
                {
                    tblImage img = new tblImage();
                    img.ImageFile = new byte[item.ContentLength];
                    img.ImageName = string.Format(@"{0}.JPG", Guid.NewGuid());
                    //        img.prod_ID = latestProdID;
                    img.vend_ID = Convert.ToInt32(Session["userID"]);

                    item.InputStream.Read(img.ImageFile, 0, item.ContentLength);

                    path = Path.Combine(Server.MapPath("~/Content/img"), img.ImageName);
                    var pathForDB = "~/Content/img/" + img.ImageName;
                    item.SaveAs(path);
                    img.ImagePath = pathForDB;
                    prodImages.Add(img);
                }
            }

            tblProduct.venodrID = Convert.ToInt32(Session["userID"]);
            if (prodImages.Count != 0)
            {
                tblProduct.productThumbnailPath = prodImages.First().ImagePath;
                tblProduct.tblImages            = prodImages;
            }


            if (ModelState.IsValid)
            {
                db.tblProducts.Add(tblProduct);
                db.SaveChanges();
                int latestProdID = tblProduct.productID;

                foreach (tblImage tblImg in tblProduct.tblImages)
                {
                    tblImg.prod_ID         = latestProdID;
                    db.Entry(tblImg).State = EntityState.Modified;
                }
                db.SaveChanges();

                return(RedirectToAction("DashBoard"));
            }
            ViewBag.productCategory = new SelectList(db.tblCategories, "categoryID", "categoryName");
            ViewBag.vendorGender    = new SelectList(db.tblGenders, "genderId", "genderName");
            return(View());
        }
 public ActionResult Edit([Bind(Include = "vendorID,vendorName,vendorEmail,vendorPassword,vendorAge,vendorAddress,vendorPhone,vendorGender,vendorType,vendorCNIC")] tblVendor tblVendor)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tblVendor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.vendorType   = new SelectList(db.tblBusinessTypes, "businessTypeId", "businessTypeName", tblVendor.vendorType);
     ViewBag.vendorGender = new SelectList(db.tblGenders, "genderId", "genderName", tblVendor.vendorGender);
     return(View(tblVendor));
 }
 public ActionResult Register_Post([Bind(Include = "customerID, customerName, customerAddress, customerGender, customerPhone, customerEmail, customerPassword")] tblCustomer tblcustomer)
 {
     if (ModelState.IsValid)
     {
         db.tblCustomers.Add(tblcustomer);
         db.SaveChanges();
         return(RedirectToAction("Login"));
     }
     ViewBag.vendorGender = new SelectList(db.tblGenders, "genderId", "genderName", tblcustomer.customerGender);
     return(View(tblcustomer));
 }