Exemplo n.º 1
0
        public IHttpActionResult UpdateGrade(GradesDto gradesDto)
        {
            foreach (var grade in gradesDto.Grades)
            {
                if (grade.AssignmentGrade != null && (grade.AssignmentGrade.Value < 0 || grade.AssignmentGrade.Value > 100))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                    {
                        ReasonPhrase = "The grade of student: " + grade.StudentId + " Is Invalid- the grade value should be at range (0,100) or empty"
                    });
                }
            }
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            var currUserName = GetUserName();

            foreach (var grade in gradesDto.Grades)
            {
                var gradeInDb = _context.Grades.Single(g => g.LecturerId.Equals(currUserName) && g.AssignmentId == grade.AssignmentId && g.StudentId.Equals(grade.StudentId));
                if (gradeInDb == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }

                Mapper.Map(grade, gradeInDb);
                gradeInDb.LecturerId = currUserName;
                _context.SaveChanges();
            }



            return(Ok());
        }
Exemplo n.º 2
0
        public decimal getGradePoint(GradesDto grade)
        {
            var     course     = ctx.Courses.Find(grade.course_id);
            decimal gradePoint = (decimal)0.00;

            if (grade.grade_value >= 90)
            {
                gradePoint += (decimal)4.00;
                if (course.is_honors)
                {
                    gradePoint += (decimal)0.50;
                }
                else if (course.is_advanced_placement)
                {
                    gradePoint += (decimal)1.00;
                }

                return(gradePoint);
            }
            else if (grade.grade_value >= 80 && grade.grade_value <= 89)
            {
                gradePoint += (decimal)3.00;
                if (course.is_honors)
                {
                    gradePoint += (decimal)0.50;
                }
                else if (course.is_advanced_placement)
                {
                    gradePoint += (decimal)1.00;
                }

                return(gradePoint);
            }
            else if (grade.grade_value >= 70 && grade.grade_value <= 79)
            {
                gradePoint += (decimal)2.00;
                if (course.is_honors)
                {
                    gradePoint += (decimal)0.50;
                }
                else if (course.is_advanced_placement)
                {
                    gradePoint += (decimal)1.00;
                }

                return(gradePoint);
            }
            else if (grade.grade_value >= 60 && grade.grade_value <= 69)
            {
                gradePoint += (decimal)1.00;
                if (course.is_honors)
                {
                    gradePoint += (decimal)0.50;
                }
                else if (course.is_advanced_placement)
                {
                    gradePoint += (decimal)1.00;
                }

                return(gradePoint);
            }
            else
            {
                return((decimal)0.00);
            }
        }