public ActionResult AddMovie(MoviePO form)
        {
            //Starting response is null
            ActionResult response = null;

            if (ModelState.IsValid)
            {
                try
                {
                    //Using the addmovie method, we pass in the object form to be filled out
                    _movieDAO.AddNewMovie(Mapping.Mapper.MoviePOtoDO(form));
                    //After it's filled out, it goes to viewing all movies
                    response = RedirectToAction("ViewAllMovies", "Movie");
                }
                catch (Exception exception)
                {
                    //If there's an error, it's logged
                    _Logger.Log("Fatal", exception.Source, exception.TargetSite.ToString(), exception.Message, exception.StackTrace);
                    //Making sure there's a fallback location in case something goes bad
                    response = RedirectToAction("ViewAllMovies", "Movie");
                }
                finally
                {
                }
            }
            else
            {
                //If the modelstate isn't good, it goes back to the form to be filled
                response = View(form);
            }
            //Show whichever response happened
            return(response);
        }
示例#2
0
        protected void btnNew_Click(object sender, EventArgs e)
        {
            string id = txtMovieID.Text.Trim();

            //check id null
            if (id.Equals(""))
            {
                SetMessageTextAndColor("MovieID cannot be null", Color.Red);
                return;
            }
            string title = txtMovieTitle.Text.Trim();

            if (title.Equals(""))
            {
                SetMessageTextAndColor("Movie Title cannot be null", Color.Red);
                return;
            }
            int   year = 0, length = 0;
            float rating = 0;

            try
            {
                length = Convert.ToInt32(txtLength.Text);
                if (length < 0)
                {
                    SetMessageTextAndColor("Movie length cannot be negative", Color.Red);
                    return;
                }
            }
            catch
            {
                SetMessageTextAndColor("Length must be a number", Color.Red);
            }
            try
            {
                year = Convert.ToInt32(txtYear.Text);
                if (year < 0)
                {
                    SetMessageTextAndColor("Year cannot be negative", Color.Red);
                    return;
                }
            }
            catch {
                SetMessageTextAndColor("Year must be a number", Color.Red);
            }
            try
            {
                rating = float.Parse(txtRating.Text);
                if (rating < 0)
                {
                    SetMessageTextAndColor("Rating cannot be negative", Color.Red);
                    return;
                }
            }
            catch
            {
                SetMessageTextAndColor("Rating must be a number", Color.Red);
            }
            string   producer  = txtProducer.Text.Trim();
            string   poster    = txtPoster.Text.Trim();
            string   trailer   = txtTrailer.Text.Trim();
            DateTime startDate = new DateTime();

            try
            {
                startDate = DateTime.Parse(txtStartDate.Text);
            }
            catch
            {
                SetMessageTextAndColor("Start Date is wrong format , format must be MM/dd/yyyy", Color.Red);
            }
            int genre = ReturnGenreID(dlGenre.SelectedValue);

            MovieDTO dto = new MovieDTO
            {
                MovieID     = id,
                MovieTitle  = title,
                Length      = length,
                Rating      = rating,
                StartDate   = startDate,
                Poster      = poster,
                LinkTrailer = trailer,
                Producer    = producer,
                Year        = year,
                Genre       = genre
            };

            try
            {
                if (MovieDao.AddNewMovie(dto))
                {
                    List <MovieDTO> list = (List <MovieDTO>)Session["MovieList"];
                    list.Add(dto);
                    gvStaffList.DataSource = list;
                    gvStaffList.DataBind();
                    SetMessageTextAndColor("Successfully added", Color.Green);
                    btnDelete.Enabled = true;
                    btnUpdate.Enabled = true;
                }
                else
                {
                    SetMessageTextAndColor("Failed to add", Color.Red);
                }
            }
            catch
            {
                SetMessageTextAndColor("Movie ID is already existed", Color.Red);
            }
        }