Esempio n. 1
0
        void UpdateRoles(Person person, List <GridDataRow> roles)
        {
            var context = new RSMDataModelDataContext();

            var thisPersonRoles = from r in context.PeopleRoles
                                  where r.PersonID == person.PersonID
                                  select r;

            if (thisPersonRoles.Count() > 0)
            {
                context.PeopleRoles.DeleteAllOnSubmit(thisPersonRoles);
            }

            context.SubmitChanges();

            PeopleRole role;


            foreach (GridDataRow row in roles)
            {
                role             = new PeopleRole();
                role.RoleID      = int.Parse(row.ID);
                role.PersonID    = person.PersonID;
                role.IsException = (row.Exception != "0");

                person.PeopleRoles.Add(role);
            }



            context.SubmitChanges();
        }
Esempio n. 2
0
        public static void RemoveAllPersons(Title title, PeopleRole type)
        {
            var deletePersons = from d in Dao.DBContext.Instance.Persons
                                where d.Role == (byte)type
                                select d;

            foreach (Dao.Person daoperson in deletePersons)
            {
                title.DaoTitle.People.Remove(daoperson);
            }
        }
Esempio n. 3
0
        public void ActorToPeople()
        {
            Actor actor = new()
            {
                Id    = 5,
                Image = "image",
                Name  = "Name",
                Role  = "role"
            };
            PeopleRole people = actor.ToPeopleRole();

            Assert.Equal("name", people.Slug);
            Assert.Equal("Name", people.People.Name);
            Assert.Equal("role", people.Role);
            Assert.Equal("https://www.thetvdb.com/banners/image", people.People.Images[Images.Poster]);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a person object from a given name and role.  Will check the db first to see if that person exists
        /// </summary>
        /// <param name="name"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        public static Person CreatePerson(OMLDataDataContext context, string name, string characterName, PeopleRole role, Dictionary<string, BioData> existingPeople)
        {
            BioData metaData = null;

            // see if the actor exists already in the in memory cache
            existingPeople.TryGetValue(name, out metaData);

            if (metaData == null)
            {
                // Ok, we may not have allready created but first check if sql thinks it has
                // SQL thinks 'æ' and 'ae' are so lets double check the database
                metaData = Dao.TitleCollectionDao.GetPersonBioDataByName(context, name);
            }

            if (metaData == null)
            {
                System.Diagnostics.Trace.WriteLine("Adding Bio for - " + name);
                // if it doesn't exist create a new one
                metaData = new BioData();
                metaData.FullName = name;
                context.BioDatas.InsertOnSubmit(metaData);
                context.SubmitChanges();

                // add the new metaData we added to the dictionary so we don't add it again
                existingPeople.Add(name, metaData);
            }
            else
            {
                System.Diagnostics.Trace.WriteLine("Found Bio for - " + name + " : Fullname - " + metaData.FullName);
            }

            // setup the person
            Person person = new Person();
            person.MetaData = metaData;
            person.Role = (byte)role;

            if (!string.IsNullOrEmpty(characterName))
            {
                person.CharacterName = characterName;
            }

            return person;
        }
Esempio n. 5
0
 /// <summary>
 /// Gets all the people and their count of movies
 /// </summary>
 /// <returns></returns>
 public static IEnumerable <FilteredCollection> GetAllPeople(List <TitleFilter> filter, PeopleRole role)
 {
     return(Dao.TitleCollectionDao.GetAllPersons(filter, role));
 }
Esempio n. 6
0
        private static void ProcessPersonList(Dao.Title title, List<OMLEngine.Person> updatedList, PeopleRole role)
        {
            IEnumerable<string> originals = from a in title.People
                                                  where a.Role == (byte)role
                                                  select a.MetaData.FullName;

            List<string> added = new List<string>(updatedList.Where(t => !originals.Contains(t.full_name)).Select(t => t.full_name));
            List<string> removed = new List<string>(originals.Where(t => !updatedList.Select(r => r.full_name).Contains(t)));

            // remove ones no longer used
            foreach (string remove in removed)
            {
                Dao.Person person = title.People.SingleOrDefault(p => p.MetaData.FullName == remove && p.Role == (byte)role);

                if (person != null)
                    title.People.Remove(person);
            }

            // add the new ones
            foreach (string add in added)
            {
                if (!string.IsNullOrEmpty(add))
                {
                    AddActorToTitle(title, add, null, role);
                }
            }
        }
Esempio n. 7
0
        private static void AddActorToTitle(Dao.Title title, string actor, string role, PeopleRole type)
        {
            if (actor.Length > 255)
                throw new FormatException("Actor must be 255 characters or less.");
            if (role != null && role.Length > 255)
                throw new FormatException("Role must be 255 characters or less.");

            if (string.IsNullOrEmpty(actor))
                return;

            Dao.BioData bioData = Dao.TitleCollectionDao.GetPersonBioDataByName(actor);

            if (bioData == null)
            {
                bioData = new OMLEngine.Dao.BioData();
                bioData.FullName = actor;
                Dao.DBContext.Instance.BioDatas.InsertOnSubmit(bioData);
                Dao.DBContext.Instance.SubmitChanges();
            }

            Dao.Person person = new OMLEngine.Dao.Person();
            person.MetaData = bioData;
            person.CharacterName = role;
            person.Role = (byte)type;
            title.People.Add(person);
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a person object from a given name and role.  Will check the db first to see if that person exists
        /// </summary>
        /// <param name="name"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        public static Person CreatePerson(OMLDataDataContext context, string name, string characterName, PeopleRole role, Dictionary <string, BioData> existingPeople)
        {
            BioData metaData = null;

            // see if the actor exists already in the in memory cache
            existingPeople.TryGetValue(name, out metaData);

            if (metaData == null)
            {
                // Ok, we may not have allready created but first check if sql thinks it has
                // SQL thinks 'æ' and 'ae' are so lets double check the database
                metaData = Dao.TitleCollectionDao.GetPersonBioDataByName(context, name);
            }

            if (metaData == null)
            {
                System.Diagnostics.Trace.WriteLine("Adding Bio for - " + name);
                // if it doesn't exist create a new one
                metaData          = new BioData();
                metaData.FullName = name;
                context.BioDatas.InsertOnSubmit(metaData);
                context.SubmitChanges();

                // add the new metaData we added to the dictionary so we don't add it again
                existingPeople.Add(name, metaData);
            }
            else
            {
                System.Diagnostics.Trace.WriteLine("Found Bio for - " + name + " : Fullname - " + metaData.FullName);
            }

            // setup the person
            Person person = new Person();

            person.MetaData = metaData;
            person.Role     = (byte)role;

            if (!string.IsNullOrEmpty(characterName))
            {
                person.CharacterName = characterName;
            }

            return(person);
        }
Esempio n. 9
0
        private static void AddActorToTitle(Dao.Title title, string actor, string role, PeopleRole type)
        {
            if (actor.Length > 255)
            {
                throw new FormatException("Actor must be 255 characters or less.");
            }
            if (role != null && role.Length > 255)
            {
                throw new FormatException("Role must be 255 characters or less.");
            }

            if (string.IsNullOrEmpty(actor))
            {
                return;
            }

            Dao.BioData bioData = Dao.TitleCollectionDao.GetPersonBioDataByName(actor);

            if (bioData == null)
            {
                bioData          = new OMLEngine.Dao.BioData();
                bioData.FullName = actor;
                Dao.DBContext.Instance.BioDatas.InsertOnSubmit(bioData);
                Dao.DBContext.Instance.SubmitChanges();
            }

            Dao.Person person = new OMLEngine.Dao.Person();
            person.MetaData      = bioData;
            person.CharacterName = role;
            person.Role          = (byte)type;
            title.People.Add(person);
        }
Esempio n. 10
0
        private static void ProcessPersonList(Dao.Title title, List <OMLEngine.Person> updatedList, PeopleRole role)
        {
            IEnumerable <string> originals = from a in title.People
                                             where a.Role == (byte)role
                                             select a.MetaData.FullName;

            List <string> added   = new List <string>(updatedList.Where(t => !originals.Contains(t.full_name)).Select(t => t.full_name));
            List <string> removed = new List <string>(originals.Where(t => !updatedList.Select(r => r.full_name).Contains(t)));

            // remove ones no longer used
            foreach (string remove in removed)
            {
                Dao.Person person = title.People.SingleOrDefault(p => p.MetaData.FullName == remove && p.Role == (byte)role);

                if (person != null)
                {
                    title.People.Remove(person);
                }
            }

            // add the new ones
            foreach (string add in added)
            {
                if (!string.IsNullOrEmpty(add))
                {
                    AddActorToTitle(title, add, null, role);
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Returns all the people in the given titles
        /// </summary>
        /// <param name="filters"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        public static IEnumerable <FilteredCollection> GetAllPersons(List <TitleFilter> filters, PeopleRole role)
        {
            var filteredPeople = DBContext.Instance.Persons.Where(GetPersonPredicate(filters));

            return(from t in GetFilteredTitlesWrapper(filters)
                   from p in filteredPeople
                   where p.TitleId == t.Id
                   where p.Role == (byte)role
                   join b in DBContext.Instance.BioDatas on p.BioId equals b.Id
                   group b by b.FullName into g
                   orderby g.Key ascending
                   select new FilteredCollection()
            {
                Name = g.Key, Count = g.Count()
            });
        }
Esempio n. 12
0
 /// <summary>
 /// Returns all the titles for the given name in the given role
 /// </summary>
 /// <param name="titles"></param>
 /// <param name="name"></param>
 /// <param name="role"></param>
 /// <returns></returns>
 private static IQueryable <Title> ApplyPersonFilter(IQueryable <Title> titles, string name, PeopleRole role, bool notEquals)
 {
     if (notEquals)
     {
         return((from t in titles
                 from p in t.People
                 where p.MetaData.FullName != name && p.Role != (byte)role
                 select t).Distinct());
     }
     else
     {
         return((from t in titles
                 from p in t.People
                 where p.MetaData.FullName == name && p.Role == (byte)role
                 select t).Distinct());
     }
 }
        public static void RemoveAllPersons(Title title, PeopleRole type)
        {
            var deletePersons = from d in Dao.DBContext.Instance.Persons
                                where d.Role == (byte)type
                                select d;

            foreach (Dao.Person daoperson in deletePersons)
            {
                title.DaoTitle.People.Remove(daoperson);
            }
        }
 /// <summary>
 /// Gets all the people and their count of movies
 /// </summary>
 /// <returns></returns>
 public static IEnumerable<FilteredCollection> GetAllPeople(List<TitleFilter> filter, PeopleRole role)
 {
     return Dao.TitleCollectionDao.GetAllPersons(filter, role);
 }