public ActionResult Create(ViewProductPriceCreate model) { if (ModelState.IsValid) { ShopProduct product = db.ShopProducts.Include(p => p.ShopProductsPrices).Where(p => p.Id == model.Id).SingleOrDefault(); ShopProductsPrice price = db.ShopProductsPrices.Where(p => p.ShopProduct.Id == product.Id && p.CurrentPrice).SingleOrDefault(); if (price != null) { price.CurrentPrice = false; db.Entry(price).State = EntityState.Modified; db.SaveChanges(); } price = new ShopProductsPrice { Price = decimal.Parse(model.Price), CurrentPrice = true, DateSet = DateTime.Now, ShopProduct = product }; db.ShopProductsPrices.Add(price); db.SaveChanges(); return(Redirect(model.URL)); //return RedirectToAction("Details", "Products", new { id = product.Id }); } return(View(model)); }
//========================================================== //========================================================== // GET: AdminPanel/Prices/Create public ActionResult Create(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ShopProduct product = db.ShopProducts.Find(id); if (product == null) { return(HttpNotFound()); } ViewProductPriceCreate model = new ViewProductPriceCreate { Id = id.Value, URL = HttpContext.Request.UrlReferrer.ToString() }; return(View(model)); }