コード例 #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));
     }
 }
コード例 #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();
         }
     }
 }
コード例 #3
0
 public List <File> GetAllFiles()
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         return(context.Files.ToList <File>());
     }
 }
コード例 #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();
         }
     }
 }
コード例 #5
0
ファイル: Keyword.cs プロジェクト: AlexandruDenis98/TSP.NET
 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));
     }
 }
コード例 #6
0
ファイル: Keyword.cs プロジェクト: AlexandruDenis98/TSP.NET
 public List <Keyword> GetAllKeywords()
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         return(context.Keywords.ToList <Keyword>());
     }
 }
コード例 #7
0
 public List <Person> GetAllPeople()
 {
     using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer())
     {
         return(context.People.ToList());
     }
 }
コード例 #8
0
ファイル: Keyword.cs プロジェクト: AlexandruDenis98/TSP.NET
 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);
     }
 }
コード例 #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);
     }
 }
コード例 #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);
     }
 }
コード例 #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));
     }
 }
コード例 #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);
         }
     }
 }
コード例 #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);
         }
     }
 }
コード例 #14
0
ファイル: Keyword.cs プロジェクト: AlexandruDenis98/TSP.NET
 //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);
     }
 }
コード例 #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);
     }
 }
コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #18
0
ファイル: Keyword.cs プロジェクト: AlexandruDenis98/TSP.NET
 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);
     }
 }