Exemplo n.º 1
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));
        }