public ActionResult PhotoForm(Photos photo, int id) { var allowedExtensions = new[] { ".png", ".jpg" }; if (ModelState.IsValid) { Photos pho = FrozenCrittersDb.GetPhoto(id); if (Request.Files.Count > 0 || Request.Files.Count != 0) { HttpPostedFileBase hpf = Request.Files[0]; var extension = Path.GetExtension(hpf.FileName); if (Request.Files[0].ContentLength > 0 && (allowedExtensions.Contains(extension))) { photo.PhotosFile = Guid.NewGuid() + Path.GetFileName(hpf.FileName); hpf.SaveAs(Path.Combine(Server.MapPath("//Content/img"), photo.PhotosFile)); } else { photo.PhotosFile = pho.PhotosFile; ViewBag.Error = "One of the file types you attempted to upload was incorrect. The file type must be a jpg or png"; return(View()); } } } if (Models.FrozenCrittersDb.EditPhoto(photo, id)) { return(RedirectToAction("Index", "Admin")); } return(View()); }
public ActionResult Products(int id) { List <Products> prods = FrozenCrittersDb.GetProductsPage(id); return(View(prods)); }