public async Task <IActionResult> PutSolution(Guid id, SolutionDTO solution) { if (id != solution.Id) { return(BadRequest()); } var find = await _context.Solutions.FindAsync(id); _context.Entry(find).State = EntityState.Modified; find.Description = solution.Description; find.LaboratoryWorkId = solution.LaboratoryWorkId; find.Mark = solution.Mark; find.OwnerId = solution.OwnerId; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { if (!SolutionExists(id)) { return(NotFound()); } else { _logger.LogError(ex.Message); return(StatusCode(500)); } } return(Ok()); }
public override void beforeAll() { base.beforeAll(); _solutionDto = new ObjectMother(AdministratorClarifySession).CreateSolution(); _solutionAssembler = Container.GetInstance <IModelBuilder <Solution> >(); _solution = _solutionAssembler.GetOne(_solutionDto.IDNumber); }
// TEST: files for solutions // done public async Task <OperationDetailDTO <TaskDTO> > GetTaskByIDAsync(int id) { var detail = new OperationDetailDTO <TaskDTO>(); var resultTaskDTO = new TaskDTO(); var resSolutionDTOList = new List <SolutionDTO>(); var resStudentDTOList = new List <StudentDTO>(); try { var entity = await _context.TaskModels .Include(t => t.Group) .Include(t => t.TaskStudentItems) .Include(t => t.Solutions) .Include(t => t.Subject) .Include(t => t.Type) .Include(t => t.File) .Include(t => t.Teacher) .FirstOrDefaultAsync(t => t.Id == id); if (entity == null) { detail.ErrorMessages.Add("Задача не найдена."); return(detail); } foreach (var ts in entity.TaskStudentItems) { var studentEntuty = await _context.Students.FindAsync(ts.StudentId); resStudentDTOList.Add(StudentDTO.Map(studentEntuty)); } // [files] foreach (var solution in entity.Solutions) { var solutionEntity = await _context.Solutions .Include(s => s.File) .Where(s => s == solution) .FirstOrDefaultAsync(); resSolutionDTOList.Add(SolutionDTO.Map(solutionEntity)); } resultTaskDTO = TaskDTO.Map(entity); _taskService.GetCurrentTimePercentage(ref resultTaskDTO); resultTaskDTO.Solutions = resSolutionDTOList; resultTaskDTO.Students = resStudentDTOList; detail.Data = resultTaskDTO; detail.Succeeded = true; return(detail); } catch (Exception e) { detail.ErrorMessages.Add(_serverErrorMessage + e.Message); return(detail); } }
public override void beforeAll() { base.beforeAll(); _solutionDto = new ObjectMother(AdministratorClarifySession).CreateSolution(); var solutionAssembler = Container.GetInstance <IModelBuilder <Solution> >(); _solution = solutionAssembler.Get(FilterType.Equals("id_number", _solutionDto.IDNumber)).First(); }
public override void beforeAll() { base.beforeAll(); _solution1Dto = new ObjectMother(AdministratorClarifySession).CreateSolution(); _solution2Dto = new ObjectMother(AdministratorClarifySession).CreateSolution(); Container.Configure(d => d.For <ModelMap <Solution> >().Use <SolutionIdentifiedByIdNumberMap>()); }
public override void beforeAll() { base.beforeAll(); _solutionDto = new ObjectMother(AdministratorClarifySession).CreateSolution(); //put a service into the container to inject the solution's resolution objid Container.Inject(new FilterInjectionService { FilterObjid = _solutionDto.Resolutions[1] }); _solutionAssembler = Container.GetInstance <IModelBuilder <FilteredSolution> >(); _solution = _solutionAssembler.GetOne(_solutionDto.IDNumber); }
private async Task AddProjectsToSolutionAsync(SolutionDTO solutionDTO) { string[] projectsFilesPaths = fileService.GetFilesPaths(solutionDTO.Path, CsProjSearchPattern); foreach (string projectDirectoryPath in fileService.GetFilesDirectoriesPaths(projectsFilesPaths)) { ProjectDTO projectDTO = new ProjectDTO { Name = directoryService.GetName(projectDirectoryPath), Path = projectDirectoryPath }; await AddPackagesToProjectAsync(projectDTO); solutionDTO.Projects.Add(projectDTO); } }
private async Task AddSolutionsToRepositoryAsync(RepositoryDTO repositoryDTO) { string[] solutionsFilesPaths = fileService.GetFilesPaths(repositoryDTO.Path, SolutionSearchPattern); foreach (string solutionDirectoryPath in fileService.GetFilesDirectoriesPaths(solutionsFilesPaths)) { SolutionDTO solutionDTO = new SolutionDTO { Name = directoryService.GetName(solutionDirectoryPath), Path = solutionDirectoryPath }; await AddProjectsToSolutionAsync(solutionDTO); repositoryDTO.Solutions.Add(solutionDTO); } }
public void RetirerSolutionParID(int p_id) { if (p_id < 1) { throw new ArgumentOutOfRangeException(nameof(p_id)); } Solution solutionASupprimer = ChercherSolutionParSolutionID(p_id); if (solutionASupprimer is null) { throw new ArgumentNullException(nameof(solutionASupprimer)); } else { SolutionDTO solutionDTO = new SolutionDTO(solutionASupprimer); this.m_appDbContext.Solution.Remove(solutionDTO); this.m_appDbContext.SaveChanges(); } }
public async Task <OperationDetailDTO <TaskDTO> > GetTaskByIDAsync(int id) { var detail = new OperationDetailDTO <TaskDTO>(); var resultTaskDTO = new TaskDTO(); SolutionDTO resSolutionDTO = null; Solution solutionEntity; try { var currentUserEntity = await GetUserFromClaimsAsync(); var studentEntity = await _context.Students .Include(s => s.User) .Include(s => s.Solutions) .Where(s => s.UserId == currentUserEntity.Id) .FirstOrDefaultAsync(); var taskEntity = await _context.TaskModels .Include(t => t.Group) .Include(t => t.Solutions) .Include(t => t.Subject) .Include(t => t.Type) .Include(t => t.File) .Include(t => t.Teacher) .Include(t => t.TaskStudentItems) .FirstOrDefaultAsync(t => t.Id == id); if (taskEntity == null) { detail.ErrorMessages.Add("Задача не найдена."); return(detail); } resultTaskDTO = TaskDTO.Map(taskEntity); _taskService.GetCurrentTimePercentage(ref resultTaskDTO); solutionEntity = await _context.Solutions .Include(s => s.Student) .Include(s => s.File) .Where(s => s.TaskId == id) .Where(s => s.StudentId == studentEntity.Id) .FirstOrDefaultAsync(); if (solutionEntity != null) { resSolutionDTO = SolutionDTO.Map(solutionEntity); } resultTaskDTO.Solution = resSolutionDTO; resultTaskDTO.Solutions = null; detail.Data = resultTaskDTO; detail.Succeeded = true; return(detail); } catch (Exception e) { detail.ErrorMessages.Add(_serverErrorMessage + e.Message); return(detail); } }
public async Task <OperationDetailDTO <List <TaskDTO> > > GetTasksFromDBAsync(FilterDTO[] filters = null) { var detail = new OperationDetailDTO <List <TaskDTO> >(); var resultList = new List <TaskDTO>(); try { var currentUserEntity = await GetUserFromClaimsAsync(); var studentEntity = await _context.Students .Include(s => s.User) .Where(s => s.UserId == currentUserEntity.Id) .FirstOrDefaultAsync(); var tasks = from t in _context.TaskModels .Include(t => t.Teacher) .Include(t => t.Subject) .Include(t => t.Type) .Include(t => t.Solutions) .Where(t => (t.TaskStudentItems.FirstOrDefault(x => x.StudentId == studentEntity.Id) != null)) select t; tasks.OrderBy(t => t.BeginDate); if (filters != null) { foreach (var filter in filters) { switch (filter.Name) { case "subjectId": { var value = Convert.ToInt32(filter.Value); if (value > 0) { tasks = tasks.Where(t => t.SubjectId == value); } break; } case "typeId": { var value = Convert.ToInt32(filter.Value); if (value > 0) { tasks = tasks.Where(t => t.TypeId == value); } break; } case "searchString": { var value = filter.Value; if (!String.IsNullOrEmpty(value)) { tasks = tasks.Where(t => t.Name.ToUpper().Contains(value) || t.ContentText.ToUpper().Contains(value)); } break; } case "isOpen": { var value = filter.Value; if (!String.IsNullOrEmpty(value)) { if (value == "true") { tasks = tasks .Where(t => t.IsOpen); } if (value == "false") { tasks = tasks .Where(t => !t.IsOpen); } } break; } } } } foreach (var entity in tasks) { var solution = new Solution(); SolutionDTO currentSolution = null; if (entity.Solutions.Count > 0) { if ((solution = entity.Solutions.Where(s => (s.StudentId == studentEntity.Id)).FirstOrDefault()) != null) { currentSolution = SolutionDTO.Map(solution); } } entity.Solutions = null; var taskDTO = TaskDTO.Map(entity); taskDTO.Solution = currentSolution; resultList.Add(taskDTO); } detail.Succeeded = true; detail.Data = resultList; return(detail); } catch (Exception e) { detail.Succeeded = false; detail.ErrorMessages.Add(_serverErrorMessage + e.Message); return(detail); } }
private int StoreAttempt(ISolver solver, LibraryPuzzle dto, SolverState state, string desc) { var best = state.Solutions?.OrderBy(x => x.Count).FirstOrDefault(); var sol = new SolutionDTO { IsAutomated = true, PuzzleIdent = dto.Ident.ToString(), Path = best?.ToString(), Created = DateTime.Now, Modified = DateTime.Now, MachineName = Environment.MachineName, MachineCPU = DevHelper.DescribeCPU(), SolverType = solver.GetType().Name, SolverVersionMajor = solver.VersionMajor, SolverVersionMinor = solver.VersionMinor, SolverDescription = solver.VersionDescription, TotalNodes = solver.Statistics.First().TotalNodes, TotalSecs = solver.Statistics.First().DurationInSec, Description = desc }; var exists = Repository.GetPuzzleSolutions(dto.Ident); if (exists != null && exists.Any()) { var onePerMachine = exists.FirstOrDefault(x => x.MachineName == sol.MachineName && x.SolverType == sol.SolverType); if (onePerMachine != null) { if (sol.HasSolution) { if (!onePerMachine.HasSolution) { sol.SolutionId = onePerMachine.SolutionId; // replace Repository.Store(sol); return(sol.SolutionId); } else if (sol.TotalNodes < onePerMachine.TotalSecs) { sol.SolutionId = onePerMachine.SolutionId; // replace Repository.Store(sol); return(sol.SolutionId); } else { // drop } } else { if (!onePerMachine.HasSolution && sol.TotalNodes > onePerMachine.TotalNodes) { sol.SolutionId = onePerMachine.SolutionId; // replace Repository.Store(sol); return(sol.SolutionId); } } } else { Repository.Store(sol); return(sol.SolutionId); } } else { Repository.Store(sol); return(sol.SolutionId); } return(-1); }
// test // сразу формировать DTO public async Task <OperationDetailDTO <List <SubjectDTO> > > GetMainDataAsync() { var detail = new OperationDetailDTO <List <SubjectDTO> >(); var resSubjectDTOList = new List <SubjectDTO>(); try { var currentUserEntity = await GetUserFromClaimsAsync(); var currentTeacher = await _context.Teachers .Include(t => t.User) .Include(t => t.Department) .ThenInclude(d => d.Faculty) .Where(t => t.UserId == currentUserEntity.Id) .FirstOrDefaultAsync(); // все задачи текущего преподавателя IQueryable <TaskModel> teacherTaskQueryList = from t in _context.TaskModels .Include(t => t.Teacher) .Include(t => t.Group) .ThenInclude(g => g.Tasks) .Include(t => t.Group) .ThenInclude(g => g.Students) .Include(t => t.Subject) .Include(t => t.Type) .Include(t => t.Solutions) .Include(t => t.TaskStudentItems) .Where(t => t.TeacherId == currentTeacher.Id) select t; // все предметы, по которым есть задачи IQueryable <Subject> subjectQueryList_ = from s in _context.Subjects .Include(s => s.Tasks) .Where(s => s.Tasks.Count > 0) select s; // формируем список сущностей предметов var resSubjectEntityList = new List <Subject>(); var resGroupEntityList = new List <Group>(); // из всех задач препода получить список предметов по которым у препода есть задачи foreach (var task in teacherTaskQueryList) { SubjectDTO currentSubjectDTO; GroupDTO currentGroupDTO; var newStudentDTO = new StudentDTO(); if ((currentSubjectDTO = resSubjectDTOList.FirstOrDefault(s => s.Id == task.SubjectId)) != null) { if ((currentGroupDTO = currentSubjectDTO.Groups.FirstOrDefault(g => g.Id == task.GroupId)) != null) { if (currentGroupDTO.Students != null) { foreach (var student in currentGroupDTO.Students) { // get every student solution for current task var ts = new TaskStudentItem(); var solution = new Solution(); if ((ts = task.TaskStudentItems.FirstOrDefault(ts => (ts.StudentId == student.Id) && (ts.TaskId == task.Id))) != null) { var taskDTO = TaskDTO.Map(task); var solEnt = task.Solutions.Where(s => s.StudentId == student.Id).FirstOrDefault(); if (solEnt != null) { taskDTO.Solution = SolutionDTO.Map(solEnt); } student.Tasks.Add(taskDTO); } } } } else { currentGroupDTO = GroupDTO.Map(task.Group); // currentSubjectDTO.Groups.Add(currentGroupDTO); if (currentGroupDTO.Students != null) { foreach (var student in currentGroupDTO.Students) { var ts = new TaskStudentItem(); var solution = new Solution(); if ((ts = task.TaskStudentItems.FirstOrDefault(ts => (ts.StudentId == student.Id) && (ts.TaskId == task.Id))) != null) { var taskDTO = TaskDTO.Map(task); var solEnt = task.Solutions.Where(s => s.StudentId == student.Id).FirstOrDefault(); if (solEnt != null) { taskDTO.Solution = SolutionDTO.Map(solEnt); } student.Tasks.Add(taskDTO); } } } } } else { currentGroupDTO = GroupDTO.Map(task.Group); currentSubjectDTO = SubjectDTO.Map(task.Subject); // наполняем студентов группы заданиями и решениями foreach (var student in currentGroupDTO.Students) { var ts = new TaskStudentItem(); if ((ts = task.TaskStudentItems.FirstOrDefault(ts => (ts.StudentId == student.Id) && (ts.TaskId == task.Id))) != null) { var taskDTO = TaskDTO.Map(task); var solEnt = task.Solutions.Where(s => s.StudentId == student.Id).FirstOrDefault(); if (solEnt != null) { taskDTO.Solution = SolutionDTO.Map(solEnt); } student.Tasks.Add(taskDTO); } } currentSubjectDTO.Groups.Add(currentGroupDTO); resSubjectDTOList.Add(currentSubjectDTO); } } detail.Succeeded = true; detail.Data = resSubjectDTOList; return(new OperationDetailDTO <List <SubjectDTO> > { Data = resSubjectDTOList, Succeeded = true }); } catch (Exception e) { detail.Succeeded = false; detail.ErrorMessages.Add(_serverErrorMessage + e.Message); return(detail); } }