示例#1
0
        public ActionResult Create([Bind(Include = "PostID,PTitle,Post_content,AdminID,Datepost,Status,ToppicID")] Post post, string linkImg)
        {
            StringBuilder sb = new StringBuilder();

            if (ModelState.IsValid)
            {
                string x = RandomNumber(1, 9999999).ToString();
                post.PostID   = x;
                post.Datepost = DateTime.Now;
                post.AdminID  = Session["AdminID"].ToString();
                post.Status   = "Disable";
                db.Posts.Add(post);
                db.SaveChanges();
                db = new ModelContext1();
                RepresentImage RIM = new RepresentImage();
                RIM.IMGID  = x;
                RIM.PostID = post.PostID;
                RIM.Image  = linkImg;
                db.RepresentImages.Add(RIM);
                db.SaveChanges();
                db = new ModelContext1();
                return(RedirectToAction("IndexDisable", "Posts"));
            }

            ViewBag.AdminID  = new SelectList(db.Admins, "AdminID", "Name", post.AdminID);
            ViewBag.ToppicID = new SelectList(db.Toppics, "ToppicID", "Toppic1", post.ToppicID);
            return(View(post));
        }
示例#2
0
 public ActionResult Create([Bind(Include = "ProductID,PName,Price,BrandID,Status")] Product product)
 {
     if (ModelState.IsValid)
     {
         product.Status = true;
         db.Products.Add(product);
         db.SaveChanges();
         db = new ModelContext1();
         Promotion pro = new Promotion();
         pro.PromotionID = RandomString(5, true);
         pro.ProductID   = product.ProductID;
         pro.Promotion1  = 0;
         db.Promotions.Add(pro);
         db.SaveChanges();
         db = new ModelContext1();
         SPro s = new SPro();
         s.ProductID = product.ProductID;
         s.Quantity  = 0;
         db.SProes.Add(s);
         db.SaveChanges();
         db = new ModelContext1();
         LPro l = new LPro();
         l.ProductID = product.ProductID;
         l.Quantity  = 0;
         db.LProes.Add(l);
         db.SaveChanges();
         db = new ModelContext1();
         MPro m = new MPro();
         m.ProductID = product.ProductID;
         m.Quantity  = 0;
         db.MProes.Add(m);
         db.SaveChanges();
         db = new ModelContext1();
         XLPro xl = new XLPro();
         xl.ProductID = product.ProductID;
         xl.Quantity  = 0;
         db.XLProes.Add(xl);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BrandID = new SelectList(db.Brands, "BrandID", "BName", product.BrandID);
     return(View(product));
 }
示例#3
0
        public RedirectToRouteResult CreateOr(Order order)
        {
            if (Session["CustomerID"] == null)
            {
                return(RedirectToAction("Login", "Customers"));
            }
            else
            {
                List <CartItem> SCart = Session["SCart"] as List <CartItem>;
                double          b     = 0;
                if (SCart != null)
                {
                    if (ModelState.IsValid)
                    {
                        order.OrderID    = RandomString(5, true);
                        order.CustomerID = Session["CustomerID"].ToString();
                        order.Date       = DateTime.Now;
                        order.TotalPrice = 0;
                        db.Orders.Add(order);
                        db.SaveChanges();
                        db = new ModelContext1();
                    }
                    foreach (var po in SCart)
                    {
                        OrderDetail orderDetail = new OrderDetail();
                        orderDetail.OrderID   = order.OrderID;
                        orderDetail.ProductID = po.ProductID;
                        orderDetail.Promotion = po.Promotion12;
                        orderDetail.Price     = po.Price;
                        orderDetail.Size      = po.Size;
                        orderDetail.Quantity  = po.Quantity;
                        orderDetail.Total     = po.Toltal;
                        b = b + po.Toltal;
                        db.OrderDetails.Add(orderDetail);
                        db.SaveChanges();
                        db = new ModelContext1();

                        CartItem cardS = SCart.FirstOrDefault(m => m.ProductID == po.ProductID && m.Size == "S");
                        if (cardS != null)
                        {
                            var ms = db.SProes.SingleOrDefault(m => m.ProductID == cardS.ProductID);
                            if (ms != null)
                            {
                                ms.Quantity = ms.Quantity - cardS.Quantity;
                            }
                        }
                        db.SaveChanges();

                        db = new ModelContext1();
                        CartItem cardM = SCart.FirstOrDefault(m => m.ProductID == po.ProductID && m.Size == "M");
                        if (cardM != null)
                        {
                            var mm = db.MProes.SingleOrDefault(m => m.ProductID == cardM.ProductID);
                            if (mm != null)
                            {
                                mm.Quantity = mm.Quantity - cardM.Quantity;
                            }
                        }
                        db.SaveChanges();

                        db = new ModelContext1();
                        CartItem cardL = SCart.FirstOrDefault(m => m.ProductID == po.ProductID && m.Size == "L");
                        if (cardL != null)
                        {
                            var ml = db.LProes.SingleOrDefault(m => m.ProductID == cardL.ProductID);
                            if (ml != null)
                            {
                                ml.Quantity = ml.Quantity - cardL.Quantity;
                            }
                        }
                        db.SaveChanges();

                        db = new ModelContext1();
                        CartItem cardXL = SCart.FirstOrDefault(m => m.ProductID == po.ProductID && m.Size == "XL");
                        if (cardXL != null)
                        {
                            var mxl = db.XLProes.SingleOrDefault(m => m.ProductID == cardXL.ProductID);
                            if (mxl != null)
                            {
                                mxl.Quantity = mxl.Quantity - cardXL.Quantity;
                            }
                        }
                        db.SaveChanges();
                    }
                    db = new ModelContext1();
                    var tol = db.Orders.FirstOrDefault(m => m.OrderID == order.OrderID);
                    tol.TotalPrice = b;
                    db.SaveChanges();
                    SCart.Clear();
                }
            }
            ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "CName", order.CustomerID);
            return(RedirectToAction("IndexCustomer", "Products"));
        }