예제 #1
0
    public void GetsDataFromDataBaseIfNotCachedTest()
    {
        var cacheProvider = new Mock <ICacheProvider>(MockBehavior.Strict);

        cacheProvider
        .Setup(x => x.IsDataCached())
        .Returns(() =>
        {
            return(false);
        });
        cacheProvider
        .Setup(x => x.GetFromCache())
        .Returns(
            () =>
        {
            return(new Event[] {
                new Event()
                {
                    Id = 1
                },
                new Event()
                {
                    Id = 2
                }
            });
        }
            );
        var eventRepo = new EventRepo(cacheProvider.Object);
        var data      = eventRepo.GetAll();

        cacheProvider.Verify(x => x.GetFromCache(), Times.Never());
    }
예제 #2
0
        private EventSearchModel Search(EventSearchModel model)
        {
            var query = EventRepo.GetAll().Where(x => x.UserId == currentUser.Id);

            if (!string.IsNullOrEmpty(model.SearchTitle))
            {
                query = query.Where(x => x.Title.Contains(model.SearchTitle));
            }

            if (model.SearchProvinceId.HasValue)
            {
                query = query.Where(x => x.City.provinceId == model.SearchProvinceId);
            }

            if (model.SearchCityId.HasValue)
            {
                query = query.Where(x => x.CityId == model.SearchCityId);
            }


            model.TotalItems = query.Count();

            var result = query.OrderBy(x => x.Createdate)
                         .Skip((model.CurrentPage - 1) * model.PageSize)
                         .Take(model.PageSize)
                         //.ToModel()
                         .ToList();

            model.Events = result;

            return(model);
        }
예제 #3
0
        public async Task <IActionResult> OnGetAsync()
        {
            EventRepo e     = new EventRepo(_context);
            var       query = e.GetAll();
            var       res   = new
            {
                EventArray = query
            };

            return(new ObjectResult(res));
        }
예제 #4
0
 public IActionResult All()
 {
     return(new ObjectResult(new { events = _eventRepo.GetAll() }));
 }