Esempio n. 1
0
        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 }));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        /// <summary>
        /// Populate DB with movie returned by API
        /// </summary>
        /// <param name="infos">Movie information</param>
        /// <param name="credit">Cast and crew linked to movie</param>
        /// <param name="originalName">Orignial Name of the movie</param>
        /// <param name="originalFilePath">Original name of the file</param>
        private void PopulateDB(Movie infos, Credits credit, string originalName, string originalFilePath)
        {
            MovieRepository      _movieRepo      = new MovieRepository();
            CollectionRepository _collectionRepo = new CollectionRepository();
            CrewRepository       _crewrepo       = new CrewRepository();
            CastRepository       _castrepo       = new CastRepository();
            CompanyRepository    _companyrepo    = new CompanyRepository();
            CountryRepository    _countryrepo    = new CountryRepository();
            GenreRepository      _genrerepo      = new GenreRepository();
            LanguageRepository   _languagerepo   = new LanguageRepository();


            bool collectionAdded = false;

            if (infos.BelongsToCollection != null)
            {
                fmmCollection collection = new fmmCollection {
                    id     = infos.BelongsToCollection.Id,
                    name   = infos.BelongsToCollection.Name,
                    poster = infos.BelongsToCollection.PosterPath
                };
                _collectionRepo.Insert(collection);

                collectionAdded = true;
            }

            fmmMovie movie = new fmmMovie {
                id          = infos.Id,
                imdbid      = infos.ImdbId,
                title       = infos.Title,
                ogtitle     = originalName,
                filename    = Path.GetFileName(originalFilePath),
                filepath    = originalFilePath,
                adult       = infos.Adult,
                budget      = infos.Budget,
                homepage    = infos.Homepage,
                runtime     = infos.Runtime,
                tagline     = infos.Tagline,
                voteaverage = infos.VoteAverage,
                oglanguage  = infos.OriginalLanguage,
                overview    = infos.Overview,
                popularity  = infos.Popularity,
                poster      = infos.PosterPath,
                releasedate = infos.ReleaseDate.ToString().Substring(0, 10)
            };

            if (collectionAdded)
            {
                movie.fk_collection = infos.BelongsToCollection.Id;
            }

            bool movieAdded = _movieRepo.Insert(movie);

            foreach (Crew crew in credit.Crew)
            {
                var ncrew = new fmmCrew {
                    id         = crew.Id,
                    creditid   = crew.CreditId,
                    name       = crew.Name,
                    image      = crew.ProfilePath,
                    department = crew.Department,
                    job        = crew.Job
                };

                _crewrepo.Insert(ncrew, movie.id);
            }

            foreach (Cast cast in credit.Cast)
            {
                var ncast = new fmmCast {
                    id        = cast.Id,
                    castid    = cast.CastId,
                    creditid  = cast.CreditId,
                    name      = cast.Name,
                    image     = cast.ProfilePath,
                    character = cast.Character,
                    aorder    = cast.Order
                };

                _castrepo.Insert(ncast, movie.id);
            }

            foreach (ProductionCompany company in infos.ProductionCompanies)
            {
                var ncompany = new fmmCompany {
                    id   = company.Id,
                    name = company.Name,
                };

                _companyrepo.Insert(ncompany, movie.id);
            }

            foreach (ProductionCountry country in infos.ProductionCountries)
            {
                var ncountry = new fmmCountry {
                    name = country.Name,
                };

                _countryrepo.Insert(ncountry, movie.id);
            }

            foreach (Genre genre in infos.Genres)
            {
                var ngenre = new fmmGenre {
                    id   = genre.Id,
                    name = genre.Name,
                };

                _genrerepo.Insert(ngenre, movie.id);
            }


            foreach (SpokenLanguage language in infos.SpokenLanguages)
            {
                var nlanguage = new fmmLanguage {
                    name = language.Name,
                };

                _languagerepo.Insert(nlanguage, movie.id);
            }
        }
Esempio n. 6
0
        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);
        }