public async Task <IActionResult> PutTask(int id, DataBase.Models.Task task) { if (id != task.Id) { return(BadRequest()); } _context.Entry(task).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaskExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <DataBase.Models.Task> > PostTask(DataBase.Models.Task task) { _context.Tasks.Add(task); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTask", new { id = task.Id }, task)); }
public async Task <ActionResult <IEnumerable <object> > > GetByTask(DataBase.Models.Task task) { var comments = await _context .Comments .Where(comment => comment.TaskId == task.Id) .Select(comment => new { Id = comment.Id, TaskId = comment.TaskId, Text = comment.Text, Name = comment.User.Role == UserRole.Student ? comment.User.Student.Name : comment.User.Teacher.Name, Surname = comment.User.Role == UserRole.Student ? comment.User.Student.Surname : comment.User.Teacher.Surname }) .OrderBy(comment => comment.Id) .ToListAsync(); return(Created("", comments)); }