Esempio n. 1
0
 public ActionResult <Model.Movie> Update(int movieId, Model.Requests.InsertMovieRequest request)
 {
     return(_service.Update(movieId, request));
 }
Esempio n. 2
0
        private async void SaveBtn_Click(object sender, EventArgs e)
        {
            var messageBox = new CustomMessageBox();

            if (string.IsNullOrWhiteSpace(MovieTitle.Text) || MovieTitle.Text.Length < 4)
            {
                messageBox.Show("The title field requires 4 letters!", "error");
                return;
            }

            if (string.IsNullOrWhiteSpace(Description.Text) || Description.Text.Length < 5)
            {
                messageBox.Show("The description field requires 5 letters!", "error");
                return;
            }

            if (string.IsNullOrWhiteSpace(Cast.Text) || Cast.Text.Length < 15)
            {
                messageBox.Show("The cast field requires 15 letters!", "error");
                return;
            }
            if (string.IsNullOrWhiteSpace(ImageLink.Text) || !ImageLink.Text.Contains(".jpg"))
            {
                messageBox.Show("Enter a valid '.jpg' image link!", "error");
                return;
            }
            if (string.IsNullOrWhiteSpace(TrailerLink.Text))
            {
                messageBox.Show("Enter a trailer id", "error");
                return;
            }

            if (string.IsNullOrWhiteSpace(Rating.Text) || !decimal.TryParse(Rating.Text, out decimal n))
            {
                messageBox.Show("Enter a valid rating (0-10)!", "error");
                return;
            }
            decimal rating = decimal.Parse(Rating.Text);

            if (rating < 0 || rating > 10)
            {
                messageBox.Show("Enter a valid rating (0-10)!", "error");
                return;
            }

            if (string.IsNullOrWhiteSpace(Price.Text) || !decimal.TryParse(Price.Text, out decimal m))
            {
                messageBox.Show("Enter a valid price (1-200)!", "error");
                return;
            }
            decimal price = decimal.Parse(Price.Text);

            if (price < 1 || price > 200)
            {
                messageBox.Show("Enter a valid price (1-200)!", "error");
                return;
            }
            if (Year.Value < Year.Minimum || Year.Value > Year.Maximum)
            {
                messageBox.Show("Enter a valid year (1800-2025)!", "error");
                return;
            }
            var hours = Duration.Value.Hour;

            if (hours < 0 || hours > 4)
            {
                messageBox.Show("Enter a valid duration (up to 5 hours)!", "error");
                return;
            }

            if (string.IsNullOrWhiteSpace(Genre.Text) || Genre.Text.Length < 4)
            {
                messageBox.Show("The genre field requires 4 letters!", "error");
                return;
            }

            Model.Requests.InsertMovieRequest request = new Model.Requests.InsertMovieRequest()
            {
                Title       = MovieTitle.Text,
                Year        = (int)Year.Value,
                Duration    = Duration.Value.ToString("HH:mm"),
                Rating      = decimal.Parse(Rating.Text),
                Description = Description.Text,
                Cast        = Cast.Text,
                ImageLink   = ImageLink.Text,
                Standalone  = Standalone.Checked,
                Price       = decimal.Parse(Price.Text),
                TrailerLink = $"https://www.youtube.com/embed/{TrailerLink.Text}",
                Genre       = Genre.Text
            };

            if (_movieId.HasValue)
            {
                await _apiService.Update <Model.Movie>(_movieId, request);
            }
            else
            {
                await _apiService.Insert <Model.Movie>(request);
            }

            this.Close();
            foreach (Form frm in _menuForm.MdiChildren)
            {
                frm.Close();
            }
            MoviesForm form = new MoviesForm {
                MdiParent = _menuForm,
                Dock      = DockStyle.Fill
            };

            form.Show();
            if (_movieId.HasValue)
            {
                messageBox.Show("Movie updated successfully!", "success");
            }
            else
            {
                messageBox.Show("Movie added successfully!", "success");
            }
        }
Esempio n. 3
0
 public ActionResult <Model.Movie> Insert(Model.Requests.InsertMovieRequest request)
 {
     return(_service.Insert(request));
 }