Exemplo n.º 1
0
        public IHttpActionResult PutMovy(int id, Movy movy)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != movy.MovieID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> Post([FromBody] Movie moviesEntity)
        {
            try
            {
                if (moviesEntity == null)
                {
                    throw new Exception("You need to input Movie title, Movie description");
                }

                if ((moviesEntity.MovieTitle == null || moviesEntity.MovieTitle == string.Empty) ||
                    (moviesEntity.MovieDescription == null || moviesEntity.MovieDescription == string.Empty))
                {
                    throw new Exception("You need to input Movie title, Movie description");
                }

                var movie = await movieEntity.Movies.Where(x => x.MovieTitle == moviesEntity.MovieTitle && x.IsDeleted == false).FirstOrDefaultAsync();

                if (movie != null)
                {
                    throw new Exception("Movie title already exist and not deleted!");
                }

                movieEntity.Movies.Add(moviesEntity);
                movieEntity.SaveChanges();

                return(Ok(new { message = "Data sucessfully saved!" }));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 3
0
 public ActionResult Create([Bind(Exclude = "Id")] Movie movieToCreate)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     _db.Movies1.Add(movieToCreate);
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Exemplo n.º 4
0
        public ActionResult Delete(int id)
        {
            var movieToDelete = (from m in _entities.MovieSet
                                 where m.Id == id
                                 select m).FirstOrDefault();

            _entities.DeleteObject(movieToDelete);
            _entities.SaveChanges();
            return(PartialView("Movies", _entities.MovieSet.ToList()));
        }
Exemplo n.º 5
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));
        }
        public ActionResult Create([Bind(Include = "CustomerID,FirstName,LastName,Phone")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Exemplo n.º 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));
        }
Exemplo n.º 8
0
        public ActionResult Create([Bind(Include = "CustomerID,FirstName,LastName,phone")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "FirstName", customer.CustomerID);
            ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "FirstName", customer.CustomerID);
            return(View(customer));
        }
Exemplo n.º 9
0
        public async Task <IHttpActionResult> Post([FromBody] User user)
        {
            try
            {
                if (user == null)
                {
                    throw new Exception("You need to input your email and password");
                }

                if ((user.FullName == null || user.FullName == string.Empty) ||
                    (user.EmailAddress == null || user.EmailAddress == string.Empty) ||
                    (user.Password == null || user.Password == string.Empty))
                {
                    throw new Exception("Fullname, EmailAddress, and Password is required!");
                }

                var userEntity = await movieEntity.Users.Where(x => x.EmailAddress == user.EmailAddress).FirstOrDefaultAsync();

                if (userEntity != null)
                {
                    throw new Exception("Email already exist");
                }

                movieEntity.Users.Add(user);
                movieEntity.SaveChanges();
                return(Ok(new { message = "Account created successfully" }));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public ActionResult Create([Bind(Exclude = "Id")] Movie movieToCreate)
        {
            // Validate
            if (movieToCreate.Title.Trim().Length == 0)
            {
                ModelState.AddModelError("Title", "Title is required.");
            }
            if (movieToCreate.Title.IndexOf("r") > 0)
            {
                ModelState.AddModelError("Title", "Title cannot contain the letter r.");
            }
            if (movieToCreate.Director.Trim().Length == 0)
            {
                ModelState.AddModelError("Director", "Director is required.");
            }
            if (!ModelState.IsValid)
            {
                return(View());
            }

            // Add to database
            _entities.AddToMovieSet(movieToCreate);
            _entities.SaveChanges();

            // Redirect
            return(RedirectToAction("Index"));
        }
Exemplo n.º 11
0
        public ActionResult Create([Bind(Exclude = "Id")] Movie newMovie)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View());
                }
                _db.Movies.Add(newMovie);
                _db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 12
0
        public bool AddUpdateMovie(MovieModel model)
        {
            try
            {
                tblMovy _movieModel = model.MovieID > 0 ? _MoviesDBEntitiesContext.tblMovies.FirstOrDefault(f => f.MovieID == model.MovieID) : new tblMovy();
                _movieModel.Name = model.Name;
                _movieModel.Plot = model.Plot;

                if (!string.IsNullOrEmpty(model.Poster))
                {
                    _movieModel.Poster            = Base64Image.Parse(model.Poster).FileContents;
                    _movieModel.PosterContentType = model.ContentType;
                }

                _movieModel.ProducerID    = model.ProducerID;
                _movieModel.YearOfRelease = model.YearOfRelease;
                _MoviesDBEntitiesContext.Entry(_movieModel).State = model.MovieID > 0 ? System.Data.Entity.EntityState.Modified : System.Data.Entity.EntityState.Added;
                _MoviesDBEntitiesContext.SaveChanges();
                if (model.MovieID > 0)
                {
                    _MoviesDBEntitiesContext.tblMovieActors.RemoveRange(_MoviesDBEntitiesContext.tblMovieActors.Where(w => w.MovieID == model.MovieID));
                    _MoviesDBEntitiesContext.SaveChanges();
                }
                foreach (int actorID in model.Actors)
                {
                    if (!_MoviesDBEntitiesContext.tblMovieActors.Any(fk => fk.ActorID == actorID && fk.MovieID == _movieModel.MovieID))
                    {
                        tblMovieActor _movieActor = new tblMovieActor();
                        _movieActor.ActorID = actorID;
                        _movieActor.MovieID = _movieModel.MovieID;
                        _MoviesDBEntitiesContext.tblMovieActors.Add(_movieActor);
                        _MoviesDBEntitiesContext.SaveChanges();
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 13
0
        public ActionResult Create(Movie item)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View());
                }

                _db.AddToMovieSet(item);
                _db.SaveChanges();

                return(RedirectToRoute(this.GetResourceRouteName(routeName, ActionType.Retrieve), new RouteValueDictionary {
                    { "id", item.Id }
                }));
            }
            catch (Exception exception)
            {
                throw new HttpException((int)HttpStatusCode.InternalServerError, "An error has occured; see details:", exception);
            }
        }
 public string Create(Movie movieToCreate)
 {
     try
     {
         _entities.AddToMovieSet(movieToCreate);
         _entities.SaveChanges();
         return("Inserted new movie " + movieToCreate.Title);
     }
     catch
     {
         return("Could not insert movie " + movieToCreate.Title);
     }
 }
Exemplo n.º 15
0
        public ActionResult Create([Bind(Exclude = "Poster")] MovieViewModel movie, HttpPostedFileBase poster)
        {
            if (ModelState.IsValid)
            {
                // if poster != null, save image in localDB
                if (poster != null)
                {
                    movie.Poster = new byte[poster.ContentLength];
                    poster.InputStream.Read(movie.Poster, 0, poster.ContentLength);
                }

                var   mapper        = new MapperConfiguration(cfg => cfg.CreateMap <MovieViewModel, Movie>()).CreateMapper();
                Movie movieSaveInDB = mapper.Map <MovieViewModel, Movie> (movie);

                movieSaveInDB.UserName = User.Identity.Name;
                entities.MovieSet.Add(movieSaveInDB);
                entities.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(movie));
        }
Exemplo n.º 16
0
        public ActionResult Create([Bind(Exclude = "Id")] Movie movieToCreate)
        {
            // Validate
            if (!ModelState.IsValid)
            {
                return(View());
            }

            // Add to database
            try
            {
                _db.AddToMovieSet(movieToCreate);
                _db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 17
0
        private static void ScrapeMovies(List <string> links)
        {
            var          web               = new HtmlWeb();
            var          document          = new HtmlDocument();
            Genre        Genre             = new Genre();
            Movie        Movie             = new Movie();
            StreamSource StreamSourceLinks = new StreamSource();
            int          index             = 0;

            foreach (var link in links)
            {
                try
                {
                    document = web.Load(link);
                }
                catch (Exception e)
                {
                    LogError(e, link);
                    continue;
                }
                Guid gId = Guid.NewGuid();

                try
                {
                    Movie.Id = gId;
                    //get title of movie
                    string title = document.DocumentNode.SelectSingleNode("//h1[@class='title']/span[@itemprop='name']").InnerHtml;
                    Movie.Title = title;
                    //get description
                    string description = document.DocumentNode.SelectSingleNode("//div[@itemprop='description']").InnerHtml;
                    Movie.Description = description;
                    //get year of release
                    string yearOfRelease = document.DocumentNode.SelectSingleNode("//span[@itemprop='copyrightYear']/a").InnerHtml;
                    Movie.ReleaseDate = yearOfRelease;

                    //get other details of the movie
                    var details = document.DocumentNode.SelectNodes("//ul[@class='detail']/div/li");

                    //get all genres
                    var genres = details[2].Descendants("a");
                    foreach (var item in genres)
                    {
                        Genre.MovieId   = gId;
                        Genre.GenreType = item.InnerHtml;
                        using (MoviesDBEntities db = new MoviesDBEntities())
                        {
                            db.Genres.Add(Genre);
                            db.SaveChanges();
                        }
                    }

                    Movie.Country = (details[1].LastChild.InnerHtml); //country
                    Movie.Lenght  = (details[3].LastChild.InnerHtml); //lenght
                    Movie.Dabing  = (details[4].LastChild.InnerHtml); //dabing

                    if (details[5].FirstChild.InnerHtml == "Originální název: ")
                    {
                        Movie.OriginalTitle = (details[5].LastChild.InnerHtml); //original name
                        Movie.Director      = (details[6].LastChild.InnerHtml); //director
                        Movie.Cast          = (details[7].LastChild.InnerHtml); //cast
                    }
                    else
                    {
                        Movie.Director = (details[5].LastChild.InnerHtml); //director
                        Movie.Cast     = (details[6].LastChild.InnerHtml); //cast
                    }

                    //get stream links
                    var streamLinks = document.DocumentNode.SelectNodes("//div[@id='k_online']/iframe");
                    foreach (var item in streamLinks)
                    {
                        StreamSourceLinks.MovieId = gId;
                        StreamSourceLinks.Source  = item.Attributes["src"].Value;
                        using (MoviesDBEntities db = new MoviesDBEntities())
                        {
                            db.StreamSources.Add(StreamSourceLinks);
                            db.SaveChanges();
                        }
                    }

                    string imagePath = document.DocumentNode.SelectSingleNode("//div[@class='full-poster']/img[@itemprop='image']").Attributes["src"].Value;
                    imagePath = "http://kinodum.cz" + imagePath;

                    Movie.CoverPath = (SaveCoverImage(gId, imagePath));
                    using (MoviesDBEntities db = new MoviesDBEntities())
                    {
                        db.Movies.Add(Movie);
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    LogError(e, link);
                    continue;
                }
                Console.WriteLine("Index: {0} Movie: {1} saved to db", index++, gId.ToString());
            }
        }
Exemplo n.º 18
0
        public void FillDbWithData()
        {
            Country country1 = new Country {
                Name = "Poland"
            };
            Country country2 = new Country {
                Name = "Vietnam"
            };

            Person director1 = new Person
            {
                FirstName   = "Joe",
                LastName    = "Doe",
                Type        = TypeOfPeople.DIRECTOR,
                DateOfBirth = DateTime.Now,
                DateOfDeath = DateTime.Now,
                Sex         = TypeOfSex.MALE,
                Country     = country1
            };

            Person actor1 = new Person
            {
                FirstName   = "Stefa",
                LastName    = "Rychu",
                Type        = TypeOfPeople.ACTOR,
                DateOfBirth = DateTime.Now,
                DateOfDeath = DateTime.Now,
                Sex         = TypeOfSex.FEMALE,
                Country     = country2
            };

            Person actor2 = new Person
            {
                FirstName   = "Rychu",
                LastName    = "Peja",
                Type        = TypeOfPeople.ACTOR,
                DateOfBirth = DateTime.Now,
                DateOfDeath = DateTime.Now,
                Sex         = TypeOfSex.MALE,
                Country     = country1
            };

            Movie movie1 = new Movie
            {
                Title    = "Snoop doog",
                Director = director1,
                Genre    = TypesOfGenre.COMEDY,
                Length   = 127,
                Year     = DateTime.Now,
                Country  = country2
            };

            Producer producer1 = new Producer
            {
                CompanyName           = "Test Company",
                YearEstablished       = DateTime.Now,
                EstimatedCompanyValue = 40000000,
                Country = country1,
            };

            MoviePerson   moviePerson1   = new MoviePerson(movie1, actor1);
            MoviePerson   moviePerson2   = new MoviePerson(movie1, actor2);
            MovieProducer movieProducer1 = new MovieProducer(movie1, producer1);

            movie1.Add(moviePerson1);
            movie1.Add(moviePerson2);
            movie1.Add(movieProducer1);

            _context.Movies.Add(movie1);
            _context.SaveChanges();
        }