Example #1
0
 public ActionResult AddNewHomework(HOMEWORK h)
 {
     h.ACTIVE = true;
     db.HOMEWORK.Add(h);
     db.SaveChanges();
     return(View());
 }
Example #2
0
        public static bool UpdateWork(HOMEWORK work)
        {
            work.MODIFY_BY   = ClientSessionService.GetSession.loginedUser.ID;
            work.MODIFY_DATE = DateTime.Now;

            try { return(WillORM.UpdateRecord(work)); }
            catch { return(false); }
        }
Example #3
0
        public ActionResult Homework(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;

            //inactive deleted view item
            foreach (var i in HVM.inactiveList)
            {
                if (result && i > 1)
                {
                    result = false;
                    result = DBS.InactiveRecord("HOMEWORK", i, CP.userID);
                }
            }

            //add new work from new view item
            foreach (var n in HVM.viewList)
            {
                if (result && n.ID < 1)
                {
                    result = false;
                    HOMEWORK newWork = new HOMEWORK()
                    {
                        NAME          = n.name,
                        STUDENT_GROUP = n.group_id,
                        HOMEWORK_TYPE = n.type_id,
                        DUE_DATE      = n.date_due,
                        FULL_MARK     = n.full_mark,
                        ADD_BY        = CP.userID,
                        ADD_DATE      = DateTime.Now,
                        ACTIVE        = true
                    };

                    result = DBS.addRecord(newWork);
                }
            }

            ModelState.Clear();
            TempData["showForm"]  = true;
            TempData["showForm2"] = false;
            if (result)
            {
                TempData[Constant.msg_success] = "Changes have been saved";
            }
            else
            {
                TempData[Constant.msg_error] = "Changes have not been saved";
            }
            return(Homework(HVM.SelectedTerm, HVM.SelectedGroup, HVM.SelectedType, HVM));
        }
Example #4
0
 public HomeworkViewModel()
 {
     newWork         = new HOMEWORK();
     inactiveList    = new List <int>();
     viewList        = new List <HomeworkView>();
     submission_list = new List <Submission_view>();
     SelectedTerm    = 0;
     SelectedGroup   = 0;
     SelectedType    = 0;
 }
Example #5
0
        public ActionResult UpdateHomework(HOMEWORK h)
        {
            var homework = db.HOMEWORK.Find(h.HOMEWORKID);

            homework.CLASSID      = h.CLASSID;
            homework.TEACHERID    = h.TEACHERID;
            homework.HOMEWORKNAME = h.HOMEWORKNAME;
            homework.HOMEWORK1    = h.HOMEWORK1;
            homework.STARTDATE    = h.STARTDATE;
            homework.FINISHDATE   = h.FINISHDATE;
            db.SaveChanges();

            return(Redirect("/Admin/HomeworkList"));
        }
Example #6
0
 public static int AddWork(HOMEWORK newWork)
 {
     try { return(WillORM.InsertRecord(newWork)); }
     catch { return(0); }
 }
Example #7
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));
        }