public async Task <IActionResult> PutComment(long id, Comment comment) { if (id != comment.Id) { return(BadRequest()); } _context.Entry(comment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(id)) { return(NotFound("Comment was not found")); } else { throw; } } return(Ok(comment)); }
public async Task <IActionResult> Post([FromBody] TaskItem taskItem) { await _context.TaskItems.AddAsync(taskItem); await _context.SaveChangesAsync(); return(CreatedAtAction("Get", new { taskItem.Id }, taskItem)); }
public async Task <IActionResult> PutTaskItem(long id, TaskItem taskItem) { if (id != taskItem.Id) { return(BadRequest()); } /*Lab2: modificarea stării unui task: dacă se schimbă în closed, se completează câmpul closedAt * ca fiind timpul request-ului. Dacă se schimbă din închis în altceva, se pune timpul închiderii pe null.*/ if (taskItem.State.Equals(State.Closed)) { taskItem.ClosedAt = DateTime.Now; } else { taskItem.ClosedAt = default; } //------------------------------------------------------------------------------------------------------ _context.Entry(taskItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaskItemExists(id)) { return(NotFound("This task does not exist!")); } else { throw; } } return(Ok(taskItem)); }