public ActionResult CreateBuy() { WantThis.Source.BuyWrapper product = new WantThis.Source.BuyWrapper(); return View(product); }
public ActionResult EditBuy(int id, FormCollection formValues) { Models.Product product = productRepo.getProduct(id); if (!product.isOwnedBy(User.Identity.Name)) return View("InvalidOwner"); BuyWrapper bw = new BuyWrapper(); double price = Convert.ToDouble(formValues["price"]); try { product.Name = Request.Form["product_wrapper.product.Name"]; product.Description = Request.Form["product_wrapper.product.Description"]; product.Features = Request.Form["product_wrapper.product.Features"]; product.Category = Request.Form["product_wrapper.product.Category"]; bw.product_wrapper = new ProductWrapper(product); bw.price = Convert.ToInt32(price); productRepo.Save(); if (price < 0 || price > 10000) throw new Exception(); Buy b = productRepo.getBuy(id); b.Price = price; productRepo.Save(); return RedirectToAction("UploadImage", new { id = product.ProductID }); } catch { foreach (var issue in bw.GetRuleViolations()) { ModelState.AddModelError(issue.PropertyName, issue.ErrorMessage); } } return View(new BuyWrapper(new Source.ProductWrapper(product),Convert.ToInt32(price))); }