public async Task <ActionResult <SetTerm> > PostSetRoles(int id, [FromBody] SetRoleIdInputModel sr) { var set = await _context.Sets.FindAsync(id); if (set == null) { return(NotFound("set not found")); } var works = _context.Works.Where(w => (w.SetId == id)).Count(); if (works != 0) { return(BadRequest("it is not possible to change number of roles after set already contains at least one work")); } var newRole = new SetRole { SetId = id, Name = sr.Name, ClassTeacher = sr.ClassTeacher, Manager = sr.Manager, PrintedInApplication = sr.PrintedInApplication, PrintedInReview = sr.PrintedInReview, }; _context.SetRoles.Add(newRole); await _context.SaveChangesAsync(); return(Ok(newRole)); }
public async Task <ActionResult <SetTerm> > PutSetRoles(int id, int roleId, [FromBody] SetRoleIdInputModel sr) { var set = await _context.Sets.FindAsync(id); if (set == null) { return(NotFound("set not found")); } var @role = await _context.SetRoles.FindAsync(roleId); if (@role == null) { return(NotFound("role not found")); } if (role.SetId != set.Id) { return(BadRequest("role is not in this set")); } role.Name = sr.Name; role.ClassTeacher = sr.ClassTeacher; role.Manager = sr.Manager; role.PrintedInApplication = sr.PrintedInApplication; role.PrintedInReview = sr.PrintedInReview; await _context.SaveChangesAsync(); return(Ok(role)); }