예제 #1
0
 public void Configure(IApplicationBuilder app)
 {
     app.UseRouter(builder =>
     {
         builder.MapGet($"/bicycles/1", async(request, response, data) =>
         {
             var bicycle = new BicycleResponseModel()
             {
                 Id = 1, Name = "Some Bicycle", Latitude = 10.000m, Longitude = 12.000m, Type = "Shopper"
             };
             var json = JsonConvert.SerializeObject(bicycle);
             await response.WriteAsync(json);
         });
     });
 }
예제 #2
0
        public async Task <IActionResult> CreateBicycle(CreateBicycleCommand command)
        {
            var result = await mediator.Send(command);

            if (result == 0)
            {
                return(BadRequest($"Bicycle with Name: {command.Name}, could not be created"));
            }

            var bicycle = new BicycleResponseModel
            {
                Id        = result,
                Name      = command.Name,
                Type      = command.Type,
                Latitude  = command.Latitude,
                Longitude = command.Longitude
            };

            return(CreatedAtRoute(nameof(GetBicycle), new { id = bicycle.Id }, bicycle));
        }