Exemplo n.º 1
0
 public int DeletePerson(int id)
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         return(context.Database.ExecuteSqlCommand("Delete From FilePerson where People_Id = @p0; Delete From People where Id = @p0", id));
     }
 }
Exemplo n.º 2
0
 public void InsertKeywordIntoFile(string kword, string filePath)
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         var keyword = context.Keywords.SingleOrDefault(k => k.Kword == kword);
         var file    = context.Files.SingleOrDefault(f => f.Path == filePath);
         //retrive all keywords of the file
         var keywords = context.Files
                        .Where(f => f.Path == filePath)
                        .SelectMany(k => k.Keywords);
         //test if file keywords contains parameter keyword
         bool exists = false;
         foreach (Keyword k in keywords)
         {
             if (k == keyword)
             {
                 exists = true;
             }
         }
         if (!exists)
         {
             file.Keywords.Add(keyword);
             context.SaveChanges();
         }
     }
 }
Exemplo n.º 3
0
 public List <File> GetAllFiles()
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         return(context.Files.ToList <File>());
     }
 }
Exemplo n.º 4
0
 public void InsertPersonIntoFile(int personId, string filePath)
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         var person = context.People.SingleOrDefault(p => p.Id == personId);
         var file   = context.Files.SingleOrDefault(f => f.Path == filePath);
         //retrive people of the file
         var people = context.Files
                      .Where(f => f.Path == filePath)
                      .SelectMany(p => p.People);
         //test if file people contains parameter person
         bool exists = false;
         foreach (Person p in people)
         {
             if (p == person)
             {
                 exists = true;
             }
         }
         if (!exists)
         {
             file.People.Add(person);
             context.SaveChanges();
         }
     }
 }
Exemplo n.º 5
0
 public int DeleteKeyword(int id)
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         return(context.Database.ExecuteSqlCommand("Delete From FileKeyword where Keywords_Id = @p0; Delete From Keywords where Id = @p0;", id));
     }
 }
Exemplo n.º 6
0
 public List <Keyword> GetAllKeywords()
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         return(context.Keywords.ToList <Keyword>());
     }
 }
Exemplo n.º 7
0
 public List <Person> GetAllPeople()
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         return(context.People.ToList());
     }
 }
Exemplo n.º 8
0
 public Keyword GetKeywordByKword(string Kword)
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         var query   = from k in context.Keywords where k.Kword == Kword select k;
         var keyword = query.FirstOrDefault <Keyword>();
         return(keyword);
     }
 }
Exemplo n.º 9
0
 public Person GetPersonByName(string First_name, string Last_name)
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         var query  = from p in context.People where p.First_name == First_name && p.Last_name == Last_name select p;
         var person = query.FirstOrDefault <Person>();
         return(person);
     }
 }
Exemplo n.º 10
0
 public File GetFileByPath(string filePath)
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         var query = from f in context.Files where f.Path == filePath select f;
         var file  = query.FirstOrDefault <File>();
         return(file);
     }
 }
Exemplo n.º 11
0
 public int DeleteFileByPath(string filePath)
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         var query = from f in context.Files where f.Path == filePath select f;
         var file  = query.FirstOrDefault <File>();
         return(context.Database.ExecuteSqlCommand("Delete From FilePerson where Files_FileId = @p1 ;Delete From FileKeyword where Files_FileId = @p1;" +
                                                   "Delete From Files where Path = @p0;", filePath, file.FileId));
     }
 }
Exemplo n.º 12
0
 public void DeleteKeywordsFromFile(List <int> keywordsIds, string filePath)
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         var file = context.Files.First(f => f.Path == filePath);
         foreach (int kId in keywordsIds)
         {
             context.Database.ExecuteSqlCommand("Delete From FileKeyword where Files_FileId = @p0 and Keywords_Id = @p1;", file.FileId, kId);
         }
     }
 }
Exemplo n.º 13
0
 public void DeletePeopleFromFile(List <int> peopleIds, string filePath)
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         var file = context.Files.First(f => f.Path == filePath);
         foreach (int PersonId in peopleIds)
         {
             context.Database.ExecuteSqlCommand("Delete From FilePerson where Files_FileId = @p0 and People_Id = @p1;", file.FileId, PersonId);
         }
     }
 }
Exemplo n.º 14
0
 //Update a Keyword kword giving its id
 public Keyword UpdateKeywordKwordById(int id, string Kword)
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         var query   = from k in context.Keywords where k.Id == id select k;
         var keyword = query.FirstOrDefault <Keyword>();
         if (keyword != null)
         {
             keyword.Kword = Kword;
             context.SaveChanges();
         }
         return(keyword);
     }
 }
Exemplo n.º 15
0
 //Update a person name giving its id
 public Person UpdatePersonNameById(int id, string First_name, string Last_name)
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         var query  = from p in context.People where p.Id == id select p;
         var person = query.FirstOrDefault <Person>();
         if (person != null)
         {
             person.First_name           = First_name;
             person.Last_name            = Last_name;
             context.Entry(person).State = System.Data.Entity.EntityState.Modified;
             context.SaveChanges();
         }
         return(person);
     }
 }
Exemplo n.º 16
0
        public List <Person> GetPeopleFile(string filePath)
        {
            List <Person> peopleList = new List <Person>();

            using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
            {
                var file = context.Files.SingleOrDefault(f => f.Path == filePath);

                var query = from person in context.People
                            where person.Files.Any(f => f.FileId == file.FileId)
                            select person;

                var people = query.ToList <Person>();
                return(people);
            }
        }
Exemplo n.º 17
0
        public List <Keyword> GetKeywordsOfFile(string filePath)
        {
            List <Keyword> keywordsList = new List <Keyword>();

            using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
            {
                var file = context.Files.SingleOrDefault(f => f.Path == filePath);

                var query = from keyword in context.Keywords
                            where keyword.Files.Any(f => f.FileId == file.FileId)
                            select keyword;

                var keywords = query.ToList <Keyword>();
                return(keywords);
            }
        }
Exemplo n.º 18
0
 public bool CreateKeyword()
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         bool bResult = false;
         if (this == null)
         {
             return(bResult);
         }
         if (this.Id == 0)
         {
             context.Entry <Keyword>(this).State = EntityState.Added;
             context.SaveChanges();
             bResult = true;
         }
         return(bResult);
     }
 }