public ActionResult BranchList(BranchSearchFilter searchFilter) { Logger.Info(_logMsg.Clear().SetPrefixMsg("Search Branch").Add("BranchName", searchFilter.BranchName).ToInputLogString()); try { if (ModelState.IsValid) { _commonFacade = new CommonFacade(); BranchViewModel branchVM = new BranchViewModel(); branchVM.SearchFilter = searchFilter; branchVM.BranchList = _commonFacade.GetBranchList(branchVM.SearchFilter); ViewBag.PageSize = branchVM.SearchFilter.PageSize; ViewBag.PageSizeList = _commonFacade.GetPageSizeList(); return(PartialView("~/Views/Branch/_BranchList.cshtml", branchVM)); } return(Json(new { Valid = false, Error = string.Empty, Errors = GetModelValidationErrors() })); } catch (Exception ex) { Logger.Error("Exception occur:\n", ex); Logger.Info(_logMsg.Clear().SetPrefixMsg("Search Branch").Add("Error Message", ex.Message).ToFailLogString()); return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString()))); } }
public IEnumerable <BranchEntity> GetBranchList(BranchSearchFilter searchFilter) { var ignoreList = searchFilter.Branches.Where(x => x.IsDelete == false).Select(x => x.BranchId); var brList = (from b in _context.TB_R_BRANCH where (string.IsNullOrEmpty(searchFilter.BranchName) || b.BRANCH_NAME.ToUpper().Contains(searchFilter.BranchName.ToUpper())) && !ignoreList.Contains(b.BRANCH_ID) && b.STATUS == Constants.ApplicationStatus.Active select new BranchEntity { BranchId = b.BRANCH_ID, BranchName = b.BRANCH_NAME }).AsQueryable <BranchEntity>(); int startPageIndex = (searchFilter.PageNo - 1) * searchFilter.PageSize; searchFilter.TotalRecords = brList.Count(); if (startPageIndex >= searchFilter.TotalRecords) { startPageIndex = 0; searchFilter.PageNo = 1; } brList = SetBranchListSort(brList, searchFilter); return(brList.Skip(startPageIndex).Take(searchFilter.PageSize).ToList <BranchEntity>()); }
public IEnumerable <BranchEntity> GetBranchList(BranchSearchFilter searchFilter) { _commonDataAccess = new CommonDataAccess(_context); return(_commonDataAccess.GetBranchList(searchFilter)); }
private static IQueryable <BranchEntity> SetBranchListSort(IQueryable <BranchEntity> brList, BranchSearchFilter searchFilter) { if (searchFilter.SortOrder.ToUpper(CultureInfo.InvariantCulture).Equals("ASC")) { switch (searchFilter.SortField.ToUpper(CultureInfo.InvariantCulture)) { case "BRANCHNAME": return(brList.OrderBy(ord => ord.BranchName)); default: return(brList.OrderBy(ord => ord.BranchId)); } } else { switch (searchFilter.SortField.ToUpper(CultureInfo.InvariantCulture)) { case "BRANCHNAME": return(brList.OrderByDescending(ord => ord.BranchName)); default: return(brList.OrderByDescending(ord => ord.BranchId)); } } }