public IActionResult alunoPegaMerenda(string AlunoMatricula, int COD_Estoque, int LancheId) { var aluno = _alunoRepository.GetByMatricula(AlunoMatricula); var estoque = _estoqueRepository.GetByCOD(COD_Estoque); if (aluno != null) { estoque.QtdEstoque--; if (estoque.QtdEstoque >= 0) { _estoqueRepository.Update(estoque, estoque.Id); var alunoLanche = new AlunoLanche() { AlunoId = aluno.Id, LancheId = LancheId }; _alunoLancheRepository.Create(alunoLanche); return(Ok("Lanche Registrado")); } else { return(BadRequest("Estoque esgotado!")); } } return(BadRequest("Aluno não existe")); }
public IActionResult Create([FromBody] AlunoLanche entity) { if (entity == null) { return(BadRequest("A entidade não pode ser null")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok(_repository.Create(entity))); }