Example #1
0
 public ActionResult Create([Bind(Include = "ProductionId,Title,Playwright,Description,Runtime,OpeningDay,ClosingDay,DefaultPhoto,ShowtimeEve,ShowtimeMat,TicketLink,Season,IsCurrent,IsWorldPremiere")] Production production, HttpPostedFileBase uploadFile)
 {
     //========== VALIDATION ==========
     //===== PHOTO - Check if photo is not null but not a valid photo format
     if (uploadFile != null && !PhotoController.ValidatePhoto(uploadFile))
     {
         ModelState.AddModelError("DefaultPhoto", "File must be a valid photo format.");
     }
     //===== SHOWTIME - at list one (ShowtimeEve, ShowtimeMat) need to be assigned
     if (production.ShowtimeEve == null && production.ShowtimeMat == null)
     {
         ModelState.AddModelError("ShowtimeEve", "At least one showtime must be specified.");
         ModelState.AddModelError("ShowtimeMat", "At least one showtime must be specified.");
     }
     //========== SAVE ==========
     if (ModelState.IsValid)
     {
         //===== DEFAULT PHOTO
         //--- save photo using photo controller, save entry to ProductionPhotos, photoName set to production title, description set to "Default Photo"
         if (uploadFile != null)
         {
             //----- Save New Photo or retrieve existing photo if the same - using photo controller
             Debug.WriteLine("Saving photo...");
             int photoId = PhotoController.CreatePhoto(uploadFile, production.Title);
             //----- Save New ProductionPhoto
             var productionPhoto = new ProductionPhotos()
             {
                 PhotoId = photoId, Title = production.Title, Description = "Default Photo"
             };
             db.ProductionPhotos.Add(productionPhoto);
             db.SaveChanges();
             //----- Save New Production, add DefaultPhoto object reference to production
             production.DefaultPhoto = productionPhoto;
             db.Productions.Add(production);
             db.SaveChanges();
             //----- Add Production object reference to productionPhoto
             productionPhoto.Production      = production;
             db.Entry(productionPhoto).State = EntityState.Modified;
             db.SaveChanges();
         }
         //===== NO PHOTO
         else
         {
             db.Productions.Add(production);
             db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     return(View(production));
 }
        public ActionResult Edit([Bind(Include = "InfoId,Title,TextContent,Image, File")] DisplayInfo displayInfo, HttpPostedFileBase file)
        {
            //validates photo
            if (file != null && !PhotoController.ValidatePhoto(file))
            {
                ModelState.AddModelError("Photo", "File must be a valid photo format.");
            }

            if (ModelState.IsValid)
            {
                if (file != null && file.ContentLength > 0)
                {
                    //updates the new displayInfo's photo, and textcontent
                    displayInfo.PhotoId = PhotoController.CreatePhoto(file, "DisplayInfoPhoto_" + displayInfo.Title);
                }
                db.Entry(displayInfo).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(displayInfo));
        }