Example #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();
         }
     }
 }
Example #2
0
 /// <summary>
 /// Gets the package.
 /// </summary>
 /// <param name="packageId">The package id.</param>
 /// <returns>
 /// package id
 /// </returns>
 public Package GetPackage(int packageId)
 {
     lock (this.dataContextLock)
     {
         this.CreateDBIfNotExist();
         using (var dataContext = new DBContext())
         {
             var queryPackage = from item in dataContext.PackageTable where item.PackageId == packageId select item;
             if (queryPackage.Any())
             {
                 return queryPackage.First();
             }
             else
             {
                 return null;
             }
         }
     }
 }
Example #3
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();
                }
            }
        }
Example #4
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();
             }
         }
     }
 }