コード例 #1
0
 public async Task<IActionResult> Post([FromBody] GalleryCatFormModel model, [FromServices] IMapper mapper)
 {
     var command = new CreateGalleryCatCommand();
     mapper.Map(model, command);
     var galleryCatId = await Mediator.Send(command);
     return Created(await GetGalleryCatById(galleryCatId));
 }
コード例 #2
0
        public async Task<IActionResult> Put(int id, [FromBody] GalleryCatFormModel model, [FromServices] IMapper mapper)
        {
            var galleryCat = await GetGalleryCatById(id);
            if (galleryCat == null)
            {
                return NotFound();
            }

            var updateCommand = new UpdateGalleryCatCommand(galleryCat);
            mapper.Map(model, updateCommand);
            await Mediator.Send(updateCommand);
            return Updated(await GetGalleryCatById(id));
        }