Example #1
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);
                }
            }
        }
Example #2
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);
            }
        }