Esempio n. 1
0
 private void Update(int movieId)
 {
     try
     {
         var image = new ImageByteConverter();
         using (var unitOfWork = new UnitOfWork(new MovieBookingContext()))
         {
             var movie = unitOfWork.Movies.Get(movieId);
             movie.Title                = txtTitle.Text;
             movie.Poster               = image.ImageToByte(picPoster.Image);
             movie.ReleaseDate          = dtpReleaseDate.Value;
             movie.Description          = txtDescription.Text;
             movie.Genre                = (Genre)Enum.Parse(typeof(Genre), cboGenre.SelectedItem.ToString());
             movie.ImdbRating           = (float)Convert.ToDecimal(txtIMDBRating.Text);
             movie.RottenTomatoesRating = (float)Convert.ToDecimal(txtRottenTomatoes.Text);
             movie.PgRating             = txtPgRating.Text;
             movie.Trailer              = txtTrailerLink.Text;
             movie.Director             = txtDirector.Text;
             movie.Casts                = txtCast.Text;
             unitOfWork.Complete();
             MessageBox.Show(@"Update Successfull");
         }
     }
     catch (ValidationException ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Esempio n. 2
0
        public void GetMovie(int movieId)
        {
            try
            {
                var image = new ImageByteConverter();

                using (var unitOfWork = new UnitOfWork(new MovieBookingContext()))
                {
                    var movie = unitOfWork.Movies.Get(movieId);
                    txtMovieId.Text        = movie.Id.ToString();
                    txtTitle.Text          = movie.Title;
                    dtpReleaseDate.Value   = movie.ReleaseDate;
                    txtDescription.Text    = movie.Description;
                    cboGenre.SelectedIndex = (int)movie.Genre;
                    txtIMDBRating.Text     = movie.ImdbRating.ToString();
                    txtRottenTomatoes.Text = movie.RottenTomatoesRating.ToString();
                    txtPgRating.Text       = movie.PgRating;
                    txtTrailerLink.Text    = movie.Trailer;
                    txtDirector.Text       = movie.Director;
                    txtCast.Text           = movie.Casts;
                    picPoster.Image        = image.ByteToImage(movie.Poster);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 3
0
        private void Save()
        {
            using (var unitOfWork = new UnitOfWork(new MovieBookingContext()))
            {
                try
                {
                    var image = new ImageByteConverter();
                    var movie = new Movie
                    {
                        Title                = txtTitle.Text,
                        Poster               = image.ImageToByte(picPoster.Image),
                        ReleaseDate          = dtpReleaseDate.Value,
                        Description          = txtDescription.Text,
                        Genre                = (Genre)Enum.Parse(typeof(Genre), cboGenre.SelectedItem.ToString()),
                        ImdbRating           = (float)Convert.ToDecimal(txtIMDBRating.Text),
                        RottenTomatoesRating = (float)Convert.ToDecimal(txtRottenTomatoes.Text),
                        PgRating             = txtPgRating.Text,
                        Trailer              = txtTrailerLink.Text,
                        Director             = txtDirector.Text,
                        Casts                = txtCast.Text
                    };

                    unitOfWork.Movies.Add(movie);
                    unitOfWork.Complete();
                    txtMovieId.Text = movie.Id.ToString();
                    MessageBox.Show(@"Save Successfull");
                }

                catch (DbEntityValidationException ex)
                {
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 4
0
        public void GetCinema(int Id)
        {
            try
            {
                var image = new ImageByteConverter();

                using (var unitOfWork = new UnitOfWork(new MovieBookingContext()))
                {
                    var cinema = unitOfWork.Cinemas.Get(Id);

                    txtId.Text      = cinema.Id.ToString();
                    txtName.Text    = cinema.Name;
                    txtAddress.Text = cinema.Address;
                    txtContact.Text = cinema.Contact;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 5
0
        private void Update(int Id)
        {
            try
            {
                var image = new ImageByteConverter();
                using (var unitOfWork = new UnitOfWork(new MovieBookingContext()))
                {
                    var cinema = unitOfWork.Cinemas.Get(Id);
                    cinema.Name    = txtName.Text;
                    cinema.Address = txtAddress.Text;
                    cinema.Contact = txtContact.Text;


                    if (unitOfWork.Complete() > 0)
                    {
                        MessageBox.Show(@"Update Successfull");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }