Exemple #1
0
        public IActionResult AssignStudents(int testId, TestType testType)
        {
            switch (testType)
            {
            case TestType.Synthesis:
                if (_synthesisRepository.Get(testId).Status >= TestStatus.Completed)
                {
                    return(StatusCode(500));
                }
                break;

            case TestType.Analysis:
                if (_analysisRepository.Get(testId).Status >= TestStatus.Completed)
                {
                    return(StatusCode(500));
                }
                break;

            default:
                return(StatusCode(500));
            }

            var vm = new AssignStudentsVM
            {
                TestId          = testId,
                TestType        = testType,
                InitialPageSize = 10
            };

            return(View(vm));
        }
Exemple #2
0
        public ActionResult <Result <bool> > DeleteAnalysisTest([FromBody] DeleteEntityRQ body)
        {
            var entity = _analysisRepo.Get(body.Id);

            if (entity.Status > TestStatus.Scheduled)
            {
                var statusText = entity.Status.ToString().ToLower();
                return(Result <bool> .Fail($"Unable to delete. Delete of '{statusText}' test is not allowed"));
            }

            var assignedCount = _analysisRepo.AssignedStudentsCount(body.Id);

            if (assignedCount > 0)
            {
                return(Result <bool> .Fail($"Unable to delete. A total of {assignedCount} students are assigned to this test."));
            }

            var success = _analysisRepo.DeleteTest(body.Id, body.TimeStamp);

            if (success)
            {
                return(Result <bool> .Success(true));
            }
            else
            {
                return(Result <bool> .Fail("Failed to delete record."));
            }
        }
Exemple #3
0
        private int AssignStudentsToAnalysis(IEnumerable <Guid> studentIds, int testId)
        {
            if (_analysisRepo.Get(testId).Status >= TestStatus.Completed)
            {
                return(0);
            }

            var analysisEntity = _analysisRepo.GetWithTaskTemplateAndSolutionFormat(testId);

            #region Get_Output_Format
            var columns = analysisEntity
                          .SynthesisTestStudent
                          .SynthesisTest
                          .Task
                          .SolutionColumns
                          .Select(c => new ColumnDTO(c.ColumnName, c.SqlType));
            #endregion

            var assignModels = NameHelper.AnalysisTestExam(studentIds, analysisEntity.Id);

            #region Clone_Input_Databases
            var analysisTemplateName = analysisEntity.SynthesisTestStudent.SynthesisTest.Task.Template.NameOnServer;
            var dbCloneSuccess       = _microsoftSQLService.CloneDatabases(analysisTemplateName, assignModels.Select(am => am.Database), false, true);
            assignModels = assignModels.Where(x => dbCloneSuccess.Contains(x.Database));
            #endregion

            var outputTablesDbName = _adminConnectionConf.OutputTablesDbName;

            #region Create_Student_Output_Tables
            var studentTableCreateSuccess = _microsoftSQLService.CreateTables(assignModels.Select(x => new CreateTable()
            {
                DatabaseName = outputTablesDbName,
                TableName    = x.StudentOutputTable,
                Columns      = columns,
            }));
            assignModels = assignModels.Where(x => studentTableCreateSuccess.Contains(x.StudentOutputTable));
            #endregion

            #region Create_Teacher_Output_Tables
            var teacherTableCreateSuccess = _microsoftSQLService.CreateTables(assignModels.Select(x => new CreateTable()
            {
                DatabaseName = outputTablesDbName,
                TableName    = x.TeacherOutputTable,
                Columns      = columns,
            }));
            assignModels = assignModels.Where(x => teacherTableCreateSuccess.Contains(x.TeacherOutputTable));
            #endregion

            #region Create_Contained_Users
            var userMapEntities = _userRepo.Get(assignModels.Select(am => am.StudentId)).ToList();
            var createContainedUserSuccessIds = new List <Guid>();
            foreach (var userMapEntity in userMapEntities)
            {
                var assignModel = assignModels.Single(am => am.StudentId == userMapEntity.AzureId);

                if (!CreateContainedCRUD(userMapEntity.SqlUsername, userMapEntity.SqlPassword, assignModel.Database))
                {
                    continue;
                }

                if (!CreateContainedCRUD(userMapEntity.SqlUsername, userMapEntity.SqlPassword, outputTablesDbName, assignModel.StudentOutputTable))
                {
                    continue;
                }

                if (!CreateContainedCRUD(userMapEntity.SqlUsername, userMapEntity.SqlPassword, outputTablesDbName, assignModel.TeacherOutputTable))
                {
                    continue;
                }

                createContainedUserSuccessIds.Add(userMapEntity.AzureId);
            }
            assignModels = assignModels.Where(x => createContainedUserSuccessIds.Contains(x.StudentId));
            #endregion

            return(_studentRepo.AssignAnalysisTest(assignModels, testId, UserId));
        }