public ActionResult MovieEdit(Movy model, HttpPostedFileBase file)
 {
     using (var context = new MovieDBEntities())
     {
         var movie = context.Movies.Find(model.Id);
         if (movie.Inserted_UserId != User.Identity.GetUserId())
         {
             ModelState.AddModelError("", "У вас нет прав на изменения.");
         }
         if (!ModelState.IsValid)
         {
             return(View(model));
         }
         if (file != null && file.ContentLength != 0)
         {
             var fileBytes = new byte[file.ContentLength];
             file.InputStream.Read(fileBytes, 0, file.ContentLength);
             movie.Poster = fileBytes;
         }
         movie.Updated_Date         = DateTime.Now;
         movie.Title                = model.Title;
         movie.Producer             = model.Producer;
         movie.Year                 = model.Year;
         movie.Description          = model.Description;
         context.Entry(movie).State = EntityState.Modified;
         var result = context.SaveChanges();
         if (result > 0)
         {
             return(RedirectToAction("MovieDetails", new { id = model.Id }));
         }
     }
     return(View(model));
 }
Beispiel #2
0
        public IHttpActionResult PutMovieInfo(int id, MovieInfo movieInfo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != movieInfo.ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public ActionResult Edit([Bind(Include = "AuthorID,AuthorFirstName,AuthorUserName")] Author author)
 {
     if (ModelState.IsValid)
     {
         db.Entry(author).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(author));
 }
Beispiel #4
0
 public ActionResult Edit([Bind(Include = "MovieID,Title,Director,Genre")] Movie movie)
 {
     if (ModelState.IsValid)
     {
         db.Entry(movie).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(movie));
 }
 public ActionResult Edit([Bind(Include = "CustomerID,FirstName,LastName,PhoneNumber")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Beispiel #6
0
 public ActionResult Edit([Bind(Include = "GenreID,GenreName")] Genre genre)
 {
     if (ModelState.IsValid)
     {
         db.Entry(genre).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(genre));
 }
Beispiel #7
0
 public ActionResult Edit([Bind(Include = "ID,MovieName,MovieGenre,ReleaseDate,MovieCover")] Movy movy)
 {
     if (ModelState.IsValid)
     {
         db.Entry(movy).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(movy));
 }
        public async Task <ActionResult> Edit([Bind(Include = "id,name,releaseDate,director,email,language,category")] tblMovy tblMovy)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tblMovy).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(tblMovy));
        }
 public ActionResult Edit([Bind(Include = "RentalID,CustomerID,MovieID,Date")] Rental rental)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rental).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "FirstName", rental.CustomerID);
     ViewBag.MovieID    = new SelectList(db.Movies, "MovieID", "Title", rental.MovieID);
     return(View(rental));
 }
 public ActionResult Edit([Bind(Include = "MovieID,Title,ReleaseDate,Description,AuthorID,GenreID")] Movie movie)
 {
     if (ModelState.IsValid)
     {
         db.Entry(movie).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AuthorID = new SelectList(db.Author, "AuthorID", "AuthorFirstName", movie.AuthorID);
     ViewBag.GenreID  = new SelectList(db.Genre, "GenreID", "GenreName", movie.GenreID);
     return(View(movie));
 }
Beispiel #11
0
        public IHttpActionResult PutMoviesList(MovieRating movieRating)
        {
            List <MovieRating> rating = db.MovieRatings.AsNoTracking().Where(r => r.MovieId == movieRating.MovieId && r.UserId == movieRating.UserId).ToList();

            if (movieRating.Rating > 5 && movieRating.Rating <= 0)
            {
                ValidationError("Invalid Rating, It should be 1 to 5 Only", HttpStatusCode.BadRequest);
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (rating.Count == 0)
            {
                ValidationError("No Records Found", HttpStatusCode.NotFound);
            }

            db.Entry(movieRating).State = EntityState.Modified;
            db.SaveChanges();
            return(StatusCode(HttpStatusCode.OK));
        }