コード例 #1
0
        public ElectionStatus Choosen(long Student_id, int Peresentedc_id)
        {
            var  result                = ElectionStatus.Success;
            var  term_name             = _SiteOption.ToList().Where(op => op.Name.Equals("Term_Name")).FirstOrDefault().Value;
            var  max_unit              = _SiteOption.ToList().Where(op => op.Name.Equals("Student_max_Unit")).FirstOrDefault().Value;
            Term thTerm                = _Term.Where(x => x.Name == term_name).FirstOrDefault();
            PeresentedCourses peresent = _PeresentedCourses.Where(x => x.Id == Peresentedc_id).FirstOrDefault();
            Election          election = _Election.Where(x => x.Student.Id == Student_id && x.PeresentedCource.Id == Peresentedc_id).FirstOrDefault();

            List <Election> maxstuselected = _Election.Where(x => x.Student.Id == Student_id && x.PeresentedCource.Term.Name == term_name).ToList();

            int ii = 0;

            foreach (var item in maxstuselected)
            {
                ii += Convert.ToInt32(item.PeresentedCource.Course.Unit);
            }
            ii += peresent.Course.Unit;

            if (election != null)
            {
                result = ElectionStatus.CannotSelectPrevSelected;
            }
            if (ii > int.Parse(max_unit))
            {
                result = ElectionStatus.CannotSelectOutOfUnit;
            }
            if ((peresent.Remain_Capacity - 1) < 0)
            {
                result = ElectionStatus.CannotSelectCapacityFull;
            }

            return(result);
        }
コード例 #2
0
        public async Task <ActionResult> SelectRemoveCource(int?id)
        {
            if (id == null)
            {
                return(Content(null));
            }
            string               resultmsg = id.Value.ToString();
            Election             ele       = _ElectionService.GetById(id.Value);
            PeresentedCourses    pc        = _PeresentedCoursesService.GetById(ele.PeresentedCource.Id);
            ElectionRemoveStatus status    = _ElectionService.Remove(ele.Id);

            switch (status)
            {
            case ElectionRemoveStatus.Success:
            {
                _ElectionService.Delete(id.Value);

                _PeresentedCoursesService.Increase_Capacity_Remained(pc.Id);
                await _unitOfWork.SaveAllChangesAsync(false);

                resultmsg = "Success Remove";
            }
            break;

            case ElectionRemoveStatus.CannotRemoveScored:
                resultmsg = "Cannot Remove Beacuse This Cource has Scored";
                break;
            }

            await _unitOfWork.SaveChangesAsync();

            CacheManager.InvalidateChildActionsCache();
            return(Json(new { msg = resultmsg }, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public virtual async Task <ActionResult> Create(AddPeresentedCoursesViewModel viewModel)
        {
            var adv = new PeresentedCourses
            {
                Course          = _CourseService.GetById(viewModel.Course_Id.Value),
                Professor       = _ProfessorService.GetById(viewModel.Professor_Id.Value),
                Term            = _TermService.GetById(viewModel.Term_Id.Value),
                Capacity        = viewModel.Capacity,
                Remain_Capacity = viewModel.Capacity
            };

            _PeresentedCoursesService.Insert(adv);
            await _unitOfWork.SaveChangesAsync();

            CacheManager.InvalidateChildActionsCache();


            PopulateCourcesDropDownList(null);
            PopulateProfessorDropDownList(null);
            PopulateTermDropDownList(null);

            return(RedirectToAction("Index", "AvailableCourses"));

            return(View(viewModel));
        }
コード例 #4
0
        public async Task <ActionResult> SelectElectionCource(int?id)
        {
            if (id == null)
            {
                return(Content(null));
            }
            string            resultmsg = id.Value.ToString();
            string            userName  = HttpContext.User.Identity.Name;
            Term              term      = _SettingService.GetOptionsForEdit().Term;
            Student           stu       = _StudentService.GetByUserId(_UserService.GetUserByUserName(userName).Id);
            PeresentedCourses pc        = _PeresentedCoursesService.GetById(id.Value);

            ElectionStatus status = _ElectionService.Choosen(stu.Id, pc.Id);

            switch (status)
            {
            case ElectionStatus.Success:
            {
                var adv = new Election
                {
                    Student          = _StudentService.GetById(stu.Id),
                    PeresentedCource = pc
                };
                _ElectionService.Insert(adv);

                _PeresentedCoursesService.Decrease_Capacity_Remained(pc.Id);
                await _unitOfWork.SaveAllChangesAsync(false);

                resultmsg = "Success";
            }
            break;

            case ElectionStatus.CannotSelectCapacityFull:
                resultmsg = "Cannot Select Beacuse Capacity of Class is Full";
                break;

            case ElectionStatus.CannotSelectOutOfUnit:
                resultmsg = "Cannot Select Beacuse Out Of Your Max Unit Allowed";
                break;

            case ElectionStatus.CannotSelectPrevSelected:
                resultmsg = "Cannot Select Beacuse You Pereviouse Choose This Class";
                break;
            }

            await _unitOfWork.SaveChangesAsync();

            CacheManager.InvalidateChildActionsCache();
            return(Json(new { msg = resultmsg }, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
 public void Insert(PeresentedCourses article)
 {
     _PeresentedCources.Add(article);
 }