public ActionResult ProcessContract(CourseContractQueryViewModel viewModel)
        {
            if (viewModel.KeyID != null)
            {
                viewModel.ContractID = viewModel.DecryptKeyValue();
            }

            var item = models.GetTable <CourseContract>().Where(c => c.ContractID == viewModel.ContractID).FirstOrDefault();

            if (item == null)
            {
                return(View("~/Views/ConsoleHome/Shared/AlertMessage.cshtml", model: "合約資料錯誤!!"));
            }

            return(View("~/Views/ContractConsole/ContractModal/ProcessContract.cshtml", item));
        }
        // GET: ContractConsole
        public async Task <ActionResult> ShowContractListAsync(CourseContractQueryViewModel viewModel, bool?popupModal)
        {
            if (viewModel.KeyID != null)
            {
                viewModel.ContractID = viewModel.DecryptKeyValue();
            }

            ViewResult result = (ViewResult) await InquireContractAsync(viewModel);

            ViewBag.Contracts = result.Model;

            var profile = await HttpContext.GetUserAsync();

            if (popupModal == true)
            {
                return(View("~/Views/ConsoleHome/CourseContract/ContractListModal.cshtml", profile.LoadInstance(models)));
            }
            else
            {
                return(View("~/Views/ConsoleHome/ContractIndex.cshtml", profile.LoadInstance(models)));
            }
        }
Exemplo n.º 3
0
        public static async Task <IQueryable <CourseContract> > InquireContractByCustomAsync(this CourseContractQueryViewModel viewModel, SampleController <UserProfile> controller)

        {
            var ModelState  = controller.ModelState;
            var ViewBag     = controller.ViewBag;
            var HttpContext = controller.HttpContext;
            var models      = controller.DataSource;

            ViewBag.ViewModel = viewModel;
            var profile = await HttpContext.GetUserAsync();

            bool hasConditon = false;

            IQueryable <CourseContract> items;

            if (viewModel.ContractQueryMode == Naming.ContractServiceMode.ContractOnly)
            {
                items = models.PromptContract();
            }
            else if (viewModel.ContractQueryMode == Naming.ContractServiceMode.ServiceOnly)
            {
                items = models.PromptContractService();
            }
            else
            {
                items = models.GetTable <CourseContract>();
            }

            if (viewModel.KeyID != null)
            {
                viewModel.ContractID = viewModel.DecryptKeyValue();
            }
            if (viewModel.ContractID.HasValue)
            {
                items = items.Where(c => c.ContractID == viewModel.ContractID);
            }

            if (viewModel.ContractDateFrom.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.ContractDate >= viewModel.ContractDateFrom);
            }

            if (viewModel.ContractDateTo.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.ContractDate < viewModel.ContractDateTo.Value);
            }

            if (viewModel.EffectiveDateFrom.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.EffectiveDate >= viewModel.EffectiveDateFrom);
            }

            if (viewModel.EffectiveDateTo.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.EffectiveDate < viewModel.EffectiveDateTo);
            }

            Expression <Func <CourseContract, bool> > queryExpr = c => false;
            bool subCondition = false;

            viewModel.CustomQuery = viewModel.CustomQuery.GetEfficientString();
            viewModel.ContractNo  = viewModel.ContractNo.GetEfficientString();
            viewModel.RealName    = viewModel.RealName.GetEfficientString();
            if (viewModel.CustomQuery != null)
            {
                if (viewModel.ContractNo == null)
                {
                    viewModel.ContractNo = viewModel.CustomQuery;
                }
                if (viewModel.RealName == null)
                {
                    viewModel.RealName = viewModel.CustomQuery;
                }
            }

            if (viewModel.ContractNo != null)
            {
                subCondition = true;
                var no = viewModel.ContractNo.Split('-');
                if (no.Length > 1)
                {
                    int.TryParse(no[1], out int seqNo);
                    queryExpr = queryExpr.Or(c => c.ContractNo.StartsWith(no[0]) &&
                                             c.SequenceNo == seqNo);
                }
                else
                {
                    queryExpr = queryExpr.Or(c => c.ContractNo.StartsWith(viewModel.ContractNo));
                }
            }

            if (viewModel.RealName != null)
            {
                subCondition = true;
                queryExpr    = queryExpr.Or(c => c.CourseContractMember.Any(m => m.UserProfile.RealName.Contains(viewModel.RealName) || m.UserProfile.Nickname.Contains(viewModel.RealName)));
            }

            if (hasConditon)
            {
                if (subCondition)
                {
                    items = items.Where(queryExpr);
                }
                else
                {
                    if (viewModel.FitnessConsultant.HasValue)
                    {
                        hasConditon = true;
                        items       = items.Where(c => c.FitnessConsultant == viewModel.FitnessConsultant);
                    }

                    if (viewModel.ManagerID.HasValue)
                    {
                        hasConditon = true;
                        items       = items.FilterByBranchStoreManager(models, viewModel.ManagerID);
                    }

                    if (viewModel.OfficerID.HasValue)
                    {
                        hasConditon = true;
                    }
                }
            }
            else
            {
                if (subCondition)
                {
                    items = items.Where(queryExpr);
                }
                else
                {
                    //items = items.Where(c => false);
                    //return Json(new { result = false, message = "請設定查詢條件!!" });
                    ModelState.AddModelError("RealName", "請輸入查詢學生姓名(暱稱)!!");
                    ModelState.AddModelError("ContractNo", "請輸入查詢合約編號!!");
                    ModelState.AddModelError("ContractDateFrom", "請輸入查詢合約起日!!");
                    ModelState.AddModelError("ContractDateTo", "請輸入查詢合約迄日!!");
                    ViewBag.ModelState = ModelState;
                    return(null);
                }
            }

            return(items);
        }
Exemplo n.º 4
0
        public static IQueryable <CourseContract> InquireContract(this CourseContractQueryViewModel viewModel, GenericManager <BFDataContext> models)

        {
            bool hasConditon = false;

            IQueryable <CourseContract> items;

            if (viewModel.ContractQueryMode == Naming.ContractServiceMode.ContractOnly)
            {
                if (viewModel.Status >= (int)Naming.CourseContractStatus.已生效)
                {
                    items = models.PromptOriginalContract();
                }
                else if (viewModel.PayoffMode.HasValue)
                {
                    items = models.PromptAccountingContract();
                }
                else
                {
                    items = models.PromptContract();
                }
            }
            else if (viewModel.ContractQueryMode == Naming.ContractServiceMode.ServiceOnly)
            {
                items = models.PromptContractService();
            }
            else
            {
                items = models.GetTable <CourseContract>();
            }

            if (viewModel.ContractID.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.ContractID == viewModel.ContractID);
            }

            if (viewModel.PayoffMode == Naming.ContractPayoffMode.Unpaid)
            {
                hasConditon = true;
                items       = items
                              .FilterByToPay(models);
            }
            else if (viewModel.PayoffMode == Naming.ContractPayoffMode.Paid)
            {
                hasConditon = true;
                items       = items.Where(c => c.ContractPayment.Any());
            }

            if (viewModel.IncludeTotalUnpaid == true)
            {
                Expression <Func <CourseContract, bool> > expr        = c => true;
                Expression <Func <CourseContract, bool> > defaultExpr = expr;
                if (viewModel.PayoffDueFrom.HasValue)
                {
                    hasConditon = true;
                    expr        = expr.And(c => c.PayoffDue >= viewModel.PayoffDueFrom);
                }

                if (viewModel.PayoffDueTo.HasValue)
                {
                    hasConditon = true;
                    expr        = expr.And(c => c.PayoffDue < viewModel.PayoffDueTo);
                }

                if (defaultExpr != expr)
                {
                    expr  = expr.Or(c => !c.PayoffDue.HasValue);
                    items = items.Where(expr);
                }
            }
            else
            {
                if (viewModel.PayoffDueFrom.HasValue)
                {
                    hasConditon = true;
                    items       = items.Where(c => c.PayoffDue >= viewModel.PayoffDueFrom);
                }

                if (viewModel.PayoffDueTo.HasValue)
                {
                    hasConditon = true;
                    items       = items.Where(c => c.PayoffDue < viewModel.PayoffDueTo);
                }
            }

            if (viewModel.Status.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.Status == viewModel.Status);
            }

            if (viewModel.FitnessConsultant.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.FitnessConsultant == viewModel.FitnessConsultant);
            }

            if (viewModel.ManagerID.HasValue)
            {
                hasConditon = true;
                items       = items.FilterByBranchStoreManager(models, viewModel.ManagerID);
            }
            else if (viewModel.ViceManagerID.HasValue)
            {
                hasConditon = true;
                items       = items.FilterByBranchStoreManager(models, viewModel.ManagerID)
                              .Where(c => c.AgentID != viewModel.ViceManagerID);
            }


            if (viewModel.OfficerID.HasValue)
            {
                hasConditon = true;
            }

            if (viewModel.IsExpired == true)
            {
                hasConditon = true;
                items       = items.FilterByExpired(models);
            }
            else if (viewModel.IsExpired == false)
            {
                hasConditon = true;
                items       = items.Where(c => c.Expiration >= DateTime.Today);
            }

            if (viewModel.EffectiveDateFrom.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.EffectiveDate >= viewModel.EffectiveDateFrom);
            }

            if (viewModel.EffectiveDateTo.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.EffectiveDate < viewModel.EffectiveDateTo);
            }

            if (viewModel.ExpirationFrom.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.Expiration >= viewModel.ExpirationFrom);
            }

            if (viewModel.ExpirationTo.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.Expiration < viewModel.ExpirationTo.Value);
            }

            if (viewModel.KeyID != null)
            {
                viewModel.ContractID = viewModel.DecryptKeyValue();
            }
            if (viewModel.ContractID.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.ContractID == viewModel.ContractID);
            }

            if (viewModel.AlarmCount.HasValue)
            {
                hasConditon = true;
                items       = items.FilterByAlarmedContract(models, viewModel.AlarmCount.Value);
            }

            if (viewModel.InstallmentID.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.InstallmentID == viewModel.InstallmentID);
            }

            if (viewModel.UnpaidExpiring == true)
            {
                hasConditon = true;
                items       = items.FilterByUnpaidContract(models)
                              .Where(p => p.PayoffDue < DateTime.Today);
            }

            if (viewModel.Unpaid == true)
            {
                hasConditon = true;
                items       = items.FilterByUnpaidContract(models);
            }

            if (viewModel.MemberID.HasValue)
            {
                hasConditon = true;
                items       = items.Where(c => c.CourseContractMember.Any(m => m.UID == viewModel.MemberID));
            }

            viewModel.Subject = viewModel.Subject.GetEfficientString();
            if (viewModel.Subject != null)
            {
                items = items.Where(c => c.Subject == viewModel.Subject);
            }

            if (hasConditon)
            {
            }
            else
            {
                items = items.Where(c => false);
            }

            //if (viewModel.ContractType.HasValue)
            //    items = items.Where(c => c.ContractType == viewModel.ContractType);
            return(items);
        }