Ejemplo n.º 1
0
        public ActionResult Homework(int SelectedTerm, int SelectedGroup, int SelectedType, HomeworkViewModel HVM)
        {
            checkLogin();

            HVM.groupSelectList = SelectedTerm == CP.currentTerm.ID ?
                                  (IEnumerable <SelectListItem>)Session["groupSelectList"] :
                                  StudentGroupService.getGroupSelectList(HVM.SelectedTerm);
            Session["groupSelectList"] = HVM.groupSelectList;
            HVM.typeSelectList         = (IEnumerable <SelectListItem>)Session["typeSelectList"];
            HVM.SelectedTerm           = SelectedTerm;
            HVM.SelectedGroup          = SelectedGroup;
            HVM.SelectedType           = SelectedType;
            HVM.termFilList            = genSelectList(CP.termSelectList, HVM.SelectedTerm);
            HVM.groupFilList           = genSelectList(HVM.groupSelectList, HVM.SelectedGroup);
            HVM.typeFilList            = genSelectList(HVM.typeSelectList, HVM.SelectedType);
            Session["termFilList"]     = HVM.termFilList;
            Session["groupFilList"]    = HVM.groupFilList;
            Session["typeFilList"]     = HVM.typeFilList;

            List <HOMEWORK>     works    = HomeworkService.GetFilteredWorks(HVM.SelectedTerm, HVM.SelectedGroup, HVM.SelectedType); //homeworks
            List <HomeworkView> viewList = new List <HomeworkView>();                                                               //homework in display format

            if (works != null && works.Any())
            {
                for (int h = 0; h < works.Count; h++) //put homeworks into display format
                {
                    HomeworkView view = new HomeworkView();
                    view.ID               = works[h].ID;
                    view.name             = works[h].NAME;
                    view.date_assign      = works[h].ADD_DATE;
                    view.date_due         = works[h].DUE_DATE;
                    view.full_mark        = works[h].FULL_MARK;
                    view.group_id         = works[h].STUDENT_GROUP;
                    view.type_id          = works[h].HOMEWORK_TYPE;
                    view.submission_ratio = works[h].SUBMISSION_RATIO;
                    view.late_ratio       = works[h].LATE_RATIO;
                    view.group_name       = view.group_id > 0 ? DBS.findRecordByID <STUDENT_GROUP>(works[h].STUDENT_GROUP).NAME : string.Empty;
                    view.type_name        = view.type_id > 0 ? DBS.findRecordByID <HOMEWORK_TYPE>(works[h].HOMEWORK_TYPE).NAME : string.Empty;

                    viewList.Add(view);
                }
            }

            HVM.viewList = viewList;

            ModelState.Clear();
            TempData["showForm2"] = false;
            TempData["showForm"]  = false;
            return(View("Homework", HVM));
        }