public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BeerProduct beerProduct = repository.Get(id); //BeerProduct beerProduct = db.Products.Find(id); if (beerProduct == null) { return(HttpNotFound()); } return(View(beerProduct)); }
public ActionResult Create([Bind(Include = "ProductId,ManufacturerId,Name,Quantity,Price,Description,ABV")] BeerProduct beerProduct, HttpPostedFileBase file, string imgPath) { if (ModelState.IsValid) { string _imgPath; repository.Add(beerProduct); repository.Save(); if (file != null) { Directory.CreateDirectory(HttpContext.Server.MapPath("~/Content/Images/") + beerProduct.ManufacturerId.ToString()); file.SaveAs(HttpContext.Server.MapPath("~/Content/Images/") + beerProduct.ManufacturerId.ToString() + "/" + beerProduct.ProductId + Path.GetExtension(file.FileName)); _imgPath = "/Content/Images/" + beerProduct.ManufacturerId.ToString() + "/" + beerProduct.ProductId + Path.GetExtension(file.FileName); } else if (imgPath != null) { _imgPath = imgPath; } else { _imgPath = "/Content/beer.png"; } beerProduct.ImgPath = _imgPath; repository.Update(beerProduct); repository.Save(); //db.Products.Add(beerProduct); //db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ManufacturerId = new SelectList(repository.GetManufacturers(), "ManufacturerId", "Name", beerProduct.ManufacturerId); //ViewBag.ManufacturerId = new SelectList(db.Manufacturers, "ManufacturerId", "Name", beerProduct.ManufacturerId); return(View(beerProduct)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BeerProduct beerProduct = repository.Get(id); //BeerProduct beerProduct = db.Products.Find(id); if (beerProduct == null) { return(HttpNotFound()); } ViewBag.CommonImgs = Directory.EnumerateFiles(Server.MapPath("~/Content/Images/Common/beers")) .Select(fn => "~/Content/Images/Common/beers/" + Path.GetFileName(fn)); ViewBag.ManufacturerId = new SelectList(repository.GetManufacturers(), "ManufacturerId", "Name", beerProduct.ManufacturerId); //ViewBag.ManufacturerId = new SelectList(db.Manufacturers, "ManufacturerId", "Name", beerProduct.ManufacturerId); return(View(beerProduct)); }
// GET: BeerProducts/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //BeerProduct beerProduct = db.Products.Include(b => b.BeerReviews) // .Where(b => b.ProductId == id) // .FirstOrDefault(); BeerProduct beerProduct = repository.Get(id); if (beerProduct == null) { return(HttpNotFound()); } //BeerProduct beerProduct = db.Products.Find(id); beerProduct.BeerReviews = beerProduct.BeerReviews.OrderByDescending(br => br.DateTime).ToList(); return(View(beerProduct)); }