public async Task <IActionResult> PutLancamentoHoras(long id, LancamentoHoras lancamentoHoras) { if (id != lancamentoHoras.Id) { return(BadRequest()); } _context.Entry(lancamentoHoras).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LancamentoHorasExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <LancamentoHoras> > PostLancamentoHoras(LancamentoHoras lancamentoHoras) { _context.LubySoftware.Add(lancamentoHoras); await _context.SaveChangesAsync(); //return CreatedAtAction("GetLancamentoHoras", new { id = lancamentoHoras.Id }, lancamentoHoras); return(CreatedAtAction(nameof(GetLancamentoHoras), new { id = lancamentoHoras.Id }, lancamentoHoras)); }
public async Task <ActionResult <LancamentoHoras> > Post ([FromServices] DataContext context, [FromBody] LancamentoHoras model) { if (DateTime.Compare(model.data_inicio, model.data_fim) >= 0) { return(BadRequest("Hora Inicio não pode ser maior ou igual a hora fim")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } context.LancamentoHora.Add(model); await context.SaveChangesAsync(); return(Ok(model)); }
public async Task <ActionResult <LancamentoHoras> > Put(int id, [FromServices] DataContext context, [FromBody] LancamentoHoras model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var lancamentoHoras = await context.LancamentoHora .AsNoTracking() .FirstOrDefaultAsync(x => x.Id == id); lancamentoHoras.data_inicio = model.data_inicio != null ? model.data_inicio : lancamentoHoras.data_inicio; lancamentoHoras.data_fim = model.data_fim != null ? model.data_fim : lancamentoHoras.data_fim; context.LancamentoHora.Update(lancamentoHoras); await context.SaveChangesAsync(); return(Ok("Lançamento atualizado com Sucesso")); }
public async Task <ActionResult <Validacao> > PostLancamentoHoras(LancamentoHoras lancamentoHoras) { try { var desenvolvedorProjeto = _context.DesenvolvedorProjeto .FirstOrDefault(dp => dp.DesenvolvedorId == lancamentoHoras.DesenvolvedorId && dp.ProjetoId == lancamentoHoras.ProjetoId); if (desenvolvedorProjeto == null) { return(Ok(new Validacao("O projeto não está vinculado ao desenvolvedor"))); } _context.LancamentoHoras.Add(lancamentoHoras); await _context.SaveChangesAsync(); return(Ok(new Validacao("Enviado"))); } catch (Exception) { return(NotFound(new { Erro = "Erro no lançamento das Horas" })); } }