Ejemplo n.º 1
0
        // PUT: odata/Movies(5)
        public IHttpActionResult Put([FromODataUri] int key, Movie movie)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (key != movie.ID)
            {
                return(BadRequest());
            }

            db.Entry(movie).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MovieExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(movie));
        }
        protected override Movie UpdateEntity(int key, Movie update)
        {
            if (GetEntityByKey(key) == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            if (key != update.ID)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid update: ID does not match."));
            }

            Movie updatedEntity = _db.Movies.Attach(update);

            _db.Entry(update).State = EntityState.Modified;
            _db.SaveChanges();
            return(updatedEntity);
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,MovieName,Rating,ReleaseDate")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                db.Entry(movie).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(movie));
        }
Ejemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "MovieId,Name,DirectorName,Description,Year,GenreId")] Movie movie, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         if (file != null)
         {
             file.SaveAs(HttpContext.Server.MapPath("~/Images/")
                         + file.FileName);
             movie.ImagePath = file.FileName;
         }
         db.Entry(movie).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("AllMovies"));
     }
     ViewBag.GenreId = new SelectList(db.Genres, "Id", "Name", movie.GenreId);
     return(View(movie));
 }