/// <summary> /// Adds the moview /// </summary> /// <param name="movieDto">movieDto</param> /// <returns></returns> public async Task <int> AddMovies(MovieDTO movieDto) { // Check if there is already a show scheduled at the same time & location List <Movie> movies = await this.GetMoviesByMultiplexId(movieDto.MultiplexId); foreach (Movie item in movies) { if (item.DateAndTime.Date.ToShortDateString() == movieDto.DateAndTime.Date.ToShortDateString()) { throw new CustomException(Constants.MovieExist); } } Movie newMovie = new Movie { Movie_Name = movieDto.Movie_Name, MovieLanguage = movieDto.MovieLanguage, Movie_Description = movieDto.Movie_Description, DateAndTime = Convert.ToDateTime(movieDto.DateAndTime), MultiplexId = movieDto.MultiplexId, Genre = movieDto.Genre }; return(await _movieRepository.AddMovies(newMovie)); }
private void CreateSampleData() { if (_contentItems.Count > 0) { return; } List <Movie> sampleData = new List <Movie>(); sampleData.Add(new Movie() { Title = "Rogue One: A Star Wars Story", Directors = new string[] { "Gareth Edwards" }, Rating = 7.8, Released = new DateTime(2016, 12, 16) }); sampleData.Add(new Movie() { Title = "Titanic", Directors = new string[] { "James Cameron" }, Rating = 7.8, Released = new DateTime(1998, 01, 23) }); sampleData.Add(new Movie() { Title = "Finding Nemo", Directors = new string[] { "Andrew Stanton", "Lee Unkrich" }, Rating = 8.1, Released = new DateTime(2003, 10, 10) }); sampleData.Add(new Movie() { Title = "Avatar", Directors = new string[] { "James Cameron" }, Rating = 7.8, Released = new DateTime(2009, 12, 17) }); sampleData.Add(new Movie() { Title = "Shrek", Directors = new string[] { "Andrew Adamson", "Vicky Jenson" }, Rating = 7.9, Released = new DateTime(2001, 06, 29) }); sampleData.Add(new Movie() { Title = "Avengers: Infinity War", Directors = new string[] { "Joe Russo", "Antony Russo" }, Rating = 8.6, Released = new DateTime(2018, 04, 26) }); sampleData.Add(new Movie() { Title = "Mamma Mia!", Directors = new string[] { "Phyllida Lloyd" }, Rating = 6.4, Released = new DateTime(2008, 07, 10) }); _contentRepository.AddMovies(sampleData); _contentItems = new ObservableCollection <Movie>(sampleData.AsEnumerable()); OnPropertyChanged(nameof(ContentItems)); }
public IActionResult AddMovies([FromBody] MovieDto movieInfo) { if (movieInfo == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } int newId = _movieRepository.AddMovies(movieInfo); if (newId <= 0) { return(StatusCode(500, "A problem happened while handling your request")); } return(Created("bookingDetails", new { id = newId })); }