public async Task <IActionResult> Delete(string id)
        {
            try
            {
                var command = new DeleteCategoriaCommand {
                    Id = id
                };

                await categoriaApplicationService.Remove(command);

                return(Ok(new { Message = "Categoria excluída com sucesso." }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        public async Task <Unit> Handle(DeleteCategoriaCommand request, CancellationToken cancellationToken)
        {
            //var categoria = categoriaDomainService.GetId(int.Parse(request.Id));
            var categoria = mapper.Map <Categoria>(request);

            //base relacional..
            categoriaDomainService.Delete(categoria);

            //base não relacional..
            await mediator.Publish(new CategoriaNotification
            {
                Categoria = categoria,
                Action    = ActionNotification.Excluir
            });

            return(Unit.Value);
        }
Example #3
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                DeleteCategoriaCommand command = new DeleteCategoriaCommand()
                {
                    Id = id
                };
                await categoriaApplicationService.Delete(command);

                return(Ok(new { message = "Categoria excluída com sucesso!" }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
Example #4
0
        public async Task <Unit> Handle(DeleteCategoriaCommand request, CancellationToken cancellationToken)
        {
            var categoria = mapper.Map <Categoria>(request);

            if (categoria == null)
            {
                throw new Exception("Categoria não encontrada.");
            }

            categoriaDomainService.Remove(categoria);

            await mediator.Publish(new CategoriaNotification
            {
                Categoria = categoria,
                Action    = ActionNotification.Excluir
            });

            return(Unit.Value);
        }
 public async Task Remove(DeleteCategoriaCommand command)
 {
     await mediator.Send(command);
 }