Exemple #1
0
 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;
         }
     }
 }
Exemple #2
0
 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;
         }
     }
 }
Exemple #3
0
 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;
         }
     }
 }
Exemple #4
0
 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;
         }
     }
 }
Exemple #5
0
 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;
         }
     }
 }
Exemple #6
0
 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;
         }
     }
 }
Exemple #7
0
        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;
                }
            }
        }