Пример #1
0
        public RedirectResult Checkout()
        {
            if (Session["goods"] != null)
            {
                db.Orders.Add(new Order
                {
                    Location = HttpContext.Request.Cookies["location"]?.Value,
                    DateTime = DateTime.Now
                });
                db.SaveChanges();
                int          orderId = db.Orders.ToList().Last().OrderId;
                WatchOrdList listWO  = JsonSerializer.Deserialize <WatchOrdList>(Session["goods"].ToString());
                foreach (var WO in listWO)
                {
                    db.Purchase.Add(new Purchase
                    {
                        OrderID  = orderId,
                        WatchId  = WO.Watch.Id,
                        Quantity = WO.Quantity
                    });
                }
                db.SaveChanges();

                Session.Remove("goods");
            }

            return(Redirect("/Cart"));
        }
Пример #2
0
 public int Add(ProductEntity model)
 {
     using (_context)
     {
         _context.Products.Add(model);
         _context.SaveChanges();
         return(model.Id);
     }
 }
Пример #3
0
 public ActionResult Create(Review review)
 {
     if (ModelState.IsValid)
     {
         db.Reviews.Add(review);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(review));
 }
Пример #4
0
 public ActionResult Create(Choose choose)
 {
     if (ModelState.IsValid)
     {
         db.Chooses.Add(choose);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(choose));
 }
Пример #5
0
 public ActionResult Create(Feature feature)
 {
     if (ModelState.IsValid)
     {
         db.Features.Add(feature);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(feature));
 }
Пример #6
0
 public ActionResult Create(Grade grade)
 {
     if (ModelState.IsValid)
     {
         db.Grades.Add(grade);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(grade));
 }
Пример #7
0
 public ActionResult Create(Update update)
 {
     if (ModelState.IsValid)
     {
         db.Updates.Add(update);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(update));
 }
Пример #8
0
 public ActionResult Create(Watch watch)
 {
     if (ModelState.IsValid)
     {
         db.Watches.Add(watch);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(watch));
 }
Пример #9
0
 public ActionResult Create(TypeWatch typeWatch)
 {
     if (ModelState.IsValid)
     {
         db.TypesWatches.Add(typeWatch);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ChooseID = new SelectList(db.Chooses, "ChooseID", "ChooseID", typeWatch.ChooseID);
     return(View(typeWatch));
 }
Пример #10
0
 public ActionResult Create(Product product)
 {
     if (ModelState.IsValid)
     {
         db.Products.Add(product);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.FeatureID   = new SelectList(db.Features, "FeatureID", "FeatureID", product.FeatureID);
     ViewBag.TypeWatchID = new SelectList(db.TypesWatches, "TypeWatchID", "TypeWatchID", product.TypeWatchID);
     return(View(product));
 }
        public async Task <IActionResult> Edit(HomePageVM homePageVM)
        {
            Product product = await _context.Products.FindAsync(homePageVM.Product.Id);

            var        image       = _context.Images.Where(i => i.ProductId == product.Id).ToList();
            HomePageVM homePageVMs = new HomePageVM()
            {
                Product = product,
                Images  = image
            };

            if (!ModelState.IsValid)
            {
                return(View(homePageVMs));
            }
            var productDb = await _context.Products.FindAsync(homePageVM.Product.Id);

            if (homePageVM.ProductPhotos != null)
            {
                try
                {
                    var ImgList = _context.Images.Where(v => v.ProductId == productDb.Id).ToList();
                    for (int i = 0; i < homePageVM.ProductPhotos.Count; i++)
                    {
                        IFormFileExstensions.Delete(_env.WebRootPath, "images", ImgList[i].ProductImage);

                        var newPhoto = await homePageVM.ProductPhotos[i].SaveFileAsync(_env.WebRootPath, "images");


                        ImgList[i].ProductImage = newPhoto;
                        _context.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "Unexpected error happened while saving image. Please, try again.");
                    return(View(homePageVMs));
                }
            }

            productDb.Name            = homePageVM.Product.Name;
            productDb.Price           = homePageVM.Product.Price;
            productDb.HasDiscount     = homePageVM.Product.HasDiscount;
            productDb.DiscountedPrice = homePageVM.Product.DiscountedPrice;
            productDb.Color           = homePageVM.Product.Color;
            productDb.Availability    = homePageVM.Product.Availability;
            productDb.Status          = true;
            productDb.InStock         = homePageVM.Product.InStock;
            productDb.BrandId         = homePageVM.Product.BrandId;

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }