コード例 #1
0
        public JsonResult GetLocationsByDistance(LocationUtilsFilterOptions locationFilterOptions, ResultsFilter resultsFilter, PagedListOptions pagedListOptions)
        {
            var locationFilter = locationFilterOptions.ToLocationFilter();
            var minutes = resultsFilter.Minutes;
            pagedListOptions.SortBy = pagedListOptions.SortBy ?? "Distance";

            var locationsQuery = db.Locations
                .Where(x => x.Coordinate.Distance(locationFilter.Origin) <= locationFilter.Radius)
                .Select(x => new LocationModel
                {
                    LocationId = x.LocationID,
                    AddressLine1 = x.Address,
                    AddressLine2 = x.Address,
                    AddressLine3 = x.Address,
                    AddressLine4 = x.Address,
                    AddressLine5 = x.Address,
                    PostalCode = "BS234",
                    Distance = x.Coordinate.Distance(locationFilter.Origin)
                });
            
            var data = locationsQuery.ToPagedListData(pagedListOptions)
                .Select(x => new ResultModel
                {
                    LocationId = x.LocationId,
                    Address = x.Address,
                    Miles = x.Miles
                });

            var result = new PagedListResult<ResultModel>(data, locationsQuery.ToPagedListDetails());

            return Json(result, JsonRequestBehavior.AllowGet);
        }
コード例 #2
0
        public PagedListResult<BooksModel> Get(PagedListOptions pagedListOptions)
        {
            var book = db.Books.Select(x => new BooksModel
            {
                BookId = x.BookId,
                Description = x.Description,
                Title = x.Title,
                PublishDate = x.PublishDate,
                Author = x.Author.FirstName + " " + x.Author.LastName
            }).ToPagedListResult(pagedListOptions);

            return book;
        }
コード例 #3
0
        public PagedListResult<BooksModel> GetList(BooksFilterOptions filters, PagedListOptions pagedListOptions)
        {
            //try
            //{
            //    //Seed();
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}

            Test();

            var data = db.Books.AsQueryable();

            // filter Description
            if (!string.IsNullOrEmpty(filters.Title))
            {
                data = data.Where("Title.Contains(@0)", filters.Title);
            }

            // filter Author
            if (!string.IsNullOrEmpty(filters.Author))
            {
                //data = data.Where("Author.Person.LastName.Contains(@0) OR Author.Person.FirstName.Contains(@0)", filters.Author);
                //data = data.Where("Author.Person.FirstName.Contains(@0)", filters.Author);
            }

            // filter Description
            if (!string.IsNullOrEmpty(filters.Description))
            {
                data = data.Where(x => x.Description.Contains(filters.Description));
            }

            // REQUIRED
            pagedListOptions.SortBy = pagedListOptions.SortBy ?? "BookId";

            var r = new Random();
            var pagedListResult = data
                .Select(x => new BooksModel
                {
                    AuthorFirstName = x.Author.FirstName,
                    BookId = x.BookId,
                    //Description = Common.QueryHelpers.BookingCost, //r.Next(9999, int.MaxValue).ToString(), //x.Description,
                    PublishDate = x.PublishDate
                }).ToPagedListResult(pagedListOptions);

            var res = new List<BooksModel>();

            pagedListResult.Data.ToList()
            .ForEach(x =>
            {
                var a = r.Next(9999, int.MaxValue) * .0001;
                x.Description = a.ToString();

                res.Add(x);
            });

            //pagedListResult.Data = res;

            return new PagedListResult<BooksModel>(res, pagedListResult.Details);

            //var pagedListResult = data
            //    .OrderBy(pagedListOptions.OrderBy)
            //    .Skip(pagedListOptions.Start)
            //    .Take(pagedListOptions.ShowAll ? data.Count() : pagedListOptions.Entries)
            //    .Select(x => new BooksModel()
            //    {
            //        BookId = x.BookId,
            //        Title = x.Title,
            //        Description = x.Description,
            //        Author = x.Author.Person.FirstName + " " + x.Author.Person.LastName,
            //        PublishDate = x.PublishDate
            //    });//.ToPagedListResult(pagedListOptions);

            //var result = new PagedListResult<BooksModel>(pagedListResult, new PagedListDetails()
            //{
            //    TotalEntries = data.Count()
            //});
            //return result;


            //return pagedListResult;
            //// sample data



            //try
            //{
            //    db.Books.AddRange(sampleData);
            //    db.SaveChanges();
            //}
            //catch (Exception ex)
            //{

            //    throw ex;
            //}

            // sample data end

            // convert to queryable
            //var data = books.AsQueryable();

            //// filter data
            //if (!string.IsNullOrEmpty(filters.Author))
            //{
            //    data = data.Where(x => x.Author.ToLower().Contains(filters.Author.ToLower()));
            //    //data = data.Where("Author.Contains(@0)", filters.Author);
            //}

            //// filter data
            //if (!string.IsNullOrEmpty(filters.Description))
            //{
            //    data = data.Where(x => x.Description.ToLower().Contains(filters.Description.ToLower()));
            //}

            //// set default sort field
            //pagedListOptions.SortBy = pagedListOptions.SortBy ?? "BookId";

            //// get paged list result
            //var pagedListResult = data.ToPagedListResult(pagedListOptions);

            //return pagedListResult;
        }