Example #1
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();
         }
     }
 }
Example #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();
         }
     }
 }
Example #3
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);
     }
 }
Example #4
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);
     }
 }
Example #5
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);
     }
 }