コード例 #1
0
        public async Task <IActionResult> Post([FromBody] FileCatFormModel model, [FromServices] IMapper mapper)
        {
            var command = new CreateFileCatCommand();

            mapper.Map(model, command);
            var fileCatId = await Mediator.Send(command);

            return(Created(await GetFileCatById(fileCatId)));
        }
コード例 #2
0
        public async Task <IActionResult> Put(int id, [FromBody] FileCatFormModel model, [FromServices] IMapper mapper)
        {
            var fileCat = await GetFileCatById(id);

            if (fileCat == null)
            {
                return(NotFound());
            }

            var updateCommand = new UpdateFileCatCommand(fileCat);

            mapper.Map(model, updateCommand);
            await Mediator.Send(updateCommand);

            return(Updated(await GetFileCatById(id)));
        }