예제 #1
0
        //==========================================================



        //==========================================================
        // GET: AdminPanel/Prices/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShopProductsPrice price = db.ShopProductsPrices.Find(id);

            if (price == null)
            {
                return(HttpNotFound());
            }

            ViewProductPriceEdit model = new ViewProductPriceEdit
            {
                Id           = price.Id,
                Price        = price.Price.ToString(),
                ProductId    = price.ShopProduct.Id,
                CurrentPrice = price.CurrentPrice
            };

            return(View(model));
        }
예제 #2
0
 public ActionResult Edit(ViewProductPriceEdit model)
 {
     if (ModelState.IsValid)
     {
         ShopProductsPrice price = db.ShopProductsPrices.Find(model.Id);
         if (model.CurrentPrice != price.CurrentPrice)
         {
             price.CurrentPrice = model.CurrentPrice;
             ShopProductsPrice ollCurrentPrice = db.ShopProductsPrices.Where(p => p.ShopProduct.Id == model.ProductId && p.CurrentPrice == model.CurrentPrice).SingleOrDefault();
             if (ollCurrentPrice != null)
             {
                 ollCurrentPrice.CurrentPrice    = !model.CurrentPrice;
                 db.Entry(ollCurrentPrice).State = EntityState.Modified;
                 db.SaveChanges();
             }
         }
         price.Price           = decimal.Parse(model.Price);
         db.Entry(price).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Details", "Products", new { id = model.ProductId }));
     }
     return(View(model));
 }