private IQueryable <BranchDto> GetBranch(BranchSearchModel searchModel = null)
        {
            IQueryable <BranchDto> list = null;

            if (searchModel.IsNull())
            {
                list = _branchService.GetAll();
            }
            else
            {
                if (!searchModel.BranchName.IsNull())
                {
                    list = _branchService.GetAll().Where(b => b.BranchName.Contains(searchModel.BranchName));
                }
                else
                {
                    list = _branchService.GetAll();
                }
            }

            return(list);
        }
        public virtual ActionResult GetBranches([DataSourceRequest] DataSourceRequest request, BranchSearchModel searchModel)
        {
            var list = GetBranch(searchModel);

            return(Json(list.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public async Task <BranchListModel> GetByPaging(BranchSearchModel request)
        {
            try
            {
                var start = 1;

                if (request != null)
                {
                    start = request.Start / request.Length + 1;
                }

                var columnOrder = "name";
                var sortDir     = "ASC";

                var url = string.Format(ApiUrl.BRANCH_PAGING,
                                        request.Name,
                                        request.HotLine,
                                        request.ProvinceId,
                                        request.DistrictId,
                                        request.DistrictId,
                                        request.ColumnOrder,
                                        start,
                                        request?.Length ?? 10,
                                        columnOrder,
                                        sortDir);

                var response = await HttpService.Send <PageResult <GetBranchPagingResponse> >(url,
                                                                                              null,
                                                                                              HttpMethod.Get,
                                                                                              true);

                if (response.IsSuccess)
                {
                    return new BranchListModel
                           {
                               Draw            = request.Draw,
                               RecordsFiltered = response.Data.TotalCount,
                               Total           = response.Data.TotalCount,
                               RecordsTotal    = response.Data.TotalCount,
                               Data            = response.Data.Data.Select(c => new Models.Branch.BranchModel
                        {
                            Id              = c.Id,
                            Name            = c.Name,
                            Address         = c.Address,
                            PageSize        = request.PageSize,
                            District        = c.District,
                            Hotline         = c.Hotline,
                            Province        = c.Province,
                            Ward            = c.Ward,
                            PageSizeOptions = request.AvailablePageSizes
                        })
                           }
                }
                ;

                throw new PeloException(response.Message);
            }
            catch (Exception exception)
            {
                throw new PeloException(exception.Message);
            }
        }