Esempio n. 1
0
        public ActionResult UserCollections(int e = 0)
        {
            UserCollectionList model = new UserCollectionList();

            Phocalstream_Shared.Data.Model.Photo.User User = UserRepository.First(u => u.ProviderID == this.User.Identity.Name);
            model.User = User;

            model.SiteThumbnails = new List<ThumbnailModel>();
            model.TimelapseThumbnails = new List<ThumbnailModel>();
            model.CollectionThumbnails = new List<ThumbnailModel>();

            model.Collections = CollectionRepository.Find(c => c.Owner.ID == User.ID, c => c.Photos).ToList<Collection>();
            foreach (var col in model.Collections)
            {
                if (col.CoverPhoto == null)
                {
                    col.CoverPhoto = col.Photos.LastOrDefault();
                }

                var thumb = new ThumbnailModel()
                {
                    ID = col.ID,
                    Name = col.Name,
                    PhotoCount = col.Photos.Count,
                    Link = "/search/index?collectionId=" + col.ID.ToString(),

                    CanEdit = true,
                    EditLink = "/Account/EditUserCollection?collectionID=" + col.ID.ToString(),
                    CanDelete = true,
                    DeleteLink = "/Account/DeleteUserCollection?collectionID=" + col.ID.ToString()
                };

                if (thumb.PhotoCount > 0)
                {
                    thumb.First = col.Photos.First().Captured;
                    thumb.Last = col.Photos.Last().Captured;
                    thumb.CoverPhotoID = col.CoverPhoto.ID;
                }

                switch (col.Type)
                {
                    case CollectionType.TIMELAPSE:
                        model.TimelapseThumbnails.Add(thumb);
                        break;
                    case CollectionType.USER:
                        if (col.Site == null)
                        {
                            model.CollectionThumbnails.Add(thumb);
                        }
                        else
                        {
                            model.SiteThumbnails.Add(thumb);
                        }
                        break;
                }
            }

            if (e == 1)
            {
                ViewBag.Message = "That collection doesn't contain any photos.";
            }
            else if (e == 2)
            {
                ViewBag.Message = "Successfully deleted collection.";
            }
            else if (e == 3)
            {
                ViewBag.Message = "Error deleting collection.";
            }

            return View(model);
        }
Esempio n. 2
0
        private CollectionViewModel GetCollectionViewModel(long siteID, long year)
        {
            CollectionViewModel model = new CollectionViewModel();

            model.Collection = CollectionRepository.First(c => c.Site.ID == siteID);
            model.SiteCoords = string.Format("{0}, {1}", model.Collection.Site.Latitude, model.Collection.Site.Longitude);

            List<Photo> photos = PhotoRepository.Find(p => p.Site.ID == model.Collection.Site.ID).OrderBy(p => p.Captured).ToList<Photo>();
            if (year != -1)
            {
                photos = photos.Where(p => p.Captured.Year == year).ToList<Photo>();
            }

            model.SiteDetails = new SiteDetails() { PhotoCount = photos.Count(), First = photos.Select(p => p.Captured).First(), Last = photos.Select(p => p.Captured).Last() };

            Phocalstream_Shared.Data.Model.Photo.User User = UserRepository.First(u => u.ProviderID == this.User.Identity.Name);
            if (User != null)
            {
                UserCollectionList userCollectionModel = new UserCollectionList();
                userCollectionModel.User = User;
                userCollectionModel.Collections = CollectionRepository.Find(c => c.Owner.ID == User.ID && c.Type == CollectionType.USER, c => c.Photos).ToList();
                model.UserCollections = userCollectionModel;
            }

            return model;
        }
Esempio n. 3
0
        public ActionResult Index(long collectionId = -1, string tag = "", string site = "", string year = "")
        {
            SearchModel model = new SearchModel();

            model.AvailableTags = PhotoService.GetTagNames();
            model.SiteNames = SearchService.GetSiteNames();

            Phocalstream_Shared.Data.Model.Photo.User User = UserRepository.First(u => u.ProviderID == this.User.Identity.Name);
            if (User != null)
            {
                UserCollectionList userCollectionModel = new UserCollectionList();
                userCollectionModel.User = User;
                userCollectionModel.Collections = CollectionRepository.Find(c => c.Owner.ID == User.ID && c.Site == null && c.Type == CollectionType.USER, c => c.Photos).ToList();
                model.UserCollections = userCollectionModel;

                ViewBag.UserId = User.ID;
            }

            Collection collection = CollectionRepository.Find(c => c.ID == collectionId).FirstOrDefault();
            if (collection != null && !collection.Public && collection.Type == CollectionType.USER)
            {
                // If the collection is a user collection, and it does not belong to current user
                if (User == null || collection.Owner.ID != User.ID)
                {
                    collection = null;
                }
            }

            if (collection != null)
            {
                ViewBag.CollectionId = collection.ID;
            }

            ViewBag.Tag = tag;
            ViewBag.Site = site;
            ViewBag.Year = year;

            return View(model);
        }