Ejemplo n.º 1
0
        public IActionResult Post([FromBody] AssessmentPost assessment, string subject, string cohort, string name)
        {
            AssessmentValidator validator = new AssessmentValidator();
            List <Error>        errors    = new List <Error>();

            subject = Utils.CleanParam(subject);
            name    = Utils.CleanParam(name);

            dynamic examResult = _db.FetchExam(subject, name, cohort);

            if (examResult == null)
            {
                return(new HttpNotFoundResult());
            }

            if (!_db.IsModelStateValid(ModelState, assessment))
            {
                return(_db.ModelStateErrors);
            }

            errors.AddRange(validator.ValidatePost(assessment));
            if (errors.Any())
            {
                return(new UnprocessableEntityObjectResult(errors));
            }

            var    id       = _db.AddAssessment(assessment, subject, name, cohort, examResult);
            var    result   = _db.FetchAssessment(id);
            string location = Url.RouteUrl("assessment", new { id = id }, Request.Scheme);

            return(new CreatedResult(location, result));
        }
Ejemplo n.º 2
0
        private void AddAssessmentAssessors(AssessmentPost assessment, dynamic assessmentResult, dynamic assessorResult)
        {
            var assessorAssessments = ((IEnumerable <dynamic>)assessorResult).Select(assessor => "(" + assessmentResult + ", " + assessor.Id + ")");

            var query = @"INSERT INTO AssessmentAssessors (AssessmentId, AssessorId) VALUES ";

            query += string.Join(",", assessorAssessments);
            _gateway.Insert(query, null);
        }
Ejemplo n.º 3
0
        public object AddAssessment(AssessmentPost assessment, string subject, string name, string cohort, dynamic examResult)
        {
            object assessorResult   = SelectAssessors(assessment.Assessors);
            object assessmentResult = InsertAssessment(assessment, examResult);

            AddAssessmentAssessors(assessment, assessmentResult, assessorResult);
            AddCategories(assessmentResult, examResult);
            AddObservations(assessmentResult, examResult);

            return(assessmentResult);
        }
Ejemplo n.º 4
0
        private object InsertAssessment(AssessmentPost assessment, dynamic examResult)
        {
            var query = @"INSERT INTO Assessments (ExamId, StudentName, StudentNumber, Assessed, Name, Cohort, Crebo, Subject)
                          VALUES (@ExamId, @StudentName, @StudentNumber, @Assessed, @Name, @Cohort, @Crebo, @Subject);";

            var parameters = new
            {
                ExamId        = examResult.Id,
                StudentName   = assessment.Student?.Name ?? string.Empty,
                StudentNumber = assessment.Student?.Number ?? string.Empty,
                Assessed      = assessment.Assessed?.ToString("s") + "Z",
                Name          = examResult.Name,
                Cohort        = examResult.Cohort,
                Crebo         = examResult.Crebo,
                Subject       = examResult.Subject
            };

            return(_gateway.Insert(query, parameters));
        }