public void CreateMovie(CreateMovieBindingModel model) { this.CheckModelForNull(model); this.CheckMovieForDuplication(model); var genresId = model.GenreIds.Select(int.Parse); var genres = this.Data.Genres.All().Where(g => genresId.Any(id => id == g.Id)).ToList(); var actorsId = model.ActorIds.Select(int.Parse); var actors = this.Data.Actors.All().Where(a => actorsId.Any(id => id == a.Id)).ToList(); var movie = new Movie() { Name = model.Name, Year = model.Year, DurationInMinutes = model.DurationInMinutes, Size = model.Size, Price = model.Price, Poster = model.Poster, Trailer = model.Trailer, Description = model.Description, Country = model.Country, Genres = genres, Actors = actors }; this.Data.Movies.Add(movie); this.Data.SaveChanges(); }
public CreateMovieBindingModel LoadCreateMovieData() { var model = new CreateMovieBindingModel(); var actors = this.actorsService.GetAllActors().ToList(); var genres = this.GetAllMovieGenres().ToList(); var actorItems = actors.Select(actor => new SelectListItem() { Value = actor.Id.ToString(), Text = actor.Name }).ToList(); var genreItems = genres.Select(genre => new SelectListItem() { Value = genre.Id.ToString(), Text = genre.Name }).ToList(); MultiSelectList actorsList = new MultiSelectList(actorItems.OrderBy(i => i.Text), "Value", "Text"); MultiSelectList genreList = new MultiSelectList(genreItems.OrderBy(i => i.Text), "Value", "Text"); model.Actors = actorsList; model.Genres = genreList; return(model); }
public async Task <IHttpActionResult> CreateMovie(CreateMovieBindingModel model) { var newMovie = await _movieService.CreateMovie(model); Uri locationHeader = new Uri(Url.Link("GetMovie", new { id = newMovie.Id })); return(Created(locationHeader, newMovie)); }
public async Task <CommonDto> CreateMovie(CreateMovieBindingModel model) { var newMovie = (Domain.Entity.Movie)_movieFactory.GetModel(model); newMovie.Id = ObjectId.GenerateNewId().ToString(); await Context.GetMovieCollection().InsertOneAsync(newMovie); return((CommonDto)_movieFactory.GetModel <CreatedMovieDto>(newMovie)); }
private void CheckMovieForDuplication(CreateMovieBindingModel model) { var doesItExist = this.Data.Movies.All() .Any(m => m.Name == model.Name && m.Year == model.Year); if (doesItExist) { throw new InvalidOperationException($"There is already movie with name {model.Name} and year ${model.Year}"); } }
public async Task <bool> Insert(CreateMovieBindingModel model) { Movie newMovie = new Movie(model.Name, model.DurationMinutes); this.DbContext.Movies.Add(newMovie); var rowsAffected = await this.DbContext.SaveChangesAsync(); return(rowsAffected == 1); }
public async Task <IHttpActionResult> Create(CreateMovieBindingModel model) { var movie = this.service.GetByNameAndDuration(model.Name, model.DurationMinutes); if (movie != null) { return(BadRequest("Movie already exists")); } bool isCreated = await this.service.Insert(model); if (!isCreated) { return(BadRequest("Error while creating a movie")); } return(Ok(movie)); }
public ActionResult Create(CreateMovieBindingModel model) { if (this.ModelState.IsValid) { try { this.movieService.CreateMovie(model); this.AddNotification("Created successfully", NotificationType.SUCCESS); return(RedirectToAction("Index", "Movies", new { Area = "" })); } catch (Exception ex) { this.AddNotification(ex.Message, NotificationType.ERROR); return(this.View(model)); } } return(this.View(model)); }
public async Task <ActionResult <List <int> > > Create([FromForm] CreateMovieBindingModel createMovieBm) { var response = await Mediator.Send(Mapper.Map <CreateMovieCommand>(createMovieBm)); return(Ok(response)); }