Esempio n. 1
0
        public ActionResult _Student(_StudentViewModel SVM)
        {
            checkLogin();

            // fields checking
            if (!ModelState.IsValid)
            {
                return(View("_Student", SVM));
            }

            //edit or create
            bool result = false;

            if (SVM.selectedStudent.ID > 0)
            {//ediit
                SVM.selectedStudent.MODIFY_BY   = CP.userID;
                SVM.selectedStudent.MODIFY_DATE = DateTime.Now;
                result = DBS.updateRecord(SVM.selectedStudent);
            }
            else
            {//create
                SVM.selectedStudent.ACTIVE   = true;
                SVM.selectedStudent.ADD_BY   = CP.userID;
                SVM.selectedStudent.ADD_DATE = DateTime.Now;
                SVM.selectedStudent.ID       = DBS.addRecordReturnID(SVM.selectedStudent);

                CLASS_STUDENT_LIST newMap = new CLASS_STUDENT_LIST(SVM.selectedClass, SVM.selectedStudent.ID, SVM.selectedStudentNum, CP.userID, DateTime.Now, 0, Constant.DEF_DATETIME, true);
                int newMap_id             = DBS.addRecordReturnID(newMap); //add new map linking up student and class

                if (SVM.selectedStudent.ID > 0 && newMap_id > 0)
                {
                    result = true;
                }
            }

            ModelState.Clear();
            if (result)
            {
                TempData[Constant.msg_success] = Constant.ChangeSucceed;
            }
            else
            {
                TempData[Constant.msg_error] = Constant.ChangeFailed;
            }
            return(_Student(SVM.selectedClass, SVM.selectedStudent.ID, SVM.selectedTerm));
        }
Esempio n. 2
0
        public ActionResult SaveSubmissions(HomeworkViewModel HVM)
        {
            checkLogin();

            HVM.groupSelectList = (IEnumerable <SelectListItem>)Session["groupSelectList"];
            HVM.typeSelectList  = (IEnumerable <SelectListItem>)Session["typeSelectList"];
            HVM.groupFilList    = (IEnumerable <SelectListItem>)Session["groupFilList"];
            HVM.typeFilList     = (IEnumerable <SelectListItem>)Session["typeFilList"];
            HVM.termFilList     = (IEnumerable <SelectListItem>)Session["termFilList"];

            bool result = true;

            foreach (var s in HVM.submission_list)
            {
                if (result)
                {
                    if (s.submission_id > 0 && !s.contain)
                    {
                        //delete submission record
                        result = false;
                        result = DBS.removeRecord <HOMEWORK_SUBMISSION_LIST>(s.submission_id);
                    }
                    else if (s.submission_id < 1 && s.contain)
                    {
                        s.submit_date = DateTime.Now;//for late ratio cal

                        //add submission record
                        HOMEWORK_SUBMISSION_LIST newList = new HOMEWORK_SUBMISSION_LIST()
                        {
                            HOMEWORK      = s.homework_id,
                            STUDENT       = s.student_id,
                            STUDENT_GROUP = s.group_id,
                            QE_CLASS      = s.QE_class,
                            QE_CLASS_NAME = s.QE_class_name,
                            GROUP_NAME    = s.group_name,
                            STUDENT_NAME  = s.student_name,
                            CLASS_NUM     = s.class_num,
                            REMARK        = s.remark,
                            MARK          = s.mark,
                            ADD_BY        = CP.userID,
                            ADD_DATE      = DateTime.Now,
                            ACTIVE        = true,
                        };

                        result = false;
                        result = DBS.addRecord(newList);
                    }
                    else if (s.submission_id > 0 && s.contain)
                    {
                        // changes other than submission
                        Dictionary <string, string> parms = new Dictionary <string, string>()
                        {
                            { "REMARK", string.IsNullOrEmpty(s.remark) ? string.Empty : s.remark },
                            { "MARK", s.mark.ToString() },
                            { "MODIFY_BY", CP.userID.ToString() },
                            { "MODIFY_DATE", DateTime.Now.ToString() }
                        };

                        result = false;
                        result = DBS.updateRecordByID <HOMEWORK_SUBMISSION_LIST>(parms, s.submission_id);
                    }
                }
            }


            if (result)
            {
                //update ratios
                HOMEWORK work = DBS.findActiveRecordByID <HOMEWORK>(HVM.submission_list.FirstOrDefault().homework_id);
                if (work != null)
                {
                    int studentCount = StudentService.countStudentByGroup(work.STUDENT_GROUP);
                    work.SUBMISSION_RATIO = (decimal)HVM.submission_list.Count(sm => sm.contain == true) / (decimal)studentCount;
                    work.LATE_RATIO       = (decimal)(HVM.submission_list.Count(sm => ((sm.contain == true) && (sm.submit_date > work.DUE_DATE)))) / (decimal)studentCount;
                    work.MODIFY_BY        = CP.userID;
                    work.MODIFY_DATE      = DateTime.Now;
                    result = DBS.updateRecord(work);
                    if (result)
                    {
                        HVM.viewList.Where(h => h.ID == work.ID).First().submission_ratio = work.SUBMISSION_RATIO;
                        HVM.viewList.Where(h => h.ID == work.ID).First().late_ratio       = work.LATE_RATIO;
                    }
                }
            }


            ModelState.Clear();
            TempData["showForm"]  = false;
            TempData["showForm2"] = true;
            if (result)
            {
                TempData[Constant.msg_success] = Constant.ChangeSucceed;
            }
            else
            {
                TempData[Constant.msg_error] = Constant.ChangeFailed;
            }
            return(viewSubmission(HVM, HVM.submission_list.FirstOrDefault().homework_id));
        }
Esempio n. 3
0
        public ActionResult TermPost(TERM next)
        {
            checkLogin();

            TERM previousT = Session["previousT"] != null? (TERM)Session["previousT"]: TermService.GetPreviousTerm();
            TERM currentT  = Session["currentT"] != null ? (TERM)Session["currentT"] : TermService.GetCurrentTerm();
            TERM nextT     = Session["nextT"] != null ? (TERM)Session["nextT"] : TermService.GetNextTerm();

            TermViewModel viewModel = new TermViewModel(previousT, currentT, nextT);

            TempData["showForm"]  = false;
            TempData["resultMsg"] = "";

            // fields checking
            if (!ModelState.IsValid)
            {
                TempData["showForm"] = true;
                return(View("Term", viewModel)); // redirect to form with data
            }
            // logic checking
            bool pass = true;

            if (TermService.GetTermByName(next.TERM_NAME).ID != 0 && TermService.GetTermByName(next.TERM_NAME).ID != next.ID)
            {
                TempData[Constant.msg_error] = "term name already in use";
                pass = false;
            }

            if (pass && next.TERM_START >= next.TERM_END)
            {
                TempData[Constant.msg_error] = "start date > end date";
                pass = false;
            }

            if (pass && next.TERM_START < DateTime.Now.Date)
            {
                TempData[Constant.msg_error] = "start date < today";
                pass = false;
            }

            if (pass && (currentT != null) && currentT.TERM_END >= next.TERM_START)
            {
                TempData[Constant.msg_error] = "current term end date > next term start date";
                pass = false;
            }

            if (!pass)
            {
                TempData["showForm"] = true;
                return(View("Term", viewModel));
            }// redirect to form with data

            next.ACTIVE = true;
            bool isSuccess = false;

            if (next.ID == Constant.DEF_INT)
            {
                isSuccess = DBS.addRecord(next);
            }
            else
            {
                isSuccess = DBS.updateRecord(next);
            }

            // some unkown error happened
            if (!isSuccess)
            {
                TempData[Constant.msg_error] = "Ops! something gone wrong.";
                TempData["showForm"]         = true;
                return(View("Term", viewModel)); // redirect to form with data
            }

            TempData[Constant.msg_success] = ((next.ID == Constant.DEF_INT) ? "New term has been created" : "Next term has been edited");

            //regen lists
            previousT = TermService.GetPreviousTerm();
            currentT  = TermService.GetCurrentTerm();
            nextT     = TermService.GetNextTerm();

            return(View(new TermViewModel(previousT, currentT, nextT))); // success
        }