Пример #1
0
        public ActionResult CreateNewProduct(ProductViewModels form)
        {
            if (Session["employee"] == null)
            {
                return(RedirectToAction("Login", "Employee"));
            }
            //ViewBag.Carts = waitingCarts;
            //ViewBag.Color = db.colors.ToList();
            employee           thisAccount = (employee)Session["employee"];
            HttpPostedFileBase file        = form.ImagePath;

            if (file != null && file.ContentLength > 0)
            {
                string extend   = Path.GetExtension(file.FileName);
                string fileName = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))
                                  .TotalSeconds
                                  .ToString() + extend;
                string path = Path.Combine(Server.MapPath(Utility.PATH_IMG_PRODUCT), fileName);

                product newProduct = new product();

                newProduct.product_price   = form.Price;
                newProduct.product_quantum = form.Quantum;
                db.products.InsertOnSubmit(newProduct);
                db.SubmitChanges();
                newProduct.product_id = db.products.OrderByDescending(u => u.product_id).FirstOrDefault().product_id;

                product_detail product_Detail = new product_detail();

                product_img product_Img = new product_img();
                product_Img.product_id       = newProduct.product_id;
                product_Img.product_img_path = Utility.CorrectPath(path);

                file.SaveAs(path);
                db.ExecuteQuery <product_detail>("Insert into product_detail " +
                                                 "values({0}, {1}, {2}, {3})",
                                                 newProduct.product_id, form.Name, form.Tag, form.Decrible);
                db.ExecuteQuery <product_img>("insert into product_img values ({0}, {1}, {2})", newProduct.product_id, product_Img.product_img_path, form.ProductColor);
                //db.customer_imgs.InsertOnSubmit(customer_Img);
                db.SubmitChanges();

                return(RedirectToAction("Product", "Employee"));
            }
            return(View());
        }
Пример #2
0
        public ActionResult EditProduct(ProductViewModels form)
        {
            if (Session["employee"] == null)
            {
                return(RedirectToAction("Login", "Employee"));
            }
            //ViewBag.Carts = waitingCarts;
            //ViewBag.Color = db.colors.ToList();
            employee           thisAccount = (employee)Session["employee"];
            HttpPostedFileBase file        = form.ImagePath;

            if (file != null && file.ContentLength > 0)
            {
                string extend   = Path.GetExtension(file.FileName);
                string fileName = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))
                                  .TotalSeconds
                                  .ToString() + extend;
                string path = Path.Combine(Server.MapPath(Utility.PATH_IMG_PRODUCT), fileName);

                product product = db.products.FirstOrDefault(m => m.product_id.Equals(form.Id));

                product.product_price   = form.Price;
                product.product_quantum = form.Quantum;

                product_detail product_detail = db.product_details.FirstOrDefault(m => m.product_id.Equals(form.Id));

                product_detail.product_decrible = form.Decrible;
                product_detail.product_name     = form.Name;
                product_detail.product_tag      = form.Tag;

                product_img product_img = db.product_imgs.FirstOrDefault(m => m.product_id.Equals(form.Id));
                product_img.color_id         = form.ProductColor;
                product_img.product_img_path = Utility.CorrectPath(path);

                file.SaveAs(path);

                db.SubmitChanges();

                return(RedirectToAction("Product", "Employee"));
            }
            return(View());
        }