Exemplo n.º 1
0
        public JsonResult GetAllPhotos(int appId, int userId, int page = 1)
        {
            var view = new PhotosViewModel();
            
            var app = db.Instances.Where(i => i.Id == appId).First();
            if (app != null)
            {
                int skip = (page - 1) * app.PageSize;

                var images = photoService.GetPhotos(app.ImagePathDirectory + "/thumb/", app.PageSize, page)
                                .Skip(skip).Take(app.PageSize).ToList();
                
                // for this set of images, which ones has the user selected
                var userSelectedPhotos = db.SelectedPhotos.Where(s => s.UserId == userId).ToList();
                PhotosViewModel.Photo photo;
                foreach (var image in images)
                {
                    photo = new PhotosViewModel.Photo() { ImageName = image };

                    var selected = userSelectedPhotos.Where(s => s.ImageName == image.ToLower()).FirstOrDefault();
                    if (selected != null)
                        photo.SelectedPhotoId = selected.Id;

                    view.Photos.Add(photo);
                }

                view.CurrentPage = page;
                view.PageSize = app.PageSize;
                view.TotalPhotos = photoService.GetPhotos(app.ImagePathDirectory + "/thumb/", app.PageSize, page).Count();
                view.Pages = (int)Math.Ceiling(view.TotalPhotos / (double)app.PageSize);
                view.TotalSelected = userSelectedPhotos.Count();
            }

            return Json(view, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 2
0
        public JsonResult GetUserSelectedPhotos(int appId, int userId, int page = 1)
        {
            var view = new PhotosViewModel();
            var app = db.Instances.Where(i => i.Id == appId).First();
            
            if (app != null)
            {
                view.Photos = db.SelectedPhotos.Where(s => s.UserId == userId).OrderBy(s => s.ImageName)
                                    .Select(s => new PhotosViewModel.Photo() { ImageName = s.ImageName, SelectedPhotoId = s.Id })
                                    .ToList();
                
                view.CurrentPage = page;
                view.PageSize = app.PageSize;
                view.TotalPhotos = view.Photos.Count();
                view.Pages = (int)Math.Ceiling(view.TotalPhotos / (double)app.PageSize);
                view.TotalSelected = view.Photos.Count();
            }

            return Json(view, JsonRequestBehavior.AllowGet);
        }