public async Task <IActionResult> AddMovie(AddMovieCommand model, CancellationToken cancellationToken) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var command = await _mediator.Send(model, cancellationToken); return(Ok(command)); }
public async Task <ActionResult <MovieDetailsModel> > Add([FromBody] AddMovieModel model, CancellationToken cancellationToken) { var command = new AddMovieCommand(model.Id.Value); var result = await Dispatcher.DispatchAsync(command, cancellationToken); if (result is null) { return(NotFound()); } var url = Url.Action(nameof(GetById), new { id = result.Id }); return(Created(url, result)); }
public Movie AddMovie(AddMovieCommand movie) { using (var db = new SqlConnection(_connectionString)) { var sql = @"INSERT [Movie] ([Title] ,[ReleaseDate] ,[PosterURL]) OUTPUT inserted.* VALUES ( @Title ,@ReleaseDate ,@PosterURL)"; return(db.QueryFirst <Movie>(sql, movie)); } }
public async Task <IActionResult> Post( [FromServices] IBus bus, [Required, FromBody] PostModel model) { // Hack: just for testing claims into the command handler HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimsIdentity.DefaultNameClaimType, "test") }, "test")); if (model == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } var command = new AddMovieCommand { Id = NewId.Next().ToString(), Title = model.Title, Year = model.Year }; //await bus.Send(command); string movieId = await bus.SendRequest <string>(command, timeout : TimeSpan.FromMinutes(1)); return(CreatedAtAction("Get", new { id = movieId })); }
public Movie AddMovie(AddMovieCommand movieToAdd) { return(_repo.AddMovie(movieToAdd)); }
public async Task <IActionResult> AddMovie([FromBody] AddMovieCommand command) { var result = await Mediator.Send(command); return(Ok(result)); }