Example #1
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);
        }
Example #2
0
        } //End LoadDMDataValues

        private UserCollectionData LoadUserCollections(long photoID)
        {
            Phocalstream_Shared.Data.Model.Photo.User User = UserRepository.First(u => u.ProviderID == this.User.Identity.Name);
            if (User != null)
            {
                UserCollectionData model = new UserCollectionData();
                model.PhotoID = photoID;

                List <UserCollection>    userCollections = new List <UserCollection>();
                IEnumerable <Collection> collections     = CollectionRepository.Find(c => c.Owner.ID == User.ID && c.Site == null && c.Type != CollectionType.TIMELAPSE, c => c.Photos);

                foreach (var col in collections)
                {
                    UserCollection userCollection = new UserCollection();

                    userCollection.CollectionID   = col.ID;
                    userCollection.CollectionName = col.Name;

                    userCollection.Added = col.Photos.Select(p => p.ID).Contains(photoID);

                    userCollections.Add(userCollection);
                }

                model.Collections = userCollections;
                return(model);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        public ActionResult TimeLapse(string photoIds, string timelapseName = "")
        {
            Phocalstream_Shared.Data.Model.Photo.User user = UserRepository.First(u => u.ProviderID == this.User.Identity.Name);
            long id = CollectionService.NewTimelapseCollection(user, timelapseName, photoIds);

            return(RedirectToAction("Timelapse", new { @collectionId = id }));
        }
        public ActionResult DeleteUserCollection(long collectionID)
        {
            Phocalstream_Shared.Data.Model.Photo.User User = UserRepository.First(u => u.ProviderID == this.User.Identity.Name);
            if (User != null)
            {
                if (CollectionService.DeleteUserCollection(User.ID, collectionID))
                {
                    return(RedirectToAction("UserCollections", "Account", new { e = 2 })); // success message
                }
            }

            return(RedirectToAction("UserCollections", "Account", new { e = 3 })); // error message
        }
        public void AddToExistingUserCollection(User user, string collectionIds, string photoIds)
        {
            long[] ids = photoIds.Split(',').Select(i => Convert.ToInt64(i)).ToArray();
            List<Photo> photos = PhotoRepository.Find(p => ids.Contains(p.ID)).ToList();

            long[] cIds = collectionIds.Split(',').Select(i => Convert.ToInt64(i)).ToArray();
            List<Collection> collections = CollectionRepository.Find(c => cIds.Contains(c.ID) && c.Type == CollectionType.USER, c => c.Photos).ToList();

            foreach (var col in collections)
            {
                col.Photos = col.Photos.Union(photos).ToList();
                col.Status = CollectionStatus.INVALID;
            }
            Unit.Commit();
        }
Example #6
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));
        }
        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));
        }
Example #8
0
        public Photo ProcessUserPhoto(Stream stream, string fileName, User user, long collectionID)
        {
            Collection collection = CollectionRepository.Find(c => c.ID == collectionID && c.Type == CollectionType.USER, c => c.Site, c => c.Photos).FirstOrDefault();

            string userFolder = Path.Combine(PathManager.GetUserCollectionPath(), Convert.ToString(user.ID));
            if (!Directory.Exists(userFolder))
            {
                Directory.CreateDirectory(userFolder);
            }

            try
            {
                // create the directory for the image and its components
                string basePath = Path.Combine(userFolder, collection.ContainerID, string.Format("{0}.phocalstream", fileName));
                if (!Directory.Exists(basePath))
                {
                    Directory.CreateDirectory(basePath);
                }

                // open a Bitmap for the image to parse the meta data from
                using (System.Drawing.Image img = System.Drawing.Image.FromStream(stream))
                {
                    string savePath = Path.Combine(basePath, fileName);
                    img.Save(savePath);

                    Photo photo = CreatePhotoWithProperties(img, fileName);
                    photo.FileName = fileName;
                    photo.Site = collection.Site;

                    PhotoRepository.Insert(photo);

                    collection.Photos.Add(photo);
                    collection.Status = CollectionStatus.INVALID;

                    // if first photo, set as cover photo
                    if (collection.Photos.Count == 1)
                    {
                        collection.CoverPhoto = photo;
                    }

                    Unit.Commit();

                    // only generate the phocalstream image if it has not already been generated
                    if (File.Exists(Path.Combine(basePath, @"High.jpg")) == false)
                    {
                        // this is a dirty hack, figure out why the image isn't opening with the correct width and height
                        if (photo.Portrait)
                        {
                            photo.Width = img.Height;
                            photo.Height = img.Width;
                        }

                        ResizeImageTo(savePath, 1200, 800, Path.Combine(basePath, @"High.jpg"), photo.Portrait);
                        ResizeImageTo(savePath, 800, 533, Path.Combine(basePath, @"Medium.jpg"), photo.Portrait);
                        ResizeImageTo(savePath, 400, 266, Path.Combine(basePath, @"Low.jpg"), photo.Portrait);
                    }

                    return photo;
                }
            }
            catch (Exception e)
            {
                throw new Exception(string.Format("Exception processing photo {0}. Message: {1}", fileName, e.Message));
            }
        }
        public void SetUserCollectionCoverPhoto(User user, long collectionID, long photoID)
        {
            Collection collection = CollectionRepository.First(c => c.ID == collectionID && c.Owner.ID == user.ID);
            Photo photo = PhotoRepository.First(p => p.ID == photoID);

            collection.CoverPhoto = photo;
            Unit.Commit();
        }
 public void SetUserCollectionPublic(User user, long collectionID, bool publish)
 {
     Collection collection = CollectionRepository.First(c => c.ID == collectionID && c.Owner.ID == user.ID);
     collection.Public = publish;
     Unit.Commit();
 }
        public void RemoveFromExistingUserCollection(User user, long collectionID, string photoIds)
        {
            long[] ids = photoIds.Split(',').Select(i => Convert.ToInt64(i)).ToArray();
            List<Photo> photos = PhotoRepository.Find(p => ids.Contains(p.ID)).ToList();

            Collection collection = CollectionRepository.First(c => c.ID == collectionID && c.Type == CollectionType.USER, c => c.Photos);

            collection.Photos = collection.Photos.Except(photos).ToList();
            collection.Status = CollectionStatus.INVALID;
            Unit.Commit();
        }
        public void NewUserCollection(User user, string collectionName, string photoIds)
        {
            List<Photo> photos;
            long[] ids;
            if (!String.IsNullOrWhiteSpace(photoIds))
            {
                ids = photoIds.Split(',').Select(i => Convert.ToInt64(i)).ToArray();
                photos = PhotoRepository.Find(p => ids.Contains(p.ID), p => p.Site).ToList();
            }
            else
            {
                ids = new long[0];
                photos = new List<Photo>();
            }

            Guid containerID = Guid.NewGuid();

            //save the collection
            Collection c = new Collection()
            {
                Name = collectionName,
                ContainerID = containerID.ToString(),
                Owner = user,
                Type = CollectionType.USER,
                Status = CollectionStatus.COMPLETE,
                Photos = photos
            };
            CollectionRepository.Insert(c);
            Unit.Commit();
        }
        public long NewTimelapseCollection(User user, string timelapseName, string photoIds)
        {
            // Use the hash of the photoIds as the container id so we can check if timelapse already exists
            string containerID = Convert.ToString(photoIds.GetHashCode());

            List<Photo> photos;
            long[] ids;

            // Only logged in users can own and name a collection
            if (user != null)
            {
                // See if the user already has a collection for those photos, if so return that collection id
                Collection existingUserCollection = CollectionRepository.Find(c => c.ContainerID == containerID & c.Owner.ID == user.ID).FirstOrDefault();
                if (existingUserCollection != null)
                {
                    // see if the name is the same, if not, overwrite
                    if (!existingUserCollection.Name.Equals(timelapseName))
                    {
                        existingUserCollection.Name = timelapseName;
                        Unit.Commit();
                    }

                    return existingUserCollection.ID;
                }
                else
                {
                    if (!String.IsNullOrWhiteSpace(photoIds))
                    {
                        ids = photoIds.Split(',').Select(i => Convert.ToInt64(i)).ToArray();
                        photos = PhotoRepository.Find(p => ids.Contains(p.ID), p => p.Site).ToList();

                        Collection c = new Collection()
                        {
                            Name = timelapseName,
                            ContainerID = containerID.ToString(),
                            Owner = user,
                            Type = CollectionType.TIMELAPSE,
                            Status = CollectionStatus.COMPLETE,
                            Photos = photos
                        };
                        CollectionRepository.Insert(c);
                        Unit.Commit();

                        return c.ID;
                    }
                }
            }
            else
            {
                // Since the user is not logged in, check if an un-owned copy of this collection exists
                Collection existingCollection = CollectionRepository.Find(c => c.ContainerID == containerID & c.Owner == null).FirstOrDefault();
                if (existingCollection != null)
                {
                    return existingCollection.ID;
                }
                else
                {
                    if (!String.IsNullOrWhiteSpace(photoIds))
                    {
                        ids = photoIds.Split(',').Select(i => Convert.ToInt64(i)).ToArray();
                        photos = PhotoRepository.Find(p => ids.Contains(p.ID), p => p.Site).ToList();

                        Collection c = new Collection()
                        {
                            Name = timelapseName,
                            ContainerID = containerID.ToString(),
                            Owner = null,
                            Type = CollectionType.TIMELAPSE,
                            Status = CollectionStatus.COMPLETE,
                            Photos = photos
                        };
                        CollectionRepository.Insert(c);
                        Unit.Commit();

                        return c.ID;
                    }
                }
            }

            // something went wrong, so return -1
            return -1;
        }
 public MobileIdentityPrincipal(User identity)
     : base(new GenericIdentity(identity.ProviderID), new string[] { identity.Role == UserRole.ADMIN ? "Admin" : "User" })
 {
     this.Identity = identity;
 }
        public ActionResult LoginCallback(string returnUrl)
        {
            AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("LoginCallback", new { ReturnUrl = returnUrl }));
            if (!result.IsSuccessful)
            {
                return RedirectToAction("LoginFailure");
            }

            if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false))
            {
                return RedirectToLocal(returnUrl);
            }

            if (User.Identity.IsAuthenticated)
            {
                // If the current user is logged in add the new account
                OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, User.Identity.Name);
                return RedirectToLocal(returnUrl);
            }
            else
            {
                // User is new, ask for their desired membership name
                string loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId);
                ViewBag.ReturnUrl = returnUrl;

                string email = "";
                string name = "";
                result.ExtraData.TryGetValue("username", out email);
                result.ExtraData.TryGetValue("name", out name);

                User tempUser = new User();
                tempUser.EmailAddress = email;

                string[] names = name.Split(' ');
                if (names.Count() > 0)
                {
                    tempUser.FirstName = names[0];
                }
                if (names.Count() > 1)
                {
                    tempUser.LastName = names[1];
                }

                return View("RegisterAccount", new RegisterUserModel { ProviderUserName = result.UserName, ProviderData = loginData, User = tempUser});
            }
        }