Example #1
0
 public void SaveGrade(SaveGradeDTO gradeDTO)
 {
     if (!context.Grades.Any(x =>
                             x.StudentId == gradeDTO.StudentId &&
                             x.SubjectId == gradeDTO.SubjectId &&
                             x.TeacherId == gradeDTO.TeacherId))
     {
         var grade = new Grades()
         {
             StudentId = gradeDTO.StudentId,
             SubjectId = gradeDTO.SubjectId,
             TeacherId = gradeDTO.TeacherId,
             GradeId   = gradeDTO.GradeId
         };
         context.Grades.Add(grade);
         SaveChanges();
     }
     else
     {
         var grade = context.Grades.Where(x =>
                                          x.StudentId == gradeDTO.StudentId &&
                                          x.SubjectId == gradeDTO.SubjectId &&
                                          x.TeacherId == gradeDTO.TeacherId).FirstOrDefault();
         grade.GradeId = gradeDTO.GradeId;
         SaveChanges();
     }
 }
Example #2
0
        public void EditGrade(SaveGradeDTO gradeDTO)
        {
            var grade = context.Grades.Where(x => x.Id == gradeDTO.Id).FirstOrDefault();

            grade.TeacherId = gradeDTO.TeacherId;
            grade.GradeId   = gradeDTO.GradeId;
            if (!context.Grades.Any(x =>
                                    x.StudentId == grade.StudentId &&
                                    x.SubjectId == grade.SubjectId &&
                                    x.TeacherId == grade.TeacherId &&
                                    x.GradeId == grade.GradeId))
            {
                SaveChanges();
            }
        }
Example #3
0
 public IHttpActionResult UpdateGrades(SaveGradeDTO gradeDTO)
 {
     gradeService.EditGrade(gradeDTO);
     return(Ok());
 }
Example #4
0
 public IHttpActionResult CreateGradeForStudent(SaveGradeDTO gradeDTO)
 {
     gradeService.SaveGrade(gradeDTO);
     return(Ok());
 }