public void AddMethodOk()
        {
            clsLinkCollection AllLinks = new clsLinkCollection();
            clsLink           TestItem = new clsLink();

            TestItem.FilmId   = 193610;
            TestItem.ImdbId   = 1160419;
            AllLinks.ThisLink = TestItem;
            AllLinks.Add();
            AllLinks.ThisLink.Find(TestItem.FilmId);
            Assert.AreEqual(AllLinks.ThisLink, TestItem);
        }
        public void UpdateMethodOk()
        {
            clsLinkCollection AllLinks = new clsLinkCollection();
            clsLink           TestItem = new clsLink();

            TestItem.FilmId   = 193615;
            TestItem.ImdbId   = 1111111;
            AllLinks.ThisLink = TestItem;
            AllLinks.Add();

            TestItem.ImdbId   = 5034838;
            AllLinks.ThisLink = TestItem;
            AllLinks.Update();
            AllLinks.ThisLink.Find(TestItem.FilmId);
            Assert.AreEqual(AllLinks.ThisLink, TestItem);
        }
Exemplo n.º 3
0
        protected void btnActionFilm_Click(object sender, EventArgs e)
        {
            string originalTitle = "";

            editFilm = Convert.ToBoolean(Session["EditFilm"]);
            if (editFilm)
            {
                originalTitle = Session["Title"].ToString();
            }

            string newTitle   = txtFilmTitle.Text;
            string tempImdbId = txtImdbId.Text;
            Int32  imdbId     = 0;
            bool   imdbIdOk   = false;

            clsFilm aFilm          = new clsFilm();
            var     filmTitleCheck = aFilm.Valid(newTitle);

            if (filmTitleCheck.Count != 0)
            {
                foreach (string error in filmTitleCheck)
                {
                    Label lblError = new Label();
                    lblError.Text = "- " + error;
                    pnlActionFilmErrorBody.Controls.Add(lblError);
                    pnlActionFilmErrorBody.Controls.Add(new LiteralControl("<br />"));
                }
            }

            clsLinkCollection AllLinks = new clsLinkCollection();
            var imdbIdCheck            = AllLinks.ThisLink.Valid(tempImdbId);

            if (imdbIdCheck.Count != 0)
            {
                foreach (string error in imdbIdCheck)
                {
                    Label lblError = new Label();
                    lblError.Text = "- " + error;
                    pnlActionFilmErrorBody.Controls.Add(lblError);
                    pnlActionFilmErrorBody.Controls.Add(new LiteralControl("<br />"));
                    imdbIdOk = false;
                }
                pnlActionFilmError.Visible = true;
            }
            else
            {
                imdbId = Convert.ToInt32(tempImdbId);
                bool ImdbIdAlreadyExists = AllLinks.ImdbIdAlreadyExistsCheck(imdbId);

                if (ImdbIdAlreadyExists)
                {
                    //if (!editFilm) //adding a new film
                    //{
                    Label lblError = new Label();
                    lblError.Text = "- IMDBId already assigned to another film";
                    pnlActionFilmErrorBody.Controls.Add(lblError);
                    pnlActionFilmErrorBody.Controls.Add(new LiteralControl("<br />"));
                    pnlActionFilmError.Visible = true;
                    imdbIdOk = false;
                    //}

                    Int32 originalImdbId = Convert.ToInt32(Session["originalIMDBId"]);

                    if (originalImdbId == imdbId)
                    {
                        imdbIdOk = true;
                    }
                    else
                    {
                        imdbIdOk = false;
                    }

                    //else //if we're editing a film
                    //{
                    //    Int32 originalImdbId = Convert.ToInt32(Session["originalIMDBId"]);
                    //    if (originalImdbId != imdbId)
                    //    {
                    //        Label lblError = new Label();
                    //        lblError.Text = "- IMDBId already assigned to another film";
                    //        pnlActionFilmErrorBody.Controls.Add(lblError);
                    //        pnlActionFilmErrorBody.Controls.Add(new LiteralControl("<br />"));
                    //        imdbIdOk = false;
                    //    }
                    //    else
                    //    {
                    //        imdbIdOk = true;
                    //    }
                    //}
                }
                else
                {
                    imdbIdOk = true;
                }
            }

            newTitle = newTitle.TrimEnd();
            string yearReleased         = " " + "(" + ddlYear.SelectedValue + ")";
            string titleAndYearReleased = newTitle + yearReleased;

            bool filmAlreadyExists     = false;
            clsFilmCollection AllFilms = new clsFilmCollection();

            if (AllFilms.FilmAlreadyExistsCheck(titleAndYearReleased))
            {
                if (!editFilm)
                {
                    Label lblError = new Label();
                    lblError.Text = "Film already exists";
                    pnlActionFilmErrorBody.Controls.Add(lblError);
                    filmAlreadyExists = true;
                }
                else //if we ARE editing a film
                {
                    if (newTitle != originalTitle)
                    {
                        Label lblError = new Label();
                        lblError.Text = "Film already exists";
                        pnlActionFilmErrorBody.Controls.Add(lblError);
                        filmAlreadyExists = true;
                    }
                    else
                    {
                        filmAlreadyExists = false;
                    }
                }
            }
            else
            {
                filmAlreadyExists = false;
            }

            if (!editFilm && !filmAlreadyExists && imdbIdOk)
            {
                AllFilms = new clsFilmCollection();
                AllFilms.ThisFilm.Title = titleAndYearReleased;
                Int32 filmId = AllFilms.Add();
                AllLinks.ThisLink.FilmId = filmId;
                AllLinks.ThisLink.ImdbId = imdbId;
                AllLinks.Add();

                clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection();

                foreach (ListItem item in chkbxlstGenres.Items)
                {
                    if (item.Selected)
                    {
                        AllFilmGenres.ThisFilmGenre.FilmId  = filmId;
                        AllFilmGenres.ThisFilmGenre.GenreId = Convert.ToInt32(item.Value);
                        AllFilmGenres.Add();
                        AllFilmGenres = new clsFilmGenreCollection();
                    }
                }
                LoadData();
                pnlActionFilm.Visible = false;
            }

            if (editFilm)
            {
                AllFilms = new clsFilmCollection();
                AllFilms.ThisFilm.FilmId = Convert.ToInt32(Session["FilmId"]);

                newTitle = titleAndYearReleased;

                if (newTitle == originalTitle)
                {
                    AllFilms.ThisFilm.Title = originalTitle;
                }
                else
                {
                    AllFilms.ThisFilm.Title = newTitle;
                }

                AllFilms.Update();

                clsFilmGenreCollection AllFilmGenres = new clsFilmGenreCollection();
                AllFilmGenres.ThisFilmGenre.FilmId = filmId;
                AllFilmGenres.DeleteByFilmId();

                foreach (ListItem item in chkbxlstGenres.Items)
                {
                    if (item.Selected)
                    {
                        AllFilmGenres.ThisFilmGenre.FilmId  = filmId;
                        AllFilmGenres.ThisFilmGenre.GenreId = Convert.ToInt32(item.Value);
                        AllFilmGenres.Add();
                        AllFilmGenres = new clsFilmGenreCollection();
                    }
                }

                LoadData();
                pnlActionFilm.Visible = false;
            }
        }