public IHttpActionResult PutMovie(int id, Movie movie)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != movie.Id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,Type")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                db.Genres.Add(genre);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(genre));
        }
Ejemplo n.º 3
0
        public string AddReview(string name, int id, string text)
        {
            var query = db.Users.Where(u => u.UserId == FigureOutId());

            db.Reviews.AddRange(new Review()
            {
                Name = name, FilmId = id, Score = 1, UserId = FigureOutId(), Text = text, Status = true, User = query.ToList()[0].Name
            });
            db.SaveChanges();
            return("Film?id=" + id);
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "ID,Title,Year,Release,Price,GenreID")] Movies movies)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movies);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.GenreID = new SelectList(db.Genres, "Id", "Type", movies.GenreID);
            return(View(movies));
        }
Ejemplo n.º 5
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (dgvActors.SelectedRows.Count > 0)
     {
         try
         {
             using (MovieDB context = new MovieDB())
             {
                 DataGridViewRow row   = dgvActors.SelectedRows[0];
                 actor           actor = (actor)row.Tag;
                 if (MessageBox.Show("Are you sure you want to delete actor: " + actor.member_of_cast_and_crew.first_name + " " + actor.member_of_cast_and_crew.last_name + "?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
                 {
                     context.actors.Attach(actor);
                     actor.member_of_cast_and_crew.active = 0;
                     context.SaveChanges();
                     RefreshTableAndFilters();
                     DirectorsUcl.Instance.RefreshTableAndFilters();
                     MoviesUcl.Instance.RefreshTableAndFilters();
                     MessageBox.Show("Actor successfully deleted.", "Success", MessageBoxButtons.OK);
                 }
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.StackTrace);
         }
     }
     else
     {
         MessageBox.Show("You haven't chosen an actor.", "Warning", MessageBoxButtons.OK);
     }
 }
Ejemplo n.º 6
0
 public ActionResult AddFilm(MovieList movie)
 {
     if (ModelState.IsValid)
     {
         using (MovieDB db = new MovieDB())
         {
             db.MovieList.Add(movie);
             db.SaveChanges();
         }
         ModelState.Clear();
         ViewBag.Message = "Movie successfully added";
     }
     return(View());
 }
Ejemplo n.º 7
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            AddMemberOfCastAndCrewForm addMemberOfCastAndCrew = new AddMemberOfCastAndCrewForm("actor");

            if (DialogResult.OK == addMemberOfCastAndCrew.ShowDialog())
            {
                try
                {
                    using (MovieDB context = new MovieDB())
                    {
                        DateTime?died = addMemberOfCastAndCrew.Dead ? addMemberOfCastAndCrew.Died : (DateTime?)null;
                        var      memberOfCastAndCrew = new member_of_cast_and_crew()
                        {
                            first_name = addMemberOfCastAndCrew.FirstName,
                            last_name  = addMemberOfCastAndCrew.LastName,
                            birthplace = addMemberOfCastAndCrew.Birthplace,
                            born       = addMemberOfCastAndCrew.Born,
                            died       = died,
                            bio        = addMemberOfCastAndCrew.Bio,
                            image      = addMemberOfCastAndCrew.MemberImage,
                            active     = 1
                        };
                        var actor = new actor()
                        {
                            member_of_cast_and_crew = memberOfCastAndCrew
                        };
                        context.actors.Add(actor);
                        if (addMemberOfCastAndCrew.DoubleMember)
                        {
                            var director = new director()
                            {
                                member_of_cast_and_crew = memberOfCastAndCrew
                            };
                            context.directors.Add(director);
                        }
                        context.SaveChanges();
                        RefreshTableAndFilters();
                        DirectorsUcl.Instance.RefreshTableAndFilters();
                        MoviesUcl.Instance.RefreshTableAndFilters();
                        MessageBox.Show("Actor successfully added.", "Success", MessageBoxButtons.OK);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
            }
        }
Ejemplo n.º 8
0
        private void btnAddLanguage_Click(object sender, EventArgs e)
        {
            AddLanguageForm addLanguageForm = new AddLanguageForm();

            if (DialogResult.OK == addLanguageForm.ShowDialog())
            {
                try
                {
                    using (MovieDB context = new MovieDB())
                    {
                        var language = new language()
                        {
                            name   = addLanguageForm.LanguageName,
                            active = 1
                        };
                        context.languages.Add(language);
                        context.SaveChanges();
                        FillLanguagesList();
                        var languageItems = lvLanguages.Items;
                        foreach (var checkedLanguage in Languages.ToList())
                        {
                            foreach (var item in languageItems)
                            {
                                language languageItem = (language)(item as ListViewItem).Tag;
                                if (languageItem.id == checkedLanguage.id)
                                {
                                    (item as ListViewItem).Checked = true;
                                }
                            }
                        }
                        MoviesUcl.Instance.RefreshTableAndFilters();
                        ActorsUcl.Instance.RefreshTableAndFilters();
                        DirectorsUcl.Instance.RefreshTableAndFilters();
                        MessageBox.Show("Language successfully added.", "Success", MessageBoxButtons.OK);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
            }
        }
        public ActionResult CreateMovie([Bind(Include = "MovieId,Title,Cert,Genre,Rating")] Movie movie)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Movies.Add(movie);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View("_Error"));
            }
            catch
            {
                return(View("_Error"));
            }
        }
Ejemplo n.º 10
0
        private void btnAddDirector_Click(object sender, EventArgs e)
        {
            AddMemberOfCastAndCrewForm addMemberOfCastAndCrew = new AddMemberOfCastAndCrewForm("director");

            if (DialogResult.OK == addMemberOfCastAndCrew.ShowDialog())
            {
                try
                {
                    using (MovieDB context = new MovieDB())
                    {
                        DateTime?died = addMemberOfCastAndCrew.Dead ? addMemberOfCastAndCrew.Died : (DateTime?)null;
                        var      memberOfCastAndCrew = new member_of_cast_and_crew()
                        {
                            first_name = addMemberOfCastAndCrew.FirstName,
                            last_name  = addMemberOfCastAndCrew.LastName,
                            birthplace = addMemberOfCastAndCrew.Birthplace,
                            born       = addMemberOfCastAndCrew.Born,
                            died       = died,
                            bio        = addMemberOfCastAndCrew.Bio,
                            image      = addMemberOfCastAndCrew.MemberImage,
                            active     = 1
                        };
                        var director = new director()
                        {
                            member_of_cast_and_crew = memberOfCastAndCrew
                        };
                        context.directors.Add(director);
                        if (addMemberOfCastAndCrew.DoubleMember)
                        {
                            var actor = new actor()
                            {
                                member_of_cast_and_crew = memberOfCastAndCrew
                            };
                            context.actors.Add(actor);
                        }
                        context.SaveChanges();
                        FillDirectorsList();
                        var directorItems = lvDirectors.Items;
                        foreach (var checkedDirector in MovieDirectors.ToList())
                        {
                            foreach (var item in directorItems)
                            {
                                director directorItem = (director)(item as ListViewItem).Tag;
                                if (directorItem.id == checkedDirector.id)
                                {
                                    (item as ListViewItem).Checked = true;
                                }
                            }
                        }
                        FillActorsList();
                        var actorItems = lvActors.Items;
                        foreach (var checkedActor in MovieActors.ToList())
                        {
                            foreach (var item in actorItems)
                            {
                                actor actorItem = (actor)(item as ListViewItem).Tag;
                                if (actorItem.id == checkedActor.id)
                                {
                                    (item as ListViewItem).Checked = true;
                                }
                            }
                        }
                        MoviesUcl.Instance.RefreshTableAndFilters();
                        ActorsUcl.Instance.RefreshTableAndFilters();
                        DirectorsUcl.Instance.RefreshTableAndFilters();
                        MessageBox.Show("Director successfully added.", "Success", MessageBoxButtons.OK);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
            }
        }
Ejemplo n.º 11
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            AddMemberOfCastAndCrewForm addMemberOfCastAndCrew = new AddMemberOfCastAndCrewForm("actor");

            if (dgvActors.SelectedRows.Count > 0)
            {
                try
                {
                    using (MovieDB context = new MovieDB())
                    {
                        DataGridViewRow row   = dgvActors.SelectedRows[0];
                        actor           actor = (actor)row.Tag;
                        addMemberOfCastAndCrew.FirstName  = actor.member_of_cast_and_crew.first_name;
                        addMemberOfCastAndCrew.LastName   = actor.member_of_cast_and_crew.last_name;
                        addMemberOfCastAndCrew.Birthplace = actor.member_of_cast_and_crew.birthplace;
                        addMemberOfCastAndCrew.Born       = actor.member_of_cast_and_crew.born;
                        if (actor.member_of_cast_and_crew.died.HasValue)
                        {
                            addMemberOfCastAndCrew.Dead = true;
                            addMemberOfCastAndCrew.Died = actor.member_of_cast_and_crew.died.Value;
                        }
                        else
                        {
                            addMemberOfCastAndCrew.Dead = false;
                        }
                        addMemberOfCastAndCrew.MemberImage = actor.member_of_cast_and_crew.image;
                        addMemberOfCastAndCrew.Bio         = actor.member_of_cast_and_crew.bio;
                        var directors = (from c in context.directors
                                         where c.id == actor.id &&
                                         c.member_of_cast_and_crew.active == 1
                                         select c).ToList();
                        if (directors.Count > 0)
                        {
                            addMemberOfCastAndCrew.DoubleMember = true;
                        }
                        else
                        {
                            addMemberOfCastAndCrew.DoubleMember = false;
                        }

                        if (DialogResult.OK == addMemberOfCastAndCrew.ShowDialog())
                        {
                            context.actors.Attach(actor);
                            actor.member_of_cast_and_crew.first_name = addMemberOfCastAndCrew.FirstName;
                            actor.member_of_cast_and_crew.last_name  = addMemberOfCastAndCrew.LastName;
                            actor.member_of_cast_and_crew.birthplace = addMemberOfCastAndCrew.Birthplace;
                            actor.member_of_cast_and_crew.born       = addMemberOfCastAndCrew.Born;
                            if (addMemberOfCastAndCrew.Dead)
                            {
                                actor.member_of_cast_and_crew.died = addMemberOfCastAndCrew.Died;
                            }
                            else
                            {
                                actor.member_of_cast_and_crew.died = null;
                            }
                            actor.member_of_cast_and_crew.image = addMemberOfCastAndCrew.MemberImage;
                            actor.member_of_cast_and_crew.bio   = addMemberOfCastAndCrew.Bio;

                            if (addMemberOfCastAndCrew.DoubleMember)
                            {
                                if (directors.Count == 0)
                                {
                                    var director = new director()
                                    {
                                        member_of_cast_and_crew = actor.member_of_cast_and_crew
                                    };
                                    context.directors.Add(director);
                                }
                            }
                            else
                            {
                                if (directors.Count > 0)
                                {
                                    var director = directors[0];
                                    context.directors.Remove(director);
                                }
                            }
                            context.SaveChanges();
                            RefreshTableAndFilters();
                            DirectorsUcl.Instance.RefreshTableAndFilters();
                            MoviesUcl.Instance.RefreshTableAndFilters();
                            MessageBox.Show("Changes successfully saved.", "Success", MessageBoxButtons.OK);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
            }
            else
            {
                MessageBox.Show("You haven't chosen an actor.", "Warning", MessageBoxButtons.OK);
            }
        }
Ejemplo n.º 12
0
 public void Add(T item)
 {
     db.Set(typeof(T)).Add(item);
     db.SaveChanges();
 }