示例#1
0
        public async Task <ActionResult> Delete([FromServices] IChurrascoRepository churrascoRepository,
                                                [FromServices] IUnitOfWork unitOfWork,
                                                int id)
        {
            try
            {
                var churrasco = await churrascoRepository.GetEntityById(id);

                if (churrasco == null)
                {
                    return(BadRequest("Churrasco não encontrado."));
                }

                churrascoRepository.Delete(churrasco);
                if (await unitOfWork.Commit())
                {
                    return(Ok("Churrasco deletado!"));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro: {ex.Message}"));
            }
        }
        public async Task <ActionResult> Delete([FromServices] IChurrascoUserRepository churrascoUserRepository,
                                                [FromServices] IChurrascoRepository churrascoRepository,
                                                [FromServices] IUnitOfWork unitOfWork,
                                                int idChurrasco,
                                                int idUser)
        {
            try
            {
                var churrascoUser = await churrascoUserRepository.GetEntityByChurrascoIdAndUserId(idChurrasco, idUser);

                if (churrascoUser == null)
                {
                    return(BadRequest("Relação de churrasco com usuário não encontrada."));
                }

                churrascoUserRepository.Delete(churrascoUser);

                if (await unitOfWork.Commit())
                {
                    return(Ok("Usuário deletado do churrasco."));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro: {ex.Message}"));
            }
        }
示例#3
0
        public async Task <ActionResult <ChurrascoGetDto> > Update([FromServices] IChurrascoRepository churrascoRepository,
                                                                   [FromServices] IUnitOfWork unitOfWork,
                                                                   [FromBody] ChurrascoUpdateDto model)
        {
            try
            {
                var churrasco = await churrascoRepository.GetEntityById(model.Id.Value);

                if (churrasco == null)
                {
                    return(BadRequest("Churrasco not found."));
                }

                var churrascoGetDto = await churrascoRepository.Update(model);

                if (await unitOfWork.Commit())
                {
                    return(churrascoGetDto);
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro: {ex.Message}"));
            }
        }
        public async Task <ActionResult <ChurrascoUserGetUserDto> > Update([FromServices] IChurrascoUserRepository churrascoUserRepository,
                                                                           [FromServices] IChurrascoRepository churrascoRepository,
                                                                           [FromServices] IUnitOfWork unitOfWork,
                                                                           [FromBody] ChurrascoUserUpdateDto model)
        {
            try
            {
                var churrascoUserDto = await churrascoUserRepository.Update(model);

                if (churrascoUserDto == null)
                {
                    return(BadRequest("Relação de churrasco com usuário não encontrada."));
                }

                if (await unitOfWork.Commit())
                {
                    return(churrascoUserDto);
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro: {ex.Message}"));
            }
        }
        public async Task <ActionResult <ChurrascoUser> > Post([FromServices] IChurrascoUserRepository churrascoUserRepository,
                                                               [FromServices] IChurrascoRepository churrascoRepository,
                                                               [FromServices] IUserRepository userRepository,
                                                               [FromServices] IUnitOfWork unitOfWork,
                                                               [FromBody] ChurrascoUser model)
        {
            try
            {
                var user = await userRepository.GetEntityById(model.UserId.Value);

                var churrasco = await churrascoRepository.GetEntityById(model.ChurrascoId.Value);

                if (user == null || churrasco == null)
                {
                    return(BadRequest("Usuário ou Churrasco não encontrado."));
                }

                churrascoUserRepository.Add(model);

                if (await unitOfWork.Commit())
                {
                    return(model);
                }
                else
                {
                    return(BadRequest("Erro desconhecido."));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro: {ex.Message}"));
            }
        }
示例#6
0
        public async Task <ActionResult <ChurrascoGetDto> > Post([FromServices] IChurrascoRepository churrascoRepository,
                                                                 [FromServices] IUnitOfWork unitOfWork,
                                                                 [FromBody] ChurrascoAddDto model)
        {
            try
            {
                var churrasco = await churrascoRepository.Add(model);

                if (await unitOfWork.Commit())
                {
                    return(await churrascoRepository.GetById(churrasco.Id));
                }
                else
                {
                    return(BadRequest("Unexpected Error!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest($"Erro: {ex.Message}"));
            }
        }
示例#7
0
 public ChurrascosController(IChurrascoRepository repository)
 {
     _repository = repository;
 }
示例#8
0
 public async Task <ActionResult <List <ChurrascoGetDto> > > GetByUserId([FromServices] IChurrascoRepository churrascoRepository, int id)
 {
     return(await churrascoRepository.GetAllByUserId(id));
 }
示例#9
0
 public async Task <ActionResult <List <ChurrascoGetDto> > > Get([FromServices] IChurrascoRepository churrascoRepository)
 {
     return(await churrascoRepository.GetAll());
 }