bool ILitedbDAL.InsertPerson(Person person) { using (var db = new LiteDatabase(LitedbConn.ConnString())) { var personsTbl = db.GetCollection <Person>(PersonsTable); try { personsTbl.Insert(person); personsTbl.EnsureIndex(x => x.PkIdPerson); //if (person.Binary.FileBytes.Length > 50) //{ // var binariesTbl = db.GetCollection<Binary>(BinariesTable); // try // { // binariesTbl.Insert(person.Binary); // binariesTbl.EnsureIndex(x => x.PkIdBinary); // return true; // } // catch (Exception ex) // { // Log2Txt.Instance.ErrorLog(ex.ToString()); // throw; // } //} return(true); } catch (Exception ex) { Log2Txt.Instance.ErrorLog(ex.ToString()); throw; } } }
Binary ILitedbDAL.ReadBinary(ObjectId id) { using (var db = new LiteDatabase(LitedbConn.ConnString())) { var binariesTbl = db.GetCollection <Binary>(BinariesTable); try { return(binariesTbl.FindById(id)); } catch (Exception ex) { Log2Txt.Instance.ErrorLog(ex.ToString()); throw; } } }
Person ILitedbDAL.ReadPerson(ObjectId id) { using (var db = new LiteDatabase(LitedbConn.ConnString())) { var personsTbl = db.GetCollection <Person>(PersonsTable); try { return(personsTbl //.Include(x => x.Binary) .FindById(id)); } catch (Exception ex) { Log2Txt.Instance.ErrorLog(ex.ToString()); throw; } } }
bool ILitedbDAL.UpdatePerson(Person person) { using (var db = new LiteDatabase(LitedbConn.ConnString())) { var personsTbl = db.GetCollection <Person>(PersonsTable); try { personsTbl.Update(person); personsTbl.EnsureIndex(x => x.PkIdPerson); return(true); } catch (Exception ex) { Log2Txt.Instance.ErrorLog(ex.ToString()); throw; } } }
bool ILitedbDAL.UpdateContact(Contact contact) { using (var db = new LiteDatabase(LitedbConn.ConnString())) { var contactsTbl = db.GetCollection <Contact>(ContactsTable); try { contactsTbl.Update(contact); contactsTbl.EnsureIndex(x => x.PkIdContact); return(true); } catch (Exception ex) { Log2Txt.Instance.ErrorLog(ex.ToString()); throw; } } }
bool ILitedbDAL.InsertBinary(Binary binary) { using (var db = new LiteDatabase(LitedbConn.ConnString())) { var binariesTbl = db.GetCollection <Binary>(BinariesTable); try { binariesTbl.Insert(binary); binariesTbl.EnsureIndex(x => x.PkIdBinary); return(true); } catch (Exception ex) { Log2Txt.Instance.ErrorLog(ex.ToString()); throw; } } }
ObservableCollection <Person> ILitedbDAL.ListPersons(string search, string empty1, string empty2, string empty3) { var searchWords = search.RemoveDiacritics().ToUpper().Split(' '); using (var db = new LiteDatabase(LitedbConn.ConnString())) { var personsTbl = db.GetCollection <Person>(PersonsTable); try { var results = personsTbl.FindAll() .Where(x => searchWords.All(x.Name.RemoveDiacritics().ToUpper().Contains) || searchWords.All(x.Company.RemoveDiacritics().ToUpper().Contains)) .OrderBy(x => x.Name) .Take(250); return(results.AsEnumerable().ToObservableCollection <Person>()); } catch (Exception ex) { Log2Txt.Instance.ErrorLog(ex.ToString()); throw; } } }