Beispiel #1
0
        public async Task <IActionResult> EstabelecimentosPostAsync(Guid id,
                                                                    [FromBody] EstabelecimentosCipasPost model)
        {
            var cipa = await ObterCipaAsync(id);

            var command = mapper.Map <EstabelecimentosCipasPost, AdicionarEstabelecimentoACipaCommand>(model, opts =>
                                                                                                       opts.AfterMap((s, d) =>
            {
                d.Cipa = cipa;
            }));

            await mediator.Send(command);

            return(NoContent());
        }
        public async Task <IActionResult> EstabelecimentosPostAsync(Guid id,
                                                                    [FromBody] EstabelecimentosCipasPost model,
                                                                    [FromServices] IEstabelecimentoReadOnlyRepository estabelecimentoReadOnlyRepository)
        {
            var cipa = await ObterCipaAsync(id);

            var estabelecimento = await estabelecimentoReadOnlyRepository.GetByIdAsync(model.EstabelecimentoId.Value) ??
                                  throw new ResourceNotFoundException(new CoreBusinessResourceNotFoundExceptionItem[] { CoreBusinessResourceNotFoundExceptionItem.Estabelecimento });

            var command = new AtualizarEstabelecimentoCommand()
            {
                Estabelecimento = estabelecimento,
                Codigo          = estabelecimento.Codigo,
                Nome            = estabelecimento.Nome,
                CipaId          = id
            };

            await mediator.Send(command);

            return(NoContent());
        }