public IActionResult PostTestForGroup([FromBody] TestGroupInputModel test) { AdminDataAccess adm = new AdminDataAccess(); var group = adm.GetGroupById(test.groupId.Value); if (group == null) { return(BadRequest("Группа не существует")); } AuthorDataAccess author = new AuthorDataAccess(); var t = author.GetTestById(test.testId.Value); if (t == null) { return(BadRequest("Тест не существует")); } if (test.testId == null) { return(BadRequest("Не выбран тест")); } if (test.groupId == null) { return(BadRequest("Не выбрана группа")); } if (string.IsNullOrWhiteSpace(test.startDate)) { return(BadRequest("Отсутствует дата начала теста")); } if (string.IsNullOrWhiteSpace(test.endDate)) { return(BadRequest("Отсутствует дата окончания теста")); } Mapper mapper = new Mapper(); TeacherDataAccess teacher = new TeacherDataAccess(); int id = teacher.SetTestForGroup(mapper.ConvertTestGroupInputModelToTestGroupDTO(test)); return(Ok(id)); }
public IActionResult GetGroupById(int groupId) { Mapper mapper = new Mapper(); AdminDataAccess adm = new AdminDataAccess(); GroupDTO group = adm.GetGroupById(groupId); if (group == null) { return(new BadRequestObjectResult("Запрашиваемой группы не существует")); } else { GroupOutputModel groupOutModel = new GroupOutputModel(); AdminDataAccess gr = new AdminDataAccess(); groupOutModel.Id = group.Id; groupOutModel.Name = group.Name; groupOutModel.StartDate = group.StartDate; groupOutModel.EndDate = group.EndDate; List <UserDTO> students = gr.GetStudents(group.Id); List <UserOutputModel> studentsOut = new List <UserOutputModel>(); foreach (UserDTO st in students) { UserMapper um = new UserMapper(); studentsOut.Add(um.ConvertUserDTOToUserOutputModel(st)); } List <UserDTO> teachers = gr.GetTeacherByGroupId(group.Id); List <UserOutputModel> teachersOut = new List <UserOutputModel>(); foreach (UserDTO tc in teachers) { UserMapper tm = new UserMapper(); teachersOut.Add(tm.ConvertUserDTOToUserOutputModel(tc)); } groupOutModel.Students = studentsOut; groupOutModel.Teachers = teachersOut; return(Ok(groupOutModel)); } }