//passing an entire URI to the server endpoint
        public async Task <PagingResponse <Region> > GetAll(EntityParameters entityParameters)
        {
            var queryStringParam = new Dictionary <string, string>
            {
                ["pageNumber"] = entityParameters.PageNumber.ToString()
            };

            var response = await _client.GetAsync(QueryHelpers.AddQueryString("https://localhost:5021/api/regions", queryStringParam));

            var content = await response.Content.ReadAsStringAsync();

            if (!response.IsSuccessStatusCode)
            {
                throw new ApplicationException(content);
            }

            var pagingResponse = new PagingResponse <Region>
            {
                Items = JsonSerializer.Deserialize <List <Region> >(content, new JsonSerializerOptions {
                    PropertyNameCaseInsensitive = true
                }),
                MetaData = JsonSerializer.Deserialize <MetaData>(response.Headers.GetValues("X-Pagination").First(), new JsonSerializerOptions {
                    PropertyNameCaseInsensitive = true
                })
            };

            return(pagingResponse);
        }
Esempio n. 2
0
        public async Task <PagingResponse <PersonTypeDto> > GetPersonTypesAsync(PersonTypeParametersDto personTypeParameters)
        {
            var queryStringParam = new Dictionary <string, string>
            {
                ["pageNumber"] = personTypeParameters.PageNumber.ToString(),
                ["pageSize"]   = personTypeParameters.PageSize.ToString(),
                ["sortOrder"]  = personTypeParameters.SortOrder.ToString(),
                ["filters"]    = String.IsNullOrEmpty(personTypeParameters.Filters) ? "" : $"Name @=* {personTypeParameters.Filters}"
            };

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync(QueryHelpers.AddQueryString(uri.ToString(), queryStringParam)))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();

                        var pagingResponse = new PagingResponse <PersonTypeDto>
                        {
                            Items    = JsonConvert.DeserializeObject <PageListPersonType>(content).PersonTypes,
                            Metadata = JsonConvert.DeserializeObject <MetaData>(response.Headers.GetValues("x-pagination").First())
                        };

                        pagingResponse.Filters   = personTypeParameters.Filters;
                        pagingResponse.SortOrder = personTypeParameters.SortOrder;
                        return(pagingResponse);
                    }
                    return(null);
                }
            }
        }
Esempio n. 3
0
        public PagingResponse <LeadMusicLog> GetMusicLogByAction(LogType action, DateTime start, DateTime end, PagingRequest pageReq)
        {
            var res = new PagingResponse <LeadMusicLog>(pageReq);

            res.Success = true;
            try
            {
                RepositoryPagingResponse <LeadMusicLog> dbRes = new RepositoryPagingResponse <LeadMusicLog>();
                switch (action)
                {
                case LogType.Purchase:
                    dbRes = _purchRep.GetMusicsPurchase(start, end, (pageReq.Page - 1) * pageReq.ResultInPage, pageReq.ResultInPage);
                    break;

                case LogType.MusicView:
                    dbRes = _rep.GetMusicLogByAction(LogActionType.Watch, start, end, (pageReq.Page - 1) * pageReq.ResultInPage, pageReq.ResultInPage);
                    break;

                default:
                    res.Success = false;
                    res.Message = string.Format("Action - {0}, not supported for GetMusicLogByAction method", action.ToString());
                    break;
                }
                res.TotalResults = dbRes.TotalResults;
                res.Entities     = dbRes.Entities;
                res.Success      = true;
            }
            catch (Exception e)
            {
                res.Success = false;
                res.Message = e.ToString();
            }
            return(res);
        }
Esempio n. 4
0
        public PagingResponse <Music> GetByArtistId(string artistId, SearchSortType sortType, PagingRequest pageRequest)
        {
            var res = new PagingResponse <Music>();

            try
            {
                RepositoryPagingResponse <Music> repositoryRes = (this._rep as IMusicsRepository).
                                                                 GetByArtistId(artistId,
                                                                               pageRequest.ResultInPage,
                                                                               (pageRequest.Page - 1) * pageRequest.ResultInPage,
                                                                               sortType);
                res.Entities      = repositoryRes.Entities;
                res.CurrPage      = pageRequest.Page;
                res.ResultsInPage = pageRequest.ResultInPage;
                res.TotalResults  = repositoryRes.TotalResults;

                res.Success = true;
            }
            catch (Exception e)
            {
                res.Success = false;
                res.Message = "אירעה שגיאה בחיפוש היצירות";
            }

            return(res);
        }
Esempio n. 5
0
        public PagingResponse <Music> GetBySearch(
            string searchMusicText,
            string searchArtistText,
            PagingRequest pageRequest,
            MusicFieldsSort sortField = MusicFieldsSort.UpdateDate,
            bool sortDesc             = true)
        {
            PagingResponse <Music> res = new PagingResponse <Music>();

            try
            {
                var repositoryRes = (this._rep as IMusicsRepository).
                                    GetBySearch(searchMusicText,
                                                searchArtistText,
                                                pageRequest.ResultInPage,
                                                (pageRequest.Page - 1) * pageRequest.ResultInPage,
                                                sortField,
                                                sortDesc);

                res.Entities      = repositoryRes.Entities;
                res.TotalResults  = repositoryRes.TotalResults;
                res.ResultsInPage = pageRequest.ResultInPage;
                res.CurrPage      = pageRequest.Page;
                res.Success       = true;
            }
            catch (Exception e)
            {
                res.Success = false;
                res.Message = e.ToString();
            }

            return(res);
        }
Esempio n. 6
0
        //Paging
        public async Task <PagingResponse <Audit> > GetAudits(RequestParams requestParams, int customerId)
        {
            var queryStringParam = new Dictionary <string, string>
            {
                //["totalCount"] = requestParams.TotalCount.ToString(),
                ["pageNumber"] = requestParams.PageNumber.ToString(),
                //["currentPage"] = requestParams.CurrentPage.ToString(),
                ["pageSize"]   = requestParams.PageSize.ToString(),
                ["searchTerm"] = requestParams.SearchTerm == null ? "" : requestParams.SearchTerm,
                ["orderBy"]    = requestParams.OrderBy == null ? "" : requestParams.OrderBy
            };


            //$"customer?pageNumber={requestParams.PageNumber}"
            var response = await _client.GetAsync(QueryHelpers.AddQueryString("Audit", queryStringParam) + "&customerId=" + customerId.ToString());

            var content = await response.Content.ReadAsStringAsync();

            var pagingResponse = new PagingResponse <Audit>
            {
                Items    = JsonSerializer.Deserialize <List <Audit> >(content, _options),
                MetaData = JsonSerializer.Deserialize <MetaData>(
                    response.Headers.GetValues("X-Pagination").First(), _options)
            };

            return(pagingResponse);
        }
Esempio n. 7
0
        public ActionResult MusicByArtistId(string Id, int page = 1, SearchSortType sortType = SearchSortType.LengthDesc)
        {
            MusicSearchResult musicRes = new MusicSearchResult();

            PagingResponse <Music> res = _mscService.GetByArtistId(Id, sortType, new PagingRequest(page, RESULTS_IN_PAGE));

            if (res.Success)
            {
                var user = User.GetUser();
                ICollection <Music> favouriteMusic = new List <Music>();
                if (user?.FavouriteMusics != null)
                {
                    favouriteMusic = user.FavouriteMusics;
                }
                musicRes.TotalPages   = res.TotalPages;
                musicRes.TotalResults = res.TotalResults;
                musicRes.Musics       = res.Entities.Select(msc => new MusicSearchModel(msc, favouriteMusic.Any(fav => fav.ID == msc.ID)));
            }
            else
            {
                return(new HttpStatusCodeResult(500, res.Message));
            }

            return(Json(musicRes));
        }
        public async Task <PagingResponse <VehiclePriceListItem> > GetAllPaging(PagingRequest paging)
        {
            var pagingResponse = new PagingResponse <VehiclePriceListItem>();


            IQueryable <VehiclePriceListItem> query = null;

            query = VehiclesPriceListAppContext.VehiclePriceListItem.BuildVehiclePriceListItem();



            if (paging.Filter != null)
            {
                query = query.BuildFilteredOptions(paging.Filter as FilterVehiclesPriceList);
            }

            var totalItems = query.Count();

            //for sorting on server side
            //var colOrder = paging.sortOrder;
            //query = colOrder == "asc" ? query.OrderBy(vpli => vpli.AskingPrice) : query.OrderByDescending(emp => emp.AskingPrice);

            //See sql statement from entity query
            //var sql = query.ToSql();


            var vehiclePriceList = await query.Skip((paging.pageNumber) *paging.pageSize).Take(paging.pageSize).ToArrayAsync();

            pagingResponse.Items      = vehiclePriceList;
            pagingResponse.TotalItems = totalItems;
            pagingResponse.PageSize   = paging.pageSize;
            pagingResponse.Page       = paging.pageNumber;

            return(pagingResponse);
        }
        public IActionResult GetEmployee([FromBody] PagingRequest paging)
        {
            var pagingResponse = new PagingResponse()
            {
                Draw = paging.Draw
            };


            IQueryable <EmployeeModel> query = null;

            if (!string.IsNullOrEmpty(paging.SearchCriteria.Filter))
            {
                query = _employeeService.GetAll().Where(emp => emp.EmployeeName.Contains(paging.SearchCriteria.Filter)).AsQueryable();
            }
            else if (!string.IsNullOrEmpty(paging.Search.Value))
            {
                query = _employeeService.GetAll().Where(emp => emp.EmployeeName.Contains(paging.Search.Value) || emp.Position.Contains(paging.Search.Value) ||
                                                        emp.Office.Contains(paging.Search.Value) || emp.Salary.ToString().Contains(paging.Search.Value)
                                                        ).AsQueryable();
            }
            else
            {
                query = _employeeService.GetAll().AsQueryable();
            }
            var recordsTotal = query.Count();
            var colOrder     = paging.Order[0];

            switch (colOrder.Column)
            {
            case 0:
                query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.EmployeeName) : query.OrderByDescending(emp => emp.EmployeeName);
                break;

            case 1:
                query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.EmployeeName) : query.OrderByDescending(emp => emp.EmployeeName);
                break;

            case 2:
                query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.Position) : query.OrderByDescending(emp => emp.Position);
                break;

            case 3:
                query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.Office) : query.OrderByDescending(emp => emp.Office);
                break;

            case 4:
                query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.Age) : query.OrderByDescending(emp => emp.Age);
                break;

            case 5:
                query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.Salary) : query.OrderByDescending(emp => emp.Salary);
                break;
            }

            pagingResponse.data            = query.Skip(paging.Start).Take(paging.Length).ToArray();
            pagingResponse.RecordsTotal    = recordsTotal;
            pagingResponse.RecordsFiltered = recordsTotal;

            return(Ok(pagingResponse));
        }
Esempio n. 10
0
        public async Task <IPagingResponse <Warehouse> > GetWarehousesAsync(Int32 pageSize = 10, Int32 pageNumber = 1)
        {
            Logger?.LogInformation("{0} has been invoked", nameof(GetWarehousesAsync));

            var response = new PagingResponse <Warehouse>();

            try
            {
                // Get query
                var query = ProductionRepository.GetWarehouses();

                // Set information for paging
                response.PageSize   = (Int32)pageSize;
                response.PageNumber = (Int32)pageNumber;
                response.ItemsCount = await query.CountAsync();

                // Retrieve items, set model for response
                response.Model = await query.Paging(pageSize, pageNumber).ToListAsync();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
Esempio n. 11
0
        public ActionResult Search(string searchText, string strTagIds, int page = 1, SearchSortType sortType = SearchSortType.Relevant)
        {
            MusicSearchResult musicRes = new MusicSearchResult();

            if (!string.IsNullOrWhiteSpace(searchText) || !string.IsNullOrWhiteSpace(strTagIds))
            {
                var tagIds = strTagIds
                             .Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                             .Select(id => Guid.Parse(id));
                PagingResponse <Music> res =
                    _mscService.GetBySearch(searchText, tagIds, new PagingRequest(page, RESULTS_IN_PAGE), sortType);

                if (res.Success)
                {
                    var user = User.GetUser();
                    ICollection <Music> favouriteMusic = new List <Music>();
                    if (user?.FavouriteMusics != null)
                    {
                        favouriteMusic = user.FavouriteMusics;
                    }
                    musicRes.TotalPages   = res.TotalPages;
                    musicRes.TotalResults = res.TotalResults;
                    musicRes.Musics       = res.Entities.Select(msc => new MusicSearchModel(msc, favouriteMusic.Any(fav => fav.ID == msc.ID)));
                }
                else
                {
                    return(new HttpStatusCodeResult(500, res.Message));
                }
            }

            return(Json(musicRes));
        }
Esempio n. 12
0
        public static PagingResponse <T> MapToDataTable <T>(this IQueryable <T> query, PagingRequest paging) where T : class
        {
            var pagingResponse = new PagingResponse <T>()
            {
                Draw = paging.Draw
            };

            if (!paging.SearchCriteria.IsPageLoad)
            {
                if (!string.IsNullOrEmpty(paging.SearchCriteria.Filter))
                {
                    query = query.Search(paging.SearchCriteria.Filter);
                }
                var recordsTotal = query.Count();
                if (paging.Order != null)
                {
                    string sortBy  = paging.Columns[paging.Order[0].Column].Data;
                    string sortDir = paging.Order[0].Dir.ToLower();
                    query = query.OrderBy($"{sortBy} {sortDir}");
                }
                pagingResponse.Data            = query.Skip(paging.Start).Take(paging.Length).ToList();
                pagingResponse.RecordsTotal    = recordsTotal;
                pagingResponse.RecordsFiltered = recordsTotal;
            }
            return(pagingResponse);
        }
Esempio n. 13
0
        public ActionResult GetProjects(long projectId, [FromBody] PagingRequest <ProjectMaintenanceFilterDto> paging)
        {
            try
            {
                using (_UnitOfWork.Transaction = _UnitOfWork.Begin())
                {
                    var pagingResponse = new PagingResponse <ProjectMaintenanceDto>();
                    var lstDto         = _UnitOfWork.ProjectMaintenanceRepository.GetProjectMaintenance(projectId, paging);
                    var recordsTotal   = lstDto.Count();
                    if (paging.pageNumber != 0 && paging.pageSize != 0)
                    {//paging
                        pagingResponse.items = lstDto.Skip <ProjectMaintenanceDto>(paging.pageNumber).Take <ProjectMaintenanceDto>(paging.pageSize).ToArray();
                    }
                    else
                    {
                        var temp = lstDto.ToArray();
                        pagingResponse.items = temp;
                    }
                    pagingResponse.itemscount = recordsTotal;

                    return(Ok(pagingResponse));
                }
            }
            catch (Exception ex)
            {
                _UnitOfWork.Dispose();
                return(BadRequest(new { message = ex.Message }));
            }
            finally
            {
                _UnitOfWork.Dispose();
            }
        }
        public async Task <PagingResponse <Product> > GetProducts(ProductParameters productParameters)
        {
            var queryStringParam = new Dictionary <string, string>
            {
                ["pageNumber"] = productParameters.PageNumber.ToString(),
                ["searchTerm"] = productParameters.SearchTerm == null ? "" : productParameters.SearchTerm,
                ["orderBy"]    = productParameters.OrderBy
            };

            var response = await _client.GetAsync(QueryHelpers.AddQueryString("https://localhost:5011/api/products", queryStringParam));

            var content = await response.Content.ReadAsStringAsync();

            if (!response.IsSuccessStatusCode)
            {
                throw new ApplicationException(content);
            }

            var pagingResponse = new PagingResponse <Product>
            {
                Items = JsonSerializer.Deserialize <List <Product> >(content, new JsonSerializerOptions {
                    PropertyNameCaseInsensitive = true
                }),
                MetaData = JsonSerializer.Deserialize <MetaData>(response.Headers.GetValues("X-Pagination").First(), new JsonSerializerOptions {
                    PropertyNameCaseInsensitive = true
                })
            };

            return(pagingResponse);
        }
        public async Task <IPagingResponse <OrderInfo> > GetOrdersAsync(Int32 pageSize = 10, Int32 pageNumber = 1, Int16?currencyID = null, Int32?customerID = null, Int32?employeeID = null, Int16?orderStatusID = null, Guid?paymentMethodID = null, Int32?shipperID = null)
        {
            Logger?.LogInformation("{0} has been invoked", nameof(GetOrdersAsync));

            var response = new PagingResponse <OrderInfo>();

            try
            {
                // Get query
                var query = SalesRepository
                            .GetOrders(currencyID, customerID, employeeID, orderStatusID, paymentMethodID, shipperID);

                // Set information for paging
                response.PageSize   = (Int32)pageSize;
                response.PageNumber = (Int32)pageNumber;
                response.ItemsCount = await query.CountAsync();

                // Retrieve items, set model for response
                response.Model = await query
                                 .Paging(pageSize, pageNumber)
                                 .ToListAsync();
            }
            catch (Exception ex)
            {
                response.SetError(ex, Logger);
            }

            return(response);
        }
Esempio n. 16
0
        public async Task <PagingResponse <Customer> > GetCustomers(RequestParams requestParams)
        {
            //variable to construct the paging request Url with the required headers.
            var queryStringParam = new Dictionary <string, string>
            {
                //["totalCount"] = requestParams.TotalCount.ToString(),
                ["pageNumber"] = requestParams.PageNumber.ToString(),
                //["currentPage"] = requestParams.CurrentPage.ToString(),
                ["pageSize"]   = requestParams.PageSize.ToString(),
                ["searchTerm"] = requestParams.SearchTerm == null ? "" : requestParams.SearchTerm,
                ["orderBy"]    = requestParams.OrderBy == null ? "" : requestParams.OrderBy
            };

            //$"customer?pageNumber={requestParams.PageNumber}"
            var response = await _client.GetAsync(QueryHelpers.AddQueryString("Customer", queryStringParam));

            var content = await response.Content.ReadAsStringAsync();

            var pagingResponse = new PagingResponse <Customer>
            {
                Items    = JsonSerializer.Deserialize <List <Customer> >(content, _options),
                MetaData = JsonSerializer.Deserialize <MetaData>(
                    response.Headers.GetValues("X-Pagination").First(), _options)
            };

            return(pagingResponse);
        }
Esempio n. 17
0
        public ActionResult GetAll([FromBody] PagingRequest <SalaryFilterDto> paging)
        {
            try
            {
                using (_UnitOfWork.Transaction = _UnitOfWork.Begin())
                {
                    var pagingResponse = new PagingResponse <SalaryListDto>();

                    var lstDto       = _UnitOfWork.SalaryRepository.GetAllSalaryAsQuerable(paging);
                    var recordsTotal = lstDto.Count();
                    //paging
                    pagingResponse.items      = lstDto.Skip <SalaryListDto>(paging.pageSize * paging.pageNumber).Take <SalaryListDto>(paging.pageSize).ToArray();
                    pagingResponse.itemscount = recordsTotal;
                    return(Ok(pagingResponse));
                }
            }
            catch (Exception ex)
            {
                _UnitOfWork.Dispose();
                return(BadRequest(new { message = ex.Message }));
            }
            finally
            {
                _UnitOfWork.Dispose();
            }
        }
Esempio n. 18
0
        public async Task <PagingResponse <UserInfo> > GetUserInfos(UserParameters userParameters)
        {
            var queryStringParam = new Dictionary <string, string>
            {
                ["pageNumber"] = userParameters.PageNumber.ToString(),
                ["searchTerm"] = userParameters.SearchTerm ?? ""
            };
            var response = await _client.GetAsync(QueryHelpers.AddQueryString("user/GetPage", queryStringParam));

            var content = await response.Content.ReadAsStringAsync();

            if (!response.IsSuccessStatusCode)
            {
                throw new ApplicationException(content);
            }
            var pagingResponse = new PagingResponse <UserInfo>
            {
                Items = JsonSerializer.Deserialize <List <UserInfo> >(content, new JsonSerializerOptions {
                    PropertyNameCaseInsensitive = true
                }),
                MetaData = JsonSerializer.Deserialize <MetaData>(response.Headers.GetValues("X-Pagination").First(), new JsonSerializerOptions {
                    PropertyNameCaseInsensitive = true
                })
            };

            return(pagingResponse);
        }
Esempio n. 19
0
        public JsonResult Cashdraws(int? pageIndex = 1)
        {
            Base_Bll bll = new Base_Bll();
            var info = bll.GetInfo<md_cashdraw_app>(1);

            if (pageIndex <= 1)
                pageIndex = 1;
            //状态
            List<SelectListItem> status = (Share.EnumOperate.ToKeyValues(typeof(CashdrawStatus))
                .Select(t => new SelectListItem() { Value = t.Key.ToString(), Text = t.Value, Selected = t.Key == 0 })).ToList();
            ViewBag.status = status;

            string error = string.Empty;
            int record = 0;
            List<md_cashdraw_app> resultlist = new md_cashdraw_app_Bll().SearchCashdrawList(1, null, null, null, null, null, 0, null, null, pageIndex.Value, 2, out record, out error);
            if (resultlist != null)
            {
                PagingResponse<md_cashdraw_app> pagingResponse = new PagingResponse<md_cashdraw_app>();
                pagingResponse.TotalRecord = record;
                pagingResponse.ResultList = resultlist;
                var jsonResult = Json(pagingResponse, JsonRequestBehavior.AllowGet);
                return jsonResult;
            }
            return null;
        }
Esempio n. 20
0
        public async Task <PagingResponse <CompanyDto> > GetCompaniesAsync(CompanyParametersDto companyParameters)
        {
            var queryStringParam = new Dictionary <string, string>
            {
                ["pageNumber"] = companyParameters.PageNumber.ToString(),
                ["pageSize"]   = companyParameters.PageSize.ToString(),
                ["sortOrder"]  = companyParameters.SortOrder.ToString(),
                ["filters"]    = companyParameters.Filters.ToString()
            };

            using (var httpClient = new HttpClient())
            {
                using (var response = await httpClient.GetAsync(QueryHelpers.AddQueryString(uriCompany.ToString(), queryStringParam)))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();

                        var pagingResponse = new PagingResponse <CompanyDto>
                        {
                            Items    = JsonConvert.DeserializeObject <PageListCompany>(content).Companies,
                            Metadata = JsonConvert.DeserializeObject <MetaData>(response.Headers.GetValues("x-pagination").First())
                        };

                        pagingResponse.Filters   = companyParameters.Filters;
                        pagingResponse.SortOrder = companyParameters.SortOrder;
                        return(pagingResponse);
                    }
                    return(null);
                }
            }
        }
Esempio n. 21
0
        public IActionResult GetCustomer([FromBody] PagingRequest paging)
        {
            var pagingResponse = new PagingResponse()
            {
                Draw = paging.Draw
            };

            IQueryable <CustomerModel> query = null;

            if (!string.IsNullOrEmpty(paging.SearchCriteria.Filter))
            {
                query = _customerService.GetAll().Where(cust => cust.FirstName.Contains(paging.SearchCriteria.Filter)).AsQueryable();
            }
            else if (!string.IsNullOrEmpty(paging.Search.Value))
            {
                query = _customerService.GetAll().Where(cust => cust.FirstName.Contains(paging.Search.Value) || cust.LastName.Contains(paging.Search.Value) ||
                                                        cust.MobileNumber.Contains(paging.Search.Value) || cust.Email.ToString().Contains(paging.Search.Value)
                                                        ).AsQueryable();
            }
            else
            {
                query = _customerService.GetAll().AsQueryable();
            }
            var recordsTotal = query.Count();
            var colOrder     = paging.Order[0];

            switch (colOrder.Column)
            {
            case 0:
                query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.FirstName) : query.OrderByDescending(emp => emp.FirstName);
                break;

            case 1:
                query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.FirstName) : query.OrderByDescending(emp => emp.FirstName);
                break;

            case 2:
                query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.LastName) : query.OrderByDescending(emp => emp.LastName);
                break;

            case 3:
                query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.MobileNumber) : query.OrderByDescending(emp => emp.MobileNumber);
                break;

            case 4:
                query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.Email) : query.OrderByDescending(emp => emp.Email);
                break;

            case 5:
                query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.Address) : query.OrderByDescending(emp => emp.Address);
                break;
            }

            pagingResponse.data            = query.Skip(paging.Start).Take(paging.Length).ToArray();
            pagingResponse.RecordsTotal    = recordsTotal;
            pagingResponse.RecordsFiltered = recordsTotal;

            return(Ok(pagingResponse));
        }
Esempio n. 22
0
        public PagingResponse <BookVM> GetDataServerSide(PagingRequest paging)
        {
            using (context)
            {
                var pagingResponse = new PagingResponse <BookVM>()
                {
                    // counts how many times the user draws data
                    Draw = paging.Draw
                };
                // initialized query
                IEnumerable <Book> query = null;
                // search if user provided a search value, i.e. search value is not empty
                if (!string.IsNullOrEmpty(paging.Search.Value))
                {
                    // search based from the search value
                    query = context.Books.Include(x => x.Genre)
                            .Include(x => x.BookAuthors)
                            .ThenInclude(x => x.Author)
                            .Where(v => v.Title.ToString().ToLower().Contains(paging.Search.Value.ToLower()) ||
                                   v.Copyright.ToString().ToLower().Contains(paging.Search.Value.ToLower()) ||
                                   v.Genre.Name.ToString().ToLower().Contains(paging.Search.Value.ToLower()) ||
                                   v.BookAuthors.Any(x => x.AuthorFullName.ToLower().Contains(paging.Search.Value.ToLower())));
                }
                else
                {
                    // selects all from table
                    query = context.Books
                            .Include(x => x.Genre)
                            .Include(x => x.BookAuthors)
                            .ThenInclude(x => x.Author);
                }
                // total records from query
                var recordsTotal = query.Count();
                // orders the data by the sorting selected by the user
                // used ternary operator to determine if ascending or descending
                var colOrder = paging.Order[0];
                switch (colOrder.Column)
                {
                case 0:
                    query = colOrder.Dir == "asc" ? query.OrderBy(v => v.Title) : query.OrderByDescending(v => v.Title);
                    break;

                case 1:
                    query = colOrder.Dir == "asc" ? query.OrderBy(b => b.Copyright) : query.OrderByDescending(b => b.Copyright);
                    break;

                case 2:
                    query = colOrder.Dir == "asc" ? query.OrderBy(b => b.Genre.Name) : query.OrderByDescending(b => b.Genre.Name);
                    break;
                }
                var taken = query.Skip(paging.Start).Take(paging.Length).ToArray();
                // converts model(query) into viewmodel then assigns it to response which is displayed as "data"
                pagingResponse.Reponse         = taken.Select(x => toViewModel.Book(x));
                pagingResponse.RecordsTotal    = recordsTotal;
                pagingResponse.RecordsFiltered = recordsTotal;

                return(pagingResponse);
            }
        }
Esempio n. 23
0
        public async Task <ActionResult> GetAllMedia()
        {
            // My test open excel
            PagingResponse result = null;

            result = await _mediaLogic.GetAllMedia();

            return(Ok(new BaseResponse(result.Data, result.Paging)));
        }
Esempio n. 24
0
        public async Task <ActionResult> FilterSimCardBy([FromBody] ReqFilterSimCard reqFilterSimCard)
        {
            PagingResponse result = null;

            if (reqFilterSimCard != null)
            {
                result = await _simCardLogic.FilterSimCardBy(reqFilterSimCard);
            }
            return(Ok(new BaseResponse(result.Data, result.Paging)));
        }
        private PagingResponse <VotingItemResponse> constructPagingResponse(PagedList <VotingItemResponse> result)
        {
            PagingResponse <VotingItemResponse> response = new PagingResponse <VotingItemResponse>();

            response.CurrentPage = result.CurrentPage;
            response.PageSize    = result.PageSize;
            response.TotalCount  = result.TotalCount;
            response.TotalPages  = result.TotalPages;
            response.Result      = result;
            return(response);
        }
Esempio n. 26
0
        /// <inheritdoc/>
        public async Task <PagingResponse <ProductViewModel> > GetProducts(PageParameters parameters, string searchTerm = null)
        {
            List <Error> errors = new List <Error>();

            try
            {
                _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var queryStringParam = new Dictionary <string, string>
                {
                    ["pageNumber"] = parameters.PageNumber.ToString()
                };

                var baseUrl = $"{ _apiSettings.BaseUrl}{ _apiSettings.GetProductsEndpoint}";

                if (!string.IsNullOrWhiteSpace(searchTerm))
                {
                    baseUrl = $"{baseUrl}{searchTerm}/";
                }

                var productsUrl = $"{QueryHelpers.AddQueryString(baseUrl, queryStringParam)}";

                var response = await _httpClient.GetAsync(productsUrl);

                if (!response.IsSuccessStatusCode)
                {
                    return(new PagingResponse <ProductViewModel>
                    {
                        Message = "Ha ocurrido un error al obtener los productos.",
                        Success = false
                    });
                }

                string productsString = await response.Content.ReadAsStringAsync();

                string metaData       = response.Headers.GetValues("X-Pagination").First();
                var    serviceData    = JsonConvert.DeserializeObject <ProductsViewModel>(productsString);
                var    pagingResponse = new PagingResponse <ProductViewModel>
                {
                    Items    = serviceData.Products,
                    MetaData = JsonConvert.DeserializeObject <PageMetadata>(metaData),
                    Success  = serviceData.Success
                };

                return(pagingResponse);
            }
            catch (System.Exception ex)
            {
                errors.Add(new Error(ex.GetType().ToString(), ex.Message));
                return(new PagingResponse <ProductViewModel>
                {
                    Message = ex.Message
                });
            }
        }
Esempio n. 27
0
        public virtual IPagingResponse FindTestEntities(IFilterDescriptor filterDescriptor, ISortDescriptor[] sortDescriptors, IPagingRequest pagingRequest)
        {
            IList <Object> allIdsOfTypeInCache = PersistenceMock.GetAllIds <TestEntity>();
            IList <Object> result         = Cache.GetObjects(typeof(TestEntity), allIdsOfTypeInCache);
            PagingResponse pagingResponse = new PagingResponse();

            if (pagingRequest != null)
            {
                pagingResponse.Number = pagingRequest.Number;
            }
            pagingResponse.Result = result;
            return(pagingResponse);
        }
        public async Task <IHttpActionResult> Post([FromBody] PagingRequest paging)
        {
            var pagingResponse = new PagingResponse()
            {
                Draw = paging.Draw
            };

            if (!paging.SearchCriteria.IsPageLoad)
            {
                IQueryable <Employee> query = null;

                if (!string.IsNullOrEmpty(paging.SearchCriteria.Filter))
                {
                    query = _context.Employees.Where(emp => emp.Name.Contains(paging.SearchCriteria.Filter));
                }
                else
                {
                    query = _context.Employees;
                }

                var recordsTotal = await query.CountAsync();

                var colOrder = paging.Order[0];

                switch (colOrder.Column)
                {
                case 0:
                    query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.EmployeeID) : query.OrderByDescending(emp => emp.EmployeeID);
                    break;

                case 1:
                    query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.Name) : query.OrderByDescending(emp => emp.Name);
                    break;

                case 2:
                    query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.Email) : query.OrderByDescending(emp => emp.Email);
                    break;

                case 3:
                    query = colOrder.Dir == "asc" ? query.OrderBy(emp => emp.Company) : query.OrderByDescending(emp => emp.Company);
                    break;
                }

                pagingResponse.Employees = await query.Skip(paging.Start).Take(paging.Length).ToArrayAsync();

                pagingResponse.RecordsTotal    = recordsTotal;
                pagingResponse.RecordsFiltered = recordsTotal;
            }

            return(Ok(pagingResponse));
        }
Esempio n. 29
0
        private static PagingResponse <T> PagingResponse <T>(PagingRequest request, IQueryable <T> countQuery, IQueryable <T> dataQuery)
        {
            var response = new PagingResponse <T>
            {
                CurrentPage  = request.CurrentPage,
                PageSize     = request.PageSize,
                TotalRecords = countQuery.Count(),
                Records      = dataQuery
                               .Skip((request.CurrentPage - 1) * request.PageSize)
                               .Take(request.PageSize)
            };

            return(response);
        }
        public IActionResult PutStudent([FromBody] PagingRequest paging)
        {
            var pagingResponse = new PagingResponse()
            {
                Draw = paging.Draw
            };


            IQueryable <Student> query = null;

            if (!string.IsNullOrEmpty(paging.SearchCriteria.Filter))
            {
                query = _studentRepository.GetAll().Where(p => p.Name.Contains(paging.SearchCriteria.Filter));
            }
            else
            {
                query = _studentRepository.GetAll();
            }

            var recordsTotal = query.Count();

            var colOrder = paging.Order[0];

            switch (colOrder.Column)
            {
            case 0:
                query = colOrder.Dir == "asc" ? query.OrderBy(st => st.Id) : query.OrderByDescending(st => st.Id);
                break;

            case 1:
                query = colOrder.Dir == "asc" ? query.OrderBy(st => st.Name) : query.OrderByDescending(st => st.Name);
                break;

            case 2:
                query = colOrder.Dir == "asc" ? query.OrderBy(st => st.Address) : query.OrderByDescending(st => st.Address);
                break;

            case 3:
                query = colOrder.Dir == "asc" ? query.OrderBy(st => st.Hire_date) : query.OrderByDescending(st => st.Hire_date);
                break;
            }

            pagingResponse.Users           = query.AsEnumerable().Skip(paging.Start).Take(paging.Length).ToArray();
            pagingResponse.RecordsTotal    = recordsTotal;
            pagingResponse.RecordsFiltered = recordsTotal;


            return(Ok(pagingResponse));
        }
        public async Task <ActionResult <PagingResponse <VehiclePriceListItemDTO> > > GetPaging([FromQuery] PagingRequest req)
        {
            PagingResponse <VehiclePriceListItem> pagingResponse = null;

            try
            {
                pagingResponse = await _vehiclesPriceListService.GetAllPaging(req);

                var pagingResponseDto = _mapper.Map <PagingResponse <VehiclePriceListItem>, PagingResponse <VehiclePriceListItemDTO> >(pagingResponse);
                return(Ok(pagingResponseDto));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
        public JsonResult PatientMessages(int? pageIndex = 1)
        {
            if (pageIndex <= 1)
                pageIndex = 1;

            string error = string.Empty;
            int record = 0;
            List<patient_message> resultlist = new patient_message_Bll().SearchMessgaeList(0, 0, 0, 0, null, null,null,
             null,null, pageIndex.Value, 20, out error);
            if (resultlist != null)
            {
                PagingResponse<patient_message> pagingResponse = new PagingResponse<patient_message>();
                pagingResponse.TotalRecord = record;
                pagingResponse.ResultList = resultlist;
                var jsonResult = Json(pagingResponse, JsonRequestBehavior.AllowGet);
                return jsonResult;
            }
            return null;
        }
Esempio n. 33
0
        public JsonResult PromotionCoupons(int? pageIndex = 1)
        {
            if (pageIndex <= 1)
                pageIndex = 1;
            //状态
            List<SelectListItem> status = (Share.EnumOperate.ToKeyValues(typeof(CouponsStatus))
                .Select(t => new SelectListItem() { Value = t.Key.ToString(), Text = t.Value, Selected = t.Key == 0 })).ToList();
            ViewBag.status = status;

            string error = string.Empty;
            int record = 0;
            var bll = new promotion_events_Bll();
            List<promotion_coupons> resultlist = bll.GetPromotionCouponsList(null, 0, 0, null, null, null, null,
               null, null, pageIndex.Value, 20, out record, out error);
            if (resultlist != null)
            {
                List<int> ids = resultlist.Select(m => m.pkid).ToList();
                var details = bll.GetCouponsDetailByIds(ids);

                foreach (var item in resultlist)
                {
                    var list = details.Where(m => m.coupons_id == item.pkid && m.userid > 0).ToList();
                    item.stock = item.issue_num - list.Count;
                }

                PagingResponse<promotion_coupons> pagingResponse = new PagingResponse<promotion_coupons>();
                pagingResponse.TotalRecord = record;
                pagingResponse.ResultList = resultlist;
                var jsonResult = Json(pagingResponse, JsonRequestBehavior.AllowGet);
                return jsonResult;
            }
            return null;
        }
Esempio n. 34
0
        public JsonResult SearchPromotionList(int? pageIndex = 1)
        {
            if (pageIndex <= 1)
                pageIndex = 1;

            string error = string.Empty;
            int record = 0;
            List<promotion_events> resultlist = new promotion_events_Bll().GetPromotionEventList(null, 0, 0, null, null, null, null,
             null, null, null, null, pageIndex.Value, 20, out record, out error);
            if (resultlist != null)
            {
                foreach (var item in resultlist)
                {
                    item.eventtypestr = Enum.GetName(typeof(Model.ConfigClass.PromotionEventType), item.pkid);
                }
                PagingResponse<promotion_events> pagingResponse = new PagingResponse<promotion_events>();
                pagingResponse.TotalRecord = record;
                pagingResponse.ResultList = resultlist;
                var jsonResult = Json(pagingResponse, JsonRequestBehavior.AllowGet);
                return jsonResult;
            }
            return null;
        }
Esempio n. 35
0
        public JsonResult SearchPromotionCouponsDetail(int coupons_id, int? pageIndex = 1)
        {
            if (pageIndex <= 1)
                pageIndex = 1;

            string error = string.Empty;
            int record = 0;
            List<promotion_coupons_detail> resultlist = new promotion_events_Bll().SearchPromotionCouponsList(coupons_id, 0, 0, 0, 0, null, null, null, null,
               null, null, pageIndex.Value, 20, out record, out error);
            if (resultlist != null)
            {
                foreach (var item in resultlist)
                {
                    item.statusstr = Enum.GetName(typeof(Model.ConfigClass.CouponsStatus), item.use_status);
                    item.businesstypestr =item.business_type == 0?null: Enum.GetName(typeof(Model.ConfigClass.CouponsStatus), item.business_type);
                }
                PagingResponse<promotion_coupons_detail> pagingResponse = new PagingResponse<promotion_coupons_detail>();
                pagingResponse.TotalRecord = record;
                pagingResponse.ResultList = resultlist;
                var jsonResult = Json(pagingResponse, JsonRequestBehavior.AllowGet);
                return jsonResult;
            }
            return null;
        }
Esempio n. 36
0
        public JsonResult PostSearchPromotionList(string name, DateTime? date1, DateTime? date2, int? pageIndex = 1)
        {
            if (pageIndex <= 1)
                pageIndex = 1;

            string error = string.Empty;
            int record = 0;
            Base_Bll bll = new Base_Bll();
            var events = bll.GetInfo<promotion_events>(BaseTool.GetIntNumber(name));
            if (events != null)
            {
                name = events.name;
            }

            List<promotion_events> resultlist = new promotion_events_Bll().GetPromotionEventList(name, 0, 0, date1, date2, null, null,
             null, null, null, null, pageIndex.Value, 20, out record, out error);
            if (resultlist != null)
            {
                foreach (var item in resultlist)
                {
                    item.eventtypestr = Enum.GetName(typeof(Model.ConfigClass.PromotionEventType), item.pkid);
                }
                PagingResponse<promotion_events> pagingResponse = new PagingResponse<promotion_events>();
                pagingResponse.TotalRecord = record;
                pagingResponse.ResultList = resultlist;
                var jsonResult = Json(pagingResponse, JsonRequestBehavior.AllowGet);
                return jsonResult;
            }
            return null;
        }
Esempio n. 37
0
        public JsonResult SearchPromotionCoupons(string name, int values, int issue_status, DateTime? startdate1, DateTime? startdate2, int? pageIndex = 1)
        {
            if (pageIndex <= 1)
                pageIndex = 1;
            //状态
            List<SelectListItem> status = (Share.EnumOperate.ToKeyValues(typeof(CouponsStatus))
                .Select(t => new SelectListItem() { Value = t.Key.ToString(), Text = t.Value, Selected = t.Key == 0 })).ToList();
            ViewBag.status = status;

            string error = string.Empty;
            int record = 0;
            List<promotion_coupons> resultlist = new promotion_events_Bll().GetPromotionCouponsList(name, values, issue_status, startdate1, startdate2, null, null,
               null, null, pageIndex.Value, 20, out record, out error);
            if (resultlist != null)
            {
                PagingResponse<promotion_coupons> pagingResponse = new PagingResponse<promotion_coupons>();
                pagingResponse.TotalRecord = record;
                pagingResponse.ResultList = resultlist;
                var jsonResult = Json(pagingResponse, JsonRequestBehavior.AllowGet);
                return jsonResult;
            }
            return null;
        }