public IList <StudentAnnouncementDetails> GetStudentAnnouncements(int announcementId) { Trace.Assert(Context.PersonId.HasValue); Trace.Assert(Context.SchoolYearId.HasValue); var ann = ServiceLocator.ClassAnnouncementService.GetClassAnnouncemenById(announcementId); var mp = ServiceLocator.MarkingPeriodService.GetMarkingPeriodByDate(ann.Expires, true); Trace.Assert(mp != null); if (ann.SisActivityId.HasValue) { IList <Score> scores = new List <Score>(); IList <Student> persons = new List <Student>(); if (CoreRoles.STUDENT_ROLE == Context.Role) { scores.Add(ActivityScoreStorage.GetScore(ann.SisActivityId.Value, Context.PersonId.Value)); persons.Add(ServiceLocator.StudentService.GetById(Context.PersonId.Value, Context.SchoolYearId.Value)); } else { scores = ActivityScoreStorage.GetSores(ann.SisActivityId.Value); persons = ServiceLocator.StudentService.GetClassStudents(ann.ClassRef, mp.Id); } var res = new List <StudentAnnouncementDetails>(); foreach (var score in scores) { var stAnn = new StudentAnnouncementDetails { ClassId = ann.ClassRef, Student = persons.First(x => x.Id == score.StudentId), AnnouncementId = ann.Id }; MapperFactory.GetMapper <StudentAnnouncementDetails, Score>().Map(stAnn, score); res.Add(stAnn); } return(res); } throw new ChalkableException("Current announcement is not in Inow "); }
public StudentAnnouncement SetGrade(int announcementId, int studentId, string value, string extraCredits, string comment, bool dropped, bool late, bool exempt, bool incomplete, GradingStyleEnum?gradingStyle = null) { var ann = ServiceLocator.ClassAnnouncementService.GetClassAnnouncemenById(announcementId); Trace.Assert(ann.SisActivityId.HasValue); if (!string.IsNullOrEmpty(value) && value.Trim() != "") { exempt = false; } else { value = null; } decimal numericScore; var isDecimal = decimal.TryParse(value, out numericScore); if (value != null && !isDecimal) { var numScore = ServiceLocator.AlphaGradeService.GetAlphaGrades() .FirstOrDefault(x => String.Equals(x.Name, value, StringComparison.InvariantCultureIgnoreCase)); if (numScore != null) { var gradingScaleRange = ((DemoGradingScaleService)ServiceLocator.GradingScaleService).GetByAlphaGradeId(numScore.Id); if (gradingScaleRange != null) { numericScore = gradingScaleRange.AveragingEquivalent; value = numScore.Name; } } } var gradeComment = comment != null && !string.IsNullOrWhiteSpace(comment) ? comment.Trim() : ""; var oldScore = ActivityScoreStorage.GetScore(ann.SisActivityId.Value, studentId); var studentAnnouncement = new StudentAnnouncement(); MapperFactory.GetMapper <StudentAnnouncement, Score>().Map(studentAnnouncement, oldScore); studentAnnouncement.AnnouncementId = oldScore.ActivityId; if (numericScore >= 0 && value != null) { studentAnnouncement.NumericScore = numericScore; studentAnnouncement.ScoreValue = isDecimal ? string.Format("{0:0.00}", numericScore) : value.ToString(CultureInfo.InvariantCulture); } else if (value == null) { studentAnnouncement.NumericScore = null; studentAnnouncement.ScoreValue = ""; } if (value == null && oldScore.ScoreValue != null) { studentAnnouncement.NumericScore = null; studentAnnouncement.ScoreValue = ""; } studentAnnouncement.Exempt = exempt; studentAnnouncement.Late = late; studentAnnouncement.Incomplete = incomplete; studentAnnouncement.ExtraCredit = extraCredits; if (studentAnnouncement.NumericScore.HasValue || studentAnnouncement.Late || studentAnnouncement.Incomplete) { studentAnnouncement.ScoreDropped = dropped; studentAnnouncement.Comment = gradeComment; } else { studentAnnouncement.ScoreDropped = false; } var score = new Score(); MapperFactory.GetMapper <Score, StudentAnnouncement>().Map(score, studentAnnouncement); score = ActivityScoreStorage.UpdateScore(score.ActivityId, score.StudentId, score); score.ActivityDate = ann.Expires; score.ActivityName = ann.Title; MapperFactory.GetMapper <StudentAnnouncement, Score>().Map(studentAnnouncement, score); if (studentAnnouncement.AlternateScoreId.HasValue) { studentAnnouncement.AlternateScore = ServiceLocator.AlternateScoreService.GetAlternateScore(studentAnnouncement.AlternateScoreId.Value); } if (ann.VisibleForStudent) { ServiceLocator.NotificationService.AddAnnouncementSetGradeNotificationToStudent(announcementId, studentAnnouncement.StudentId); } return(studentAnnouncement); }