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)); } }
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(); } } }
public List <File> GetAllFiles() { using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer()) { return(context.Files.ToList <File>()); } }
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(); } } }
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)); } }
public List <Keyword> GetAllKeywords() { using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer()) { return(context.Keywords.ToList <Keyword>()); } }
public List <Person> GetAllPeople() { using (MemoriesManagerModelContainer context = new MemoriesManagerModelContainer()) { return(context.People.ToList()); } }
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); } }
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); } }
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); } }
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)); } }
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); } } }
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); } } }
//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); } }
//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); } }
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); } }
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); } }
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); } }