Example #1
0
        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));
        }
Example #2
0
        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));
        }
Example #3
0
 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));
     }
 }
Example #4
0
        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 }));
        }
Example #5
0
 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));
        }