public ActionResult Edit(Show show, HttpPostedFileBase photo)
        {
            if (ModelState.IsValid)
            {
                UploadPhoto(show, photo);
                profile.Shows.First(s => s.ID == show.ID).update(show);
                return RedirectToAction("Index");
            }

            return View(show);
        }
 public ActionResult Create(Show show, HttpPostedFileBase photo)
 {
     try
     {
         UploadPhoto(show, photo);
         profile.Shows.Add(show);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
Exemple #3
0
 public void update(Show show)
 {
     VenueName = show.VenueName;
     VenueWebsite = show.VenueWebsite;
     VenueLocation = show.VenueLocation;
     if (!string.IsNullOrEmpty(show.PhotoUrl))
     {
         PhotoUrl = show.PhotoUrl;
     }
     Description = show.Description;
     Date = show.Date;
     MapHtml = show.MapHtml;
 }
 private void UploadPhoto(Show show, HttpPostedFileBase photo)
 {
     if (photo != null && photo.ContentLength > 0)
     {
         try
         {
             show.PhotoUrl = Path.GetFileName(photo.FileName);
             var path = Path.Combine(Server.MapPath("~/Content/images/shows"), show.PhotoUrl);
             photo.SaveAs(path);
         }
         catch (Exception ex)
         {
             show.PhotoUrl = string.Empty;
             ModelState.AddModelError("photo", string.Format("Error Uploading Image: {0}", ex.Message));
         }
     }
 }