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 void Update(AlunoLanche entity, int id) { var exist = _context.AlunoLanche.Find(id); _context.Entry(exist).CurrentValues.SetValues(entity); _context.SaveChanges(); }
public IActionResult Update(int id, [FromBody] AlunoLanche entity) { if (entity == null) { return(BadRequest()); } _repository.Update(entity, id); return(NoContent()); }
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))); }
public AlunoLanche Create(AlunoLanche entity) { _context.AlunoLanche.Add(entity); _context.SaveChanges(); return(entity); }