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(); } }
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(); } }
public IHttpActionResult UpdateGrades(SaveGradeDTO gradeDTO) { gradeService.EditGrade(gradeDTO); return(Ok()); }
public IHttpActionResult CreateGradeForStudent(SaveGradeDTO gradeDTO) { gradeService.SaveGrade(gradeDTO); return(Ok()); }