public static int Save(SubjectRating subjectRating) { var a = new SubjectRating { SubjectRatingId = subjectRating.SubjectRatingId, SubjectRatingOne = subjectRating.SubjectRatingOne, SubjectRatingTwo = subjectRating.SubjectRatingTwo, SubjectRatingThree = subjectRating.SubjectRatingThree, SubjectRatingFour = subjectRating.SubjectRatingFour, SubjectRatingFinalRating = subjectRating.SubjectRatingFinalRating, SubjectRatingUnit = subjectRating.SubjectRatingUnit, SubjectRatingActionTaken = subjectRating.SubjectRatingActionTaken, ModifiedOn = subjectRating.ModifiedOn, ModifiedBy = subjectRating.ModifiedBy, SubjectId = subjectRating.SubjectId, CurriculumDetailId = subjectRating.CurriculumDetailId, CurriculumDetail = subjectRating.CurriculumDetail, Subject = subjectRating.Subject }; using (_d = new DataRepository <SubjectRating>()) { if (subjectRating.SubjectRatingId > 0) { _d.Update(a); } else { _d.Add(a); } _d.SaveChanges(); } return(a.SubjectRatingId); }
public static bool Delete(SubjectRating subjectRating) { using (_d = new DataRepository <SubjectRating>()) { _d.Delete(subjectRating); _d.SaveChanges(); } return(true); }
public static IReadOnlyCollection <SubjectRating> GetAvarageMarkBySubjects(this IEnumerable <Student> students) { var averageMarks = new List <SubjectRating>(); var studentExams = students.SelectMany(s => s.Exams, (s, e) => new { Student = s, Exam = e }); foreach (string subject in students.First().GetSubjects()) { (string subject, double mark)averageMark = (subject, studentExams .Where(x => x.Exam.Subject == subject) .Select(x => x.Exam.Mark) .Average()); var subjectRating = new SubjectRating { Mark = averageMark.mark, Subject = averageMark.subject }; averageMarks.Add(subjectRating); } return(averageMarks.AsReadOnly()); }