public async Task <ActionResult <Sarcina> > PostSarcina(Sarcina sarcina) { _context.Sarcini.Add(sarcina); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSarcina", new { id = sarcina.Id }, sarcina)); }
public async Task <IActionResult> PutSarcina(int id, Sarcina sarcina) { if (id != sarcina.Id) { return(BadRequest()); } //Ex.1 - Task 3 if (sarcina.Stare.Equals(Stare.Closed)) { sarcina.ClosedAt = DateTime.Now; } else { sarcina.ClosedAt = default; } _context.Entry(sarcina).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SarcinaExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }