示例#1
0
        public ActionResult Create(Production production)
        {
            if (ModelState.IsValid)
            {
                db.Productions.Add(production);
                db.SaveChanges();

                // Create new production photo
                ProductionPhoto defaultPhoto = new ProductionPhoto
                {
                    Title        = production.Title,
                    Description  = production.Description,
                    Image        = ProductionPhotosController.FileToBytes(production.File),
                    Production   = production,
                    ProductionId = production.ProductionId
                };

                db.ProductionPhotos.Add(defaultPhoto);
                db.SaveChanges();

                production.DefaultPhoto = defaultPhoto;
                production.ProPhotoID   = defaultPhoto.ProPhotoId;

                db.Entry(production).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(production));
        }
示例#2
0
        public ActionResult Edit(Production production)
        {
            if (ModelState.IsValid)
            {
                // Can't pass DefaultPhoto as a Hidden form, so this is necessary to reset the photo with
                // the ProPhotoID passed through the form
                production.DefaultPhoto = db.ProductionPhotos.Find(production.ProPhotoID);

                db.Entry(production).State = EntityState.Modified;
                db.SaveChanges();

                // Update DefaultPhoto's image if a new file was uploaded
                if (production.File != null)
                {
                    byte[] image = ProductionPhotosController.FileToBytes(production.File);
                    production.DefaultPhoto.Image = image;

                    db.Entry(production.DefaultPhoto).State = EntityState.Modified;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            return(View(production));
        }