Exemplo n.º 1
0
        // GET: Reports/Edit/5
        public ActionResult EditGroup(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Report report = reportService.Get(id);

            if (report == null)
            {
                return(HttpNotFound());
            }
            ReportGroupViewModel model = new ReportGroupViewModel
            {
                ID         = report.Group.ID,
                ReportID   = report.ID,
                ReportLink = report.Link
            };

            ViewBag.ID = new SelectList(groupService.GetAll(), "ID", "Description");
            return(View(model));
        }
Exemplo n.º 2
0
        public virtual Task <HttpStatusCode> SendEmailReportGroup(ReportGroupViewModel reportGroupInfo)
        {
            var messageSubject = $"Changes to a group's information - {reportGroupInfo.GroupName}";

            _logger.LogInformation("Sending group submission form email");

            var emailBody = new ReportGroupInfoConfirmation
            {
                Email   = reportGroupInfo.Email,
                Name    = reportGroupInfo.Name,
                Subject = reportGroupInfo.Subject,
                Message = reportGroupInfo.Message,
                Slug    = reportGroupInfo.Slug
            };

            return(_emailClient.SendEmailToService(new EmailMessage(messageSubject,
                                                                    _emailClient.GenerateEmailBodyFromHtml(emailBody),
                                                                    _fromEmail,
                                                                    _configuration.GetGroupSubmissionEmail(_businessId.ToString()).ToString(),
                                                                    reportGroupInfo.Email,
                                                                    new List <IFormFile>())));
        }
Exemplo n.º 3
0
        public ActionResult EditGroup(ReportGroupViewModel report)
        {
            if (ModelState.IsValid)
            {
                string path = System.Web.HttpContext.Current.Server.MapPath("~/Content/Uploads/");
                if (System.IO.File.Exists(path + report.ReportLink))
                {
                    System.IO.File.Delete(path + report.ReportLink);
                }

                var group = groupService.Get(report.ID);
                List <ReportStudents> students = new List <ReportStudents>();
                foreach (var student in group.Students)
                {
                    List <Grade> grades = gradeService.GetAll().Where(x => x.UserID == student.ID).ToList();
                    List <Test>  tests  = new List <Test>();
                    foreach (var section in groupSectionService.GetAll().Where(x => x.GroupID == student.GroupID))
                    {
                        tests.AddRange(testService.GetAll().Where(x => x.SectionID == section.SectionID));
                    }
                    double          gradeAVG   = grades.Select(y => y.Value).Sum() / tests.Count;
                    List <UserTask> taskGrades = userTaskService.GetAll().Where(x => x.UserID == student.ID).ToList();
                    List <Task>     tasks      = new List <Task>();
                    foreach (var section in groupSectionService.GetAll().Where(x => x.GroupID == student.GroupID))
                    {
                        tasks.AddRange(taskService.GetAll().Where(x => x.SectionID == section.SectionID));
                    }
                    double gradeTaskAVG = taskGrades.Select(y =>
                    {
                        switch (y.Grade)
                        {
                        case "Отлично":
                            return(1);

                        case "Хорошо":
                            return(0.75);

                        case "Удовлетворительно":
                            return(0.5);

                        case "Неудовлетворительно":
                            return(0.25);

                        default:
                            return(0);
                        }
                    }).Sum() / tasks.Count;

                    students.Add(new ReportStudents
                    {
                        Student = student,
                        TestAVG = gradeAVG,
                        TaskAVG = gradeTaskAVG,
                        SUM     = (gradeAVG + gradeTaskAVG) / 2
                    });
                }

                Report result = new Report
                {
                    Link = CreatePDF(group, students.OrderByDescending(x => x.SUM).ToList())
                };
                var oldReport = group.Report;
                group.Report = result;
                groupService.Edit(group);
                if (oldReport != null && oldReport.ID != 0)
                {
                    reportService.Delete(oldReport);
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.ID = new SelectList(groupService.GetAll(), "ID", "Description");
            return(View(report));
        }