Exemplo n.º 1
0
        public ActionResult ViewDataOfDatabase(string currentFilter, string searchString, int?page, FormCollection collection, int?Year, int?Month, String City)
        {
            CCIRepository                _repository  = CCIRepository.CreateRepository();
            AirtelManagementModel        _Airtelmodel = new AirtelManagementModel();
            IEnumerable <CityListClass>  CityList     = _repository.GetCities();
            IEnumerable <SelectListItem> CityNames    = from c in CityList
                                                        select new SelectListItem()
            {
                Value    = c.CityName.ToString(),
                Text     = c.CityName.ToString(),
                Selected = c.CityName == Request["CityNames"],
            };

            ViewBag.CityList = CityNames;
            IEnumerable <clsYearOfDate> SelectList = GetYears();
            //IEnumerable<MonthListClass> SelectMonthList = GetMonths(YearId);
            IEnumerable <SelectListItem> Yearitems = (from v in SelectList
                                                      select new SelectListItem()
            {
                Value = v.YearSelectedId.ToString(),
                Text = v.YearOfDate.ToString(),
                Selected = v.YearOfDate == Request["Yearitems"],
            });

            ViewBag.SelectList = Yearitems;
            int    DateId   = 0;
            string CityName = string.Empty;

            //int SelectedYear = Year;
            //int SelectedMonth = Month;
            CityName = City;
            DateId   = _repository.GetImportDateId(Year, Month);
            //ViewBag.SelectedYear = SelectedYear;
            //ViewBag.SelectedMonth = SelectedMonth;
            ViewBag.SelectedCity = CityName;


            //IEnumerable<SelectListItem> MonthItems = (from m in SelectMonthList
            //                                          select new SelectListItem()
            //                                          {
            //                                              Value = m.MonthSelectedId.ToString(),
            //                                              Text = m.MonthName,


            //                                          });
            //ViewBag.SelectMonthList = MonthItems;
            IEnumerable <SelectListItem> MonthItems = Enumerable.Empty <SelectListItem>();

            ViewBag.SelectMonthList = MonthItems;
            List <AirtelManagementModel> list = ViewDetails();

            //ViewBag.CurrentSort = sortorder;

            //ViewBag.PhoneSortParm = String.IsNullOrEmpty(sortorder) ? "Phone_desc" : "";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            //if(searchString!=null)
            //{
            ViewBag.Year          = Year;
            ViewBag.Month         = Month;
            ViewBag.City          = City;
            ViewBag.CurrentFilter = searchString;
            var airteldetails = from _model in list
                                select _model;

            if (!String.IsNullOrEmpty(searchString) && DateId != 0 && !String.IsNullOrEmpty(CityName))
            {
                airteldetails = _repository.FilterAirtelDetails(searchString, DateId, CityName);
                int PageSize   = 5;
                int PageNumber = (page ?? 1);
                return(View(airteldetails.ToPagedList(PageNumber, PageSize)));
            }
            //airteldetails=airteldetails.OrderByDescending(A=>A.AirtelNumber);
            int pageSize   = 5;
            int pageNumber = (page ?? 1);

            //return View(airteldetails.ToList());
            return(View(airteldetails.ToPagedList(pageNumber, pageSize)));
            //}
            //if (list.Count > 0)
            //{
            //    var airteldetails = from _model in list
            //                        select _model;
            //    return View(airteldetails.ToPagedList(pageNumber,pageSize));
            //}
            //else
            //{
            //    ModelState.AddModelError("Error", "No Data found in Database");
            //    return RedirectToAction("ImportExcelFile", "AirtelManagement");
            //}
        }