コード例 #1
0
        public IActionResult AdmissionPay(int?ID, string name, int?standard)
        {
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Session1")))
            {
                return(RedirectToAction("UserLogin", "Login"));
            }
            TempData["StdId"] = new SelectList(_Standard.GetAll().ToList(), "StdId", "Stname");
            var res = _admission.GetAll();


            if (ID != null && name != null && standard != null)
            {
                res = from k in res
                      where k.AdId == ID && k.St.StName.Equals(name) && k.StdId == standard
                      select k;
                //res = res.Where(d => d.AdId == ID).Where(d => d.St.Name.Equals(name)).Where(d => d.StdId == standard);
            }
            else if (ID > 0 && name != null)
            {
                res = from k in res
                      where k.AdId == ID && k.St.StName.Equals(name)
                      select k;
            }
            else if (ID > 0)
            {
                res = from k in res
                      where k.AdId == ID
                      select k;
            }
            else if (ID > 0 && standard != null)
            {
                res = from k in res
                      where k.AdId == ID && k.StdId == standard
                      select k;
            }
            else if (name != null)
            {
                res = from k in res
                      where k.St.StName.Equals(name)
                      select k;
            }
            else if (standard != null)
            {
                res = from k in res
                      where k.StdId == standard
                      select k;
            }
            else
            {
                res = from k in res
                      where k.AdId != ID && !k.St.StName.Equals(name) && k.StdId != standard
                      select k;
            }
            ViewBag.ID        = ID;
            TempData["StdId"] = new SelectList(_Standard.GetAll().ToList(), "StdId", "Stname", standard);

            /*
             *  if(ID!=null)
             *  {
             *  res=    res.Where(k => k.AdId == ID);
             *      ViewBag.ID = ID;
             *  }
             *  if(name!=null)
             *  {
             *    var st_data= StudentRepository.GetAll();
             *      res =
             * from k in st_data
             * join k1 in res on k.StId equals k1.StId
             * where k.StName.Contains(name )
             * select k1;
             *  }
             *  if(standard!=null)
             *  {
             *      res = res.Where(k => k.StdId == standard);
             *      TempData["StdId"] = new SelectList(_Standard.GetAll().ToList(), "StdId", "Stname",standard);
             *  }*/
            foreach (var item in res)
            {
                ICollection <Admissiopay> admissiopays = _admissionPay.GetAll();
                var   res1  = admissiopays.Where(d => d.AdId == item.AdId);
                AdPay adPay = new AdPay();
                adPay.Admission1      = item;
                adPay.ListAdmissiopay = res1;
                p.Add(adPay);
            }
            ViewBag.name = name;
            return(View(p));
            //List<Admissiopay> x = new List<Admissiopay>();
            // foreach (var item in adm)
            // {
            //  var res1= _admissionPay.GetByAdmissionId(item.AdId);
            //     foreach (var item2 in res1)
            //     {
            //         x.Add(item2);
            //     }
            // }

            // p.ListAdmissiopay = x;
            //IEnumerable<Admissiopay> listpay= _admissionPay.GetAll();
            // p.ListAdmissiopay = listpay;
            // return View(p);
        }