private SiteDetails GetDetailsForCollection(Collection collection)
        {
            SiteDetails details = PhotoRepository.GetSiteDetails(collection.Site);
            details.CoverPhotoID = collection.CoverPhoto == null ? details.LastPhotoID : collection.CoverPhoto.ID;

            return details;
        }
Beispiel #2
0
 public void FinishCollectionProcessing(Collection collection)
 {
     collection.Status = CollectionStatus.COMPLETE;
     CollectionRepository.Update(collection);
 }
Beispiel #3
0
        public Collection GetCollectionForProcessing(XmlNode siteData)
        {
            string siteName = siteData["Folder"].InnerText;
            CameraSite site = SiteRepository.Find(s => s.Name == siteName).FirstOrDefault();
            Collection collection = null;

            if (site == null)
            {
                site = new CameraSite();
                site.Name = siteData["Folder"].InnerText;
                site.DirectoryName = siteData["Folder"].InnerText;
                site.ContainerID = Guid.NewGuid().ToString();
                if (siteData["Location"].Attributes["latitude"].Value != String.Empty)
                {
                    site.Latitude = Convert.ToDouble(siteData["Location"].Attributes["latitude"].Value);
                    site.Longitude = Convert.ToDouble(siteData["Location"].Attributes["longitude"].Value);
                }

                var county = siteData["County"].InnerText;
                var state = siteData["State"].InnerText;
                site.CountyFips = DMRepository.GetFipsForCountyAndState(county, state);

                collection = new Collection()
                {
                    ContainerID = site.ContainerID,
                    Name = site.Name,
                    Site = site,
                    Status = CollectionStatus.PROCESSING,
                    Type = CollectionType.SITE
                };

                CollectionRepository.Insert(collection);
                SiteRepository.Insert(site);
            }
            else
            {
                collection = CollectionRepository.Find(c => c.Site.ID == site.ID).FirstOrDefault();
                collection.Status = CollectionStatus.PROCESSING;
                CollectionRepository.Update(collection);
            }

            return collection;
        }
        public long CreateUserCameraSite(NewUserSiteModel model)
        {
            User user = UserRepository.First(u => u.ProviderID == this.User.Identity.Name);
            string guid = Guid.NewGuid().ToString();

            CameraSite newCameraSite = new CameraSite()
            {
                Name = model.SiteName,
                Latitude = model.Latitude,
                Longitude = model.Longitude,
                CountyFips = DroughtMonitorRepository.GetFipsForCountyAndState(model.County, model.State),
                ContainerID = guid,
                DirectoryName = guid
            };

            Collection newCollection = new Collection()
            {
                Name = model.SiteName,
                Site = newCameraSite,
                Owner = user,
                ContainerID = guid,
                Type = CollectionType.USER
            };

            CollectionRepository.Insert(newCollection);
            Unit.Commit();

            return newCollection.ID;
        }
 public void UpdateUserCollection(Collection collection)
 {
     collection.Status = CollectionStatus.COMPLETE;
     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 ActionResult CreateUserSite(AddUserCameraSite site)
        {
            User user = UserRepository.First(u => u.ProviderID == this.User.Identity.Name);
            string guid = Guid.NewGuid().ToString();

            CameraSite newCameraSite = new CameraSite()
            {
                Name = site.CameraSiteName,
                Latitude = site.Latitude,
                Longitude = site.Longitude,
                CountyFips = DroughtMonitorRepository.GetFipsForCountyAndState(site.County, site.State),
                ContainerID = guid,
                DirectoryName = guid
            };

            Collection newCollection = new Collection()
            {
                Name = site.CameraSiteName,
                Site = newCameraSite,
                Owner = user,
                ContainerID = guid,
                Type = CollectionType.USER
            };

            CollectionRepository.Insert(newCollection);
            Unit.Commit();

            return RedirectToAction("UploadPhotos", new { @collectionID = newCollection.ID });
        }