Ejemplo n.º 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));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ProductionPhoto photo = db.ProductionPhotos.Find(id);

            db.ProductionPhotos.Remove(photo);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult Upload(ProductionPhoto photo)
        {
            // Convert uploaded file to byte[]
            photo.Image = FileToBytes(photo.File);

            // If form is filled out correctly, add new photo to database and redirect to index
            if (ModelState.IsValid)
            {
                db.ProductionPhotos.Add(photo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(photo));
        }
        // GET: Prod/ProductionPhotos/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ProductionPhoto photo = db.ProductionPhotos.Find(id);

            if (photo == null)
            {
                return(HttpNotFound());
            }

            return(View(photo));
        }
        public ActionResult Edit(ProductionPhoto photo)
        {
            // Convert uploaded file to byte[] if new photo is uploaded
            if (photo.File != null)
            {
                photo.Image = FileToBytes(photo.File);
            }

            // If form is filled out correctly, save changes to database and redirect to Index
            if (ModelState.IsValid)
            {
                db.Entry(photo).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(photo));
        }
        // GET: Prod/ProductionPhotos/Edit/5
        public ActionResult Edit(int?id)
        {
            // If no ID provided, return bad request code
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            // Find photo in database by ID
            ProductionPhoto photo = db.ProductionPhotos.Find(id);

            // If photo is null, return HttpNotFound
            if (photo == null)
            {
                return(HttpNotFound());
            }

            return(View(photo));
        }
        public ActionResult Edit(ProductionPhoto photo)
        {
            // Update production with production that was selected
            photo.Production = db.Productions.Find(photo.ProductionId);

            // Convert uploaded file to byte[] if new photo is uploaded
            if (photo.File != null)
            {
                photo.Image = FileToBytes(photo.File);
            }

            // If form is filled out correctly, save changes to database and redirect to Index
            if (ModelState.IsValid)
            {
                db.Entry(photo).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductionList = GetProductionList();
            return(View(photo));
        }