예제 #1
0
        // GET: WeeklyReport
        /// <summary>
        /// Returns an individual weekly report for a student
        /// </summary>
        /// <param name="id">Student ID to generate Report for</param>
        /// <returns>Report data</returns>
        public ActionResult WeeklyReport(string id = null)
        {
            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            // Todo: Remove when identity is fully hooked up
            // Hack, to keep the current system working, while the identity system is slowly hooked up everywhere.  If the user is not logged in, then the passed in user will work, if the user is logged in, then the passed in user is ignored.
            if (string.IsNullOrEmpty(CurrentId))
            {
                CurrentId = id;
            }

            ViewBag.StudentId = CurrentId;  //TODO: Remove this when identity is fully hooked up

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.StudentUser))
            {
                return(RedirectToAction("Roster", "Portal"));
            }

            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(CurrentId);

            if (myStudent == null)
            {
                return(RedirectToAction("Error", "Home"));
            }

            var myReport = new WeeklyReportViewModel()
            {
                StudentId      = CurrentId,
                SelectedWeekId = 1
            };

            var myReturn = ReportBackend.Instance.GenerateWeeklyReport(myReport);

            return(View(myReturn));
        }
        void worker_initDataCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            SchoolYearTextBlock.Text = WeeklyReportViewModel.getInstance().schoolYearForDisplay;
            ClassesBox.ItemsSource   = ClassViewModel.getInstance().allClasses;
            ClassesBox.SelectedIndex = ClassViewModel.getInstance().getClassIndexById(WeeklyReportViewModel.getInstance().selectedClassId);
            WeekNoTextBlock.Text     = "第" + WeeklyReportViewModel.getInstance().weekNoForDisplay + "周";

            ListCollectionView collectionLive = new ListCollectionView(WeeklyReportViewModel.getInstance().weeklyReportLiveItems);

            collectionLive.GroupDescriptions.Add(new PropertyGroupDescription("coursename"));
            weeklyReportLiveDataGrid.ItemsSource = collectionLive;

            ListCollectionView collectionDuoYuan = new ListCollectionView(WeeklyReportViewModel.getInstance().weeklyReportDuoYuanItems);

            collectionDuoYuan.GroupDescriptions.Add(new PropertyGroupDescription("coursename"));
            weeklyReportDuoyuanDataGrid.ItemsSource = collectionDuoYuan;

            ListCollectionView collectionRisk = new ListCollectionView(WeeklyReportViewModel.getInstance().weeklyReportRiskItems);

            collectionRisk.GroupDescriptions.Add(new PropertyGroupDescription("coursename"));
            weeklyReportRiskDataGrid.ItemsSource = collectionRisk;

            ListCollectionView collectionEvaluation = new ListCollectionView(WeeklyReportViewModel.getInstance().weeklyReportEvaluationItems);

            collectionEvaluation.GroupDescriptions.Add(new PropertyGroupDescription("coursename"));
            weeklyReportEvaluationDataGrid.ItemsSource = collectionEvaluation;

            ListCollectionView collectionFamilyAndSchollEdu = new ListCollectionView(WeeklyReportViewModel.getInstance().weeklyReportFamilyAndSchollEduItems);

            collectionFamilyAndSchollEdu.GroupDescriptions.Add(new PropertyGroupDescription("coursename"));
            weeklyReportFamilyAndSchoolEduDataGrid.ItemsSource = collectionFamilyAndSchollEdu;
        }
예제 #3
0
        public void Backend_ReportBackend_Generate_Weekly_Report_Attendance_Overlap_Should_Pass()
        {
            //arrange
            var dateTimeHelper = DateTimeHelper.Instance;

            dateTimeHelper.EnableForced(true);
            dateTimeHelper.SetForced(new DateTime(2018, 10, 20, 0, 0, 0));
            var dateTimeUTCNow = dateTimeHelper.GetDateTimeNowUTC();

            var reportBackend = ReportBackend.Instance;
            var testReport    = new WeeklyReportViewModel
            {
                SelectedWeekId = 1
            };
            var testStudent = DataSourceBackend.Instance.StudentBackend.GetDefault();

            testReport.Student   = testStudent;
            testReport.StudentId = testStudent.Id;

            var dayNow = dateTimeUTCNow.Date;                                                  //today's date

            var thisMonday = dayNow.AddDays(-((dayNow.DayOfWeek - DayOfWeek.Monday + 7) % 7)); //this Monday's date

            var attendanceMon1 = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(12)),
                Emotion = EmotionStatusEnum.VeryHappy
            };

            var attendanceMon2 = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(9)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(11)),
                Emotion = EmotionStatusEnum.VeryHappy
            };

            var attendanceMon3 = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(13)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(14)),
                Emotion = EmotionStatusEnum.VeryHappy
            };


            testStudent.Attendance.Add(attendanceMon1);
            testStudent.Attendance.Add(attendanceMon2);
            testStudent.Attendance.Add(attendanceMon3);

            testReport.DateEnd = dateTimeUTCNow;

            //act
            var result = reportBackend.GenerateWeeklyReport(testReport);

            //reset
            DataSourceBackend.Instance.Reset();

            //assert
            Assert.IsTrue(result.Stats.AccumlatedTotalHours.Equals(new TimeSpan(4, 0, 0)), TestContext.TestName);
        }
예제 #4
0
        // GET: WeeklyReport
        /// <summary>
        /// Returns an individual weekly report for a student
        /// </summary>
        /// <param name="id">Student ID to generate Report for</param>
        /// <returns>Report data</returns>
        public ActionResult WeeklyReport(string id = null)
        {
            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser))
            {
                return(RedirectToAction("Login", "Admin"));
            }

            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(id);

            if (myStudent == null)
            {
                return(RedirectToAction("Error", "Home"));
            }

            var myReport = new WeeklyReportViewModel()
            {
                StudentId      = id,
                SelectedWeekId = 1
            };

            var myReturn = ReportBackend.Instance.GenerateWeeklyReport(myReport);

            return(View(myReturn));
        }
예제 #5
0
        public void Models_WeeklyReportViewModel_Default_Instantiate_Should_Pass()
        {
            // Act
            var result = new WeeklyReportViewModel();

            // Assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
예제 #6
0
        public static List <WeeklyReportViewModel> GetWeeklyReportsUKSA(this List <User> users,
                                                                        DateTime startDate, DateTime endDate,
                                                                        StormContext db)
        {
            // Declare a list of weekly reports and populate it according to the users and date parameters
            var weeklyReportVMList = new List <WeeklyReportViewModel>();

            foreach (var user in users)
            {
                var weeklyReportVM = new WeeklyReportViewModel
                {
                    Name     = user.Name,
                    Location = user.Location.StormLocationName
                };

                foreach (var rfq in db.RFQs.Where(r => r.LoginID == user.LoginID && r.RFQDate > startDate && r.RFQDate < endDate))
                {
                    if (rfq.Status == "CAN")
                    {
                        if (rfq.AccountManager.EndsWith("UK"))
                        {
                            weeklyReportVM.UKRFQs++;
                            rfq.Content.ForEach(c => weeklyReportVM.UKLineItems += Convert.ToInt64(c.Qty));
                        }
                        else if (rfq.AccountManager.EndsWith("SA"))
                        {
                            weeklyReportVM.SARFQs++;
                            rfq.Content.ForEach(c => weeklyReportVM.SALineItems += Convert.ToInt64(c.Qty));
                        }
                    }
                    else
                    {
                        if (rfq.AccountManager.EndsWith("UK"))
                        {
                            weeklyReportVM.UKCancelledRFQs++;
                            rfq.Content.ForEach(c => weeklyReportVM.UKCancelledLineItems += Convert.ToInt64(c.Qty));
                        }
                        else if (rfq.AccountManager.EndsWith("SA"))
                        {
                            weeklyReportVM.SACancelledRFQs++;
                            rfq.Content.ForEach(c => weeklyReportVM.SACancelledLineItems += Convert.ToInt64(c.Qty));
                        }
                    }
                }
                //Add the newly populated WeeklyReportVM to the list declared at the beginning
                weeklyReportVMList.Add(weeklyReportVM);
            }

            // Return the list
            return(weeklyReportVMList);
        }
예제 #7
0
        /// <summary>
        /// Index Page
        /// </summary>
        /// <param name="id">Student Id</param>
        /// <returns>Student Record as a Student View Model</returns>
        // GET: Portal
        public ActionResult Index(string id = null)
        {
            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            // Todo: Remove when identity is fully hooked up
            // Hack, to keep the current system working, while the identity system is slowly hooked up everywhere.  If the user is not logged in, then the passed in user will work, if the user is logged in, then the passed in user is ignored.
            if (string.IsNullOrEmpty(CurrentId))
            {
                CurrentId = id;
            }

            ViewBag.StudentId = CurrentId;  //TODO: Remove this when identity is fully hooked up

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.StudentUser))
            {
                return(RedirectToAction("Roster", "Portal"));
            }

            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(CurrentId);

            if (myStudent == null)
            {
                return(RedirectToAction("Roster", "Portal"));
            }

            var myReturn = new StudentDisplayViewModel(myStudent);

            //Set the last log in time and emotion status img uri
            if (myReturn.Attendance.Any())
            {
                myReturn.LastLogIn = UTCConversionsBackend.UtcToKioskTime(myReturn.Attendance.OrderByDescending(m => m.In).FirstOrDefault().In);
            }

            var myWeeklyReport = new WeeklyReportViewModel()
            {
                StudentId      = CurrentId,
                SelectedWeekId = 1
            };

            var myMonthlyReport = new MonthlyReportViewModel()
            {
                StudentId       = CurrentId,
                SelectedMonthId = 1
            };

            myReturn.WeeklyAttendanceScore  = ReportBackend.Instance.GenerateWeeklyReport(myWeeklyReport).Stats.PercAttendedHours;
            myReturn.MonthlyAttendanceScore = ReportBackend.Instance.GenerateMonthlyReport(myMonthlyReport).Stats.PercAttendedHours;

            return(View(myReturn));
        }
예제 #8
0
        public ActionResult WeeklyReport([Bind(Include =
                                                   "StudentId," +
                                                   "SelectedWeekId" +
                                                   "")] WeeklyReportViewModel data)
        {
            if (data == null)
            {
                // Send to error page
                return(RedirectToAction("Error", "Home"));
            }

            //generate the report
            var myReturn = ReportBackend.Instance.GenerateWeeklyReport(data);

            return(View(myReturn));
        }
예제 #9
0
        public void Controller_Admin_Weekly_Report_Post_Data_Is_Null_Should_Return_Error_Page()
        {
            // Arrange
            AdminController       controller = new AdminController();
            WeeklyReportViewModel data       = null;

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var result = (RedirectToRouteResult)controller.WeeklyReport(data);

            // Assert
            Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName);
        }
예제 #10
0
        public void Controller_Admin_Semester_Report_Post_Selected_ID_Is_2_Should_Pass()
        {
            // Arrange
            AdminController controller = new AdminController();
            var             data       = new WeeklyReportViewModel()
            {
                StudentId      = DataSourceBackend.Instance.StudentBackend.GetDefault().Id,
                SelectedWeekId = 2
            };

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var result = controller.WeeklyReport(data);

            // Assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
예제 #11
0
        public void Models_WeeklyReportViewModel_Get_Set_Check_All_Fields_Should_Pass()
        {
            // Arrange

            // Act
            // Set all the fields for a BaseReportViewModel
            var test = new WeeklyReportViewModel
            {
                SelectedWeekId = 1,
                Weeks          = new List <SelectListItem>()
            };

            var expectedSelectedWeekId = 1;

            // Assert

            //Check each value
            Assert.AreEqual(test.SelectedWeekId, expectedSelectedWeekId, "SelectedWeekId " + TestContext.TestName);

            Assert.IsNotNull(test.Weeks, "Weeks " + TestContext.TestName);
        }
예제 #12
0
        public ActionResult WeeklyReport([Bind(Include =
                                                   "StudentId," +
                                                   "SelectedWeekId" +
                                                   "")] WeeklyReportViewModel data)
        {
            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser))
            {
                return(RedirectToAction("Login", "Admin"));
            }

            if (data == null)
            {
                // Send to error page
                return(RedirectToAction("Error", "Home"));
            }

            //generate the report
            var myReturn = ReportBackend.Instance.GenerateWeeklyReport(data);

            return(View(myReturn));
        }
예제 #13
0
        public void Backend_ReportBackend_Generate_Weekly_Report_Should_Pass()
        {
            //arrange
            var dateTimeHelper = DateTimeHelper.Instance;

            dateTimeHelper.EnableForced(true);
            dateTimeHelper.SetForced(new DateTime(2018, 10, 20, 0, 0, 0));
            var dateTimeUTCNow = dateTimeHelper.GetDateTimeNowUTC();

            var reportBackend = ReportBackend.Instance;
            var testReport    = new WeeklyReportViewModel
            {
                SelectedWeekId = 1
            };
            var testStudent = DataSourceBackend.Instance.StudentBackend.GetDefault();

            testReport.Student   = testStudent;
            testReport.StudentId = testStudent.Id;

            var dayNow = dateTimeUTCNow.Date;                                                      //today's date

            var thisMonday = dayNow.AddDays(-7 - ((dayNow.DayOfWeek - DayOfWeek.Monday + 7) % 7)); //this Monday's date

            var attendanceMon = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(9)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddHours(12)),
                Emotion = EmotionStatusEnum.VeryHappy
            };
            var attendanceTue = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(1).AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(1).AddHours(12)),
                Emotion = EmotionStatusEnum.Happy
            };
            var attendanceWed = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(2).AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(2).AddHours(12)),
                Emotion = EmotionStatusEnum.Neutral
            };
            var attendanceThu = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(3).AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(3).AddHours(12)),
                Emotion = EmotionStatusEnum.Sad
            };
            var attendanceFri = new AttendanceModel
            {
                In      = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(4).AddHours(10)),
                Out     = UTCConversionsBackend.KioskTimeToUtc(thisMonday.AddDays(4).AddHours(12)),
                Emotion = EmotionStatusEnum.VerySad
            };

            testStudent.Attendance.Add(attendanceMon);
            testStudent.Attendance.Add(attendanceTue);
            testStudent.Attendance.Add(attendanceWed);
            testStudent.Attendance.Add(attendanceThu);
            testStudent.Attendance.Add(attendanceFri);

            testReport.DateEnd = dateTimeUTCNow;

            //act
            var result = reportBackend.GenerateWeeklyReport(testReport);

            //reset
            DataSourceBackend.Instance.Reset();

            //assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
예제 #14
0
        /// <summary>
        /// Generate Weekly report
        /// </summary>
        /// <param name="report"></param>
        /// <returns></returns>
        public WeeklyReportViewModel GenerateWeeklyReport(WeeklyReportViewModel report)
        {
            //set student
            report.Student = DataSourceBackend.Instance.StudentBackend.Read(report.StudentId);

            //to generate week selection drop down, make a list item for every week between first and last day of school
            var dayFirst = DataSourceBackend.Instance.SchoolDismissalSettingsBackend.GetDefault().DayFirst.Date;
            var dayLast  = DataSourceBackend.Instance.SchoolDismissalSettingsBackend.GetDefault().DayLast.Date;

            var dayNow = UTCConversionsBackend.UtcToKioskTime(DateTimeHelper.Instance.GetDateTimeNowUTC()).Date;

            //The first valid week(Monday's date) for the dropdown
            var FirstWeek = dayFirst.AddDays(-((dayFirst.DayOfWeek - DayOfWeek.Monday + 7) % 7)); //added this mod operation to make sure it's the previous monday not the next monday
            //The last valid month for the dropdown
            var LastWeek = dayLast.AddDays(-((dayLast.DayOfWeek - DayOfWeek.Monday + 7) % 7));
            //The month of today
            var WeekNow = dayNow.AddDays(-((dayNow.DayOfWeek - DayOfWeek.Monday + 7) % 7)); //if today is sunday, dayNow.DayOfWeek - DayOfWeek.Monday = -1

            //do not go beyond the week of today
            if (LastWeek > WeekNow)
            {
                LastWeek = WeekNow;
            }

            //Set the current week (loop variable) to the last valid week
            var currentWeek = LastWeek;


            //initialize the dropdownlist
            report.Weeks = new List <SelectListItem>();

            // the week id
            int weekId = 1;

            //loop backwards in time so that the week select list items are in time reversed order
            while (currentWeek >= FirstWeek)
            {
                //the friday's date of the current week
                var currentWeekFriday = currentWeek.AddDays(4);

                //make a list item for the current week
                var week = new SelectListItem {
                    Value = "" + weekId, Text = "" + currentWeek.ToShortDateString() + " to " + currentWeekFriday.ToShortDateString()
                };

                //add to the select list
                report.Weeks.Add(week);

                //if current week is the selected month, set the start date and end date for this report
                if (weekId == report.SelectedWeekId)
                {
                    //set start date and end date
                    report.DateStart = currentWeek;
                    report.DateEnd   = currentWeekFriday;
                }

                weekId++;
                currentWeek = currentWeek.AddDays(-7);
            }


            //Generate report for this month
            GenerateReportFromStartToEnd(report);

            return(report);
        }
 public void worker_initData(object sender, DoWorkEventArgs e)
 {
     WeeklyReportViewModel.getInstance().initData();
 }