Пример #1
0
        public HttpResponseMessage GetReportCardForStudentId(string studentId)
        {
            string userId   = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value;
            string userRole = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == ClaimTypes.Role).Value;

            logger.Info("UserRole: " + userRole + ", UserId: " + userId + ": Requesting Report Card For Student Id: " + studentId);

            try
            {
                ReportCardDTO reportCard = marksService.GetReportCardForStudentId(studentId);
                if (reportCard == null)
                {
                    logger.Info("Failed!");
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Failed!"));
                }
                if (userRole == "admin" || reportCard.StudentId == userId ||
                    reportCard.Parent.Substring(0, 3).Equals(userId))
                {
                    logger.Info("Success!");
                    return(Request.CreateResponse(HttpStatusCode.OK, reportCard));
                }

                logger.Info("Authorisation failure. User is not authorised for this request.");
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Access Denied. We’re sorry, " +
                                                   "but you are not authorized to perform the requested operation."));
            }
            catch (Exception e)
            {
                logger.Error(e);
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }
Пример #2
0
        public void CreateReportCardMail(string studentId, ReportCardDTO reportCard)
        {
            Student student = db.StudentsRepository.GetByID(studentId);

            if (student != null)
            {
                string subject = $"E-School: Student Report Card";

                string body = string.Empty;

                body += $"<p>Dear {student.Parent.FirstName} {student.Parent.LastName},<br/>" +
                        $"We are sending you Report Card for Student {student.FirstName} {student.LastName} on the date of {DateTime.Today}.</p>" +
                        $"<br/>" +
                        $"<br/>" +

                        $"<table border='1'>" +
                        $"<tr><td><b> School Year : </b></td><td colspan=3> {reportCard.SchoolYear} </td></tr>" +
                        $"<tr><td><b> Student : </b></td><td colspan=3> {reportCard.StudentId}, {reportCard.Student} </td></tr>" +
                        $"<tr><td><b> Form : </b></td><td colspan=3> {reportCard.Form} </td></tr>" +
                        $"<tr><td><b> Attending Teacher : </b></td><td colspan=3> {reportCard.AttendingTeacher} </td></tr>" +
                        $"<tr><td><b> Parent : </b></td><td colspan=3> {reportCard.Parent} </td></tr>" +
                        $"<tr><td colspan=4><b> Classes: </b></td></tr>" +
                        $"<tr><td><b><center> Subject </center></b></td><td><b><center> Teacher </center></b></td><td colspan=2><b><center> Mark </center></b></td></tr>";

                foreach (var line in reportCard.Classes)
                {
                    body += "<tr><td>" + line.Subject + "</td><td>" + line.Teacher + "</td><td colspan=2><center><b>" + line.FirstSemesterAverageMark + "</b></center></td></tr>";
                }

                body += "</table>";

                body += $"<br/>" +
                        $"<br/>" +
                        $"Sincerely,<br/>" +
                        $"Svetlana Topalov, E-School";

                string emailTo    = student.Parent.Email;
                bool   isBodyHtml = true;

                CreateMail(subject, body, emailTo, isBodyHtml);
            }
        }
Пример #3
0
        //REPORT CARD
        public ReportCardDTO GetReportCardForStudentId(string studentId)
        {
            Student foundStudent = db.StudentsRepository.GetByID(studentId);

            if (foundStudent == null)
            {
                throw new HttpException("Student with id: " + studentId + " was not found.");
            }

            ReportCardDTO reportCard = new ReportCardDTO
            {
                SchoolYear       = foundStudent.Form.Started.Year,
                StudentId        = foundStudent.Id,
                Student          = foundStudent.FirstName + " " + foundStudent.LastName,
                Form             = foundStudent.Form.Grade + "-" + foundStudent.Form.Tag,
                AttendingTeacher = foundStudent.Form.AttendingTeacher.Id + ", " + foundStudent.Form.AttendingTeacher.FirstName + " " + foundStudent.Form.AttendingTeacher.LastName,
                Parent           = foundStudent.Parent.Id + ", " + foundStudent.Parent.FirstName + " " + foundStudent.Parent.LastName
            };

            IList <ReportCardDTOItem> classes = new List <ReportCardDTOItem>();

            IEnumerable <FormToTeacherSubject> studentFormFTSs = db.FormsToTeacherSubjectsRepository.GetByFormIdOnlyActive(foundStudent.Form.Id);

            foreach (var fts in studentFormFTSs)
            {
                IEnumerable <Mark> studentMarks = db.MarksRepository.GetByFTSIdAndStudentId(fts.Id, foundStudent.Id);
                ReportCardDTOItem  item         = ConvertToReportCardDTOItem(fts, studentMarks);
                classes.Add(item);
            }

            classes            = classes.OrderBy(x => x.Subject).ToList();
            reportCard.Classes = classes;

            emailsService.CreateReportCardMail(foundStudent.Id, reportCard);

            return(reportCard);
        }