//[Route("api/IndexPage/GetCarouselImages")] public CarouselInfoModel GetCarouselImages(string root, int skip, int take, bool includeLandscape, bool includePortrait) { CarouselInfoModel carouselInfo = new CarouselInfoModel(); try { using (var db = new OggleBoobleMySqlContext()) { if (includeLandscape) { carouselInfo.Links.AddRange(db.VwCarouselImages.Where(v => v.RootFolder == root).Where(v => v.Height < v.Width) .Where(v => v.Width > v.Height) .OrderBy(v => v.LinkId).Skip(skip).Take(take).ToList()); } if (includePortrait) { carouselInfo.Links.AddRange(db.VwCarouselImages.Where(v => v.RootFolder == root).Where(v => v.Height < v.Width) .Where(v => v.Height >= v.Width) .OrderBy(v => v.LinkId).Skip(skip).Take(take).ToList()); } } carouselInfo.Success = "ok"; } catch (Exception ex) { carouselInfo.Success = Helpers.ErrorDetails(ex); } return(carouselInfo); }
public CarouselInfoModel LoadCache(string cacheName) { CarouselInfoModel carouselInfo = new CarouselInfoModel(); try { using (var db = new OggleBoobleMySqlContext()) { } carouselInfo.Success = "ok"; } catch (Exception ex) { carouselInfo.Success = Helpers.ErrorDetails(ex); } return(carouselInfo); }
public CarouselInfoModel RefreshCache(string root, int cacheCount) { CarouselInfoModel carouselInfo = new CarouselInfoModel(); using (var db = new OggleBoobleMySqlContext()) { try { List <VwCarouselItem> allCarouselItems; allCarouselItems = db.VwCarouselImages.Where(v => v.RootFolder == root) .Where(v => v.Width > v.Height) .OrderBy(v => v.LinkId).ToList(); int itemCount = allCarouselItems.Count(); if (itemCount > cacheCount) { Random random = new Random(); int rnd = random.Next(0, itemCount); for (int i = 0; i < cacheCount; i++) { carouselInfo.Links.Add(allCarouselItems[rnd]); rnd = random.Next(0, itemCount); } } else { carouselInfo.Links = allCarouselItems; } carouselInfo.Success = "ok"; } catch (Exception ex) { carouselInfo.Success = Helpers.ErrorDetails(ex); } } return(carouselInfo); }