예제 #1
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));
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "AuthorID,AuthorFirstName,AuthorUserName")] Author author)
        {
            if (ModelState.IsValid)
            {
                db.Author.Add(author);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(author));
        }
예제 #3
0
        public ActionResult Create([Bind(Include = "MovieID,Title,Director,Genre")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movie);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(movie));
        }
예제 #4
0
        public ActionResult Create([Bind(Include = "CustomerID,FirstName,LastName,PhoneNumber")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
예제 #5
0
        public ActionResult Create([Bind(Include = "GenreID,GenreName")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                db.Genre.Add(genre);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(genre));
        }
예제 #6
0
        public ActionResult Create([Bind(Include = "ID,MovieName,MovieGenre,ReleaseDate,MovieCover")] Movy movy)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movy);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(movy));
        }
예제 #7
0
        public ActionResult Create([Bind(Include = "RentalID,CustomerID,MovieID,Date")] Rental rental)
        {
            if (ModelState.IsValid)
            {
                db.Rentals.Add(rental);
                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));
        }
예제 #8
0
        public ActionResult Create([Bind(Include = "MovieID,Title,ReleaseDate,Description,AuthorID,GenreID")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                db.Movie.Add(movie);
                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));
        }
예제 #9
0
 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));
 }
예제 #10
0
        public ActionResult MovieAdd(Movy model, HttpPostedFileBase file)
        {
            if (file == null || file.ContentLength == 0)
            {
                ModelState.AddModelError("Poster", "Загрузите постер");
                return(View(model));
            }

            var fileBytes = new byte[file.ContentLength];

            file.InputStream.Read(fileBytes, 0, file.ContentLength);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            using (var context = new MovieDBEntities())
            {
                model.Inserted_Date   = DateTime.Now;
                model.Inserted_UserId = User.Identity.GetUserId();
                model.Poster          = fileBytes;
                context.Movies.Add(model);
                var result = context.SaveChanges();
                if (result > 0)
                {
                    return(RedirectToAction("MovieDetails", new { id = model.Id }));
                }
            }
            return(View(model));
        }
예제 #11
0
        public virtual DbResult <int> SaveChanges(MovieDBEntities db)
        {
            DbResult <int> DMLResult = new DbResult <int>();

            try
            {
                int cnt = db.SaveChanges();
                if (cnt > 0)
                {
                    DMLResult.IsSuccess = true;
                    DMLResult.Message   = "Transaction Successful";
                    DMLResult.Result    = cnt;
                }
                else
                {
                    DMLResult.IsSuccess = false;
                    DMLResult.Message   = "Transaction Failed";
                    DMLResult.Result    = 0;
                }
            }
            catch (Exception ex)
            {
                //This is the part where I usually log things
                throw ex;
            }
            return(DMLResult);
        }
예제 #12
0
        //insert a data Model -> EmpModel.edmx -> EmpModel.tt -> Movie_Master
        //in postman Post method https://localhost:44367/api/movie Body -> Row -> last option in drop down JSON

        /*{
         *  "movie_id":1,
         *  "movie_name":"YDLJ",
         *  "movie_cast":"alia"
         * }*/
        public IHttpActionResult PostData(Movie_Master movie)
        {
            try
            {
                if (movie != null)
                {
                    db.Movie_Master.Add(movie);
                    db.SaveChanges();
                    return(Ok("Inserted Data Successfully!"));
                }
                else
                {
                    return(BadRequest("Provide Proper Data!"));
                }
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.InternalServerError, "Enter Proper data!"));
            }
        }
예제 #13
0
        public IHttpActionResult PostMoviesList(MovieRating movieRating)
        {
            List <MovieRating> movie = db.MovieRatings.Where(r => r.MovieId == movieRating.MovieId && r.UserId == movieRating.UserId).ToList();

            if (movie.Count > 0)
            {
                ValidationError("Invalid Movie Id", HttpStatusCode.BadRequest);
            }
            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));
            }

            db.MovieRatings.Add(movieRating);
            db.SaveChanges();

            return(StatusCode(HttpStatusCode.OK));
        }
        public ActionResult Create([Bind(Exclude = "Id")] Movie movieToCreate)
        {
            try
            {
                // TODO: Add insert logic here

                if (!ModelState.IsValid)
                {
                    return(View());
                }

                _db.Table.Add(movieToCreate);

                _db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #15
0
        public void Add(MovieModel movie)
        {
            using (var context = new MovieDBEntities())
            {
                var entity = context.Movies.Create();

                entity.Title        = movie.Title;
                entity.Director     = movie.Director;
                entity.DateReleased = movie.DateReleased;

                context.Movies.Add(entity);
                context.SaveChanges();
            }
        }
예제 #16
0
        public void Update(MovieModel movie)
        {
            using (var context = new MovieDBEntities())
            {
                var entity = (from m in context.Movies
                              where m.Id == movie.Id
                              select m).Single(); // not using SingleOrDefault() because by convention, when we search by Id, if there are no results, we should throw an Exception

                entity.Title        = movie.Title;
                entity.Director     = movie.Director;
                entity.DateReleased = movie.DateReleased;

                context.SaveChanges();
            }
        }