Beispiel #1
0
 /// <summary>
 /// Gets the packages.
 /// </summary>
 /// <returns>
 /// get all packages
 /// </returns>
 public IList<Package> GetPackages()
 {
     lock (this.dataContextLock)
     {
         this.CreateDBIfNotExist();
         using (var dataContext = new DBContext())
         {
             return dataContext.PackageTable.OrderByDescending(m => m.PackageId).ToList();
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Inserts the or update package.
        /// </summary>
        /// <param name="package">The package.</param>
        public void InsertOrUpdatePackage(Package package)
        {
            lock (this.dataContextLock)
            {
                this.CreateDBIfNotExist();
                using (var dataContext = new DBContext())
                {
                    var queryPackage = from item in dataContext.PackageTable where item.PackageId == package.PackageId select item;
                    if (queryPackage.Any())
                    {
                        Package databasePackage = queryPackage.First();
                        databasePackage.CopyFrom(package);
                    }
                    else
                    {
                        dataContext.PackageTable.InsertOnSubmit(package);
                    }

                    dataContext.SubmitChanges();
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Creates the DB if not exist.
 /// </summary>
 private void CreateDBIfNotExist()
 {
     lock (this.dataContextLock)
     {
         using (var dataContext = new DBContext())
         {
             if (!dataContext.DatabaseExists())
             {
                 dataContext.CreateDatabase();
             }
         }
     }
 }