コード例 #1
0
        public IActionResult ViewContract()
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }

            CentricsContext context          = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
            List <Contract> contractlist     = context.getContracts();
            List <Contract> ValidContract    = new List <Contract>();
            List <Contract> ExpiredContract  = new List <Contract>();
            List <Contract> FutureContract   = new List <Contract>();
            List <Contract> FinishedContract = new List <Contract>();
            int             counter          = contractlist.Count();
            int             i = 0;

            while (counter != 0)
            {
                if (contractlist[i].EndValid.CompareTo(DateTime.Today) >= 0 && (contractlist[i].StartValid.CompareTo(DateTime.Today)) <= 0)
                {
                    if (contractlist[i].MSH != 0)
                    {
                        ValidContract.Add(contractlist[i]);
                    }
                    else
                    {
                        FinishedContract.Add(contractlist[i]);
                    }
                }
                else if (contractlist[i].EndValid.CompareTo(DateTime.Today) < 0)
                {
                    ExpiredContract.Add(contractlist[i]);
                }
                else if (contractlist[i].StartValid.CompareTo(DateTime.Today) > 0)
                {
                    FutureContract.Add(contractlist[i]);
                }
                i++;
                counter--;
            }
            if (FinishedContract.Count != 0)
            {
                ViewData["Finished"] = FinishedContract;
            }
            if (ExpiredContract.Count != 0)
            {
                ViewData["Expired"] = ExpiredContract;
            }
            if (ValidContract.Count != 0)
            {
                ViewData["Valid"] = ValidContract;
            }
            if (FutureContract.Count != 0)
            {
                ViewData["Future"] = FutureContract;
            }
            return(View());
        }