示例#1
0
        //public static SalesContext db = new SalesContext();

        //public static Customer CloneCustomer(Customer SelectedItem)
        //{
        //    using (var db = new SalesContext())
        //    {
        //        var item = db.Customers.Find(SelectedItem.Id);
        //        item.CustomerRank = CustomerRanks.Where(p => p.Id == item.CustomerRankID).Single();
        //        return item;
        //    }
        //}

        #endregion

        #region Asset
        public async static Task GetAllAssets()
        {
            Assets.Clear();
            AssetCategories.Clear();
            using (var db = new SalesContext())
            {
                var result  = await(from c in db.Assets select c).ToListAsync();
                var result1 = await(from c in db.AssetCategories.Include("Assets") select c).ToListAsync();
                var result2 = await(from c in db.Departments.Include("Assets") select c).ToListAsync();
                var result3 = await(from c in db.InstallationLocations.Include("Assets") select c).ToListAsync();
                foreach (Asset item in result)
                {
                    Assets.Add(item);
                }
                foreach (AssetCategory item in result1)
                {
                    AssetCategories.Add(item);
                }
                foreach (Department item in result2)
                {
                    Departments.Add(item);
                }
                foreach (InstallationLocation item in result3)
                {
                    InstallationLocations.Add(item);
                }
            }
        }
示例#2
0
        public object Get(AssetCategories request)
        {
            ApiUser hdUser = request.ApiUser;

            CheckAssets(hdUser);
            return(Models.AssetCategories.GetAssetCategories(hdUser.OrganizationId, hdUser.DepartmentId));
        }
示例#3
0
 public async static Task DeleteAssetCategory(AssetCategory itemPara)
 {
     using (var db = new SalesContext())
     {
         db.Entry(itemPara).State = EntityState.Unchanged;   //NOT DELETE - IMPORTANT
         AssetCategories.Remove(itemPara);
         db.Entry(itemPara).State = EntityState.Deleted;     // must be executed after deleted it in AssetCategories
         await UpdateDatabase(db);
     }
 }
示例#4
0
        public async static Task AddAssetCategory(AssetCategory itemPara)
        {
            using (var db = new SalesContext())
            {
                db.AssetCategories.Add(itemPara);
                await UpdateDatabase(db);

                AssetCategories.Add(itemPara);
            }
        }
示例#5
0
 public async static Task DeleteManyAssetCategories(IList itemParas)
 {
     using (var db = new SalesContext())
     {
         List <AssetCategory> list = new List <AssetCategory>();
         foreach (object item in itemParas)
         {
             list.Add((AssetCategory)item);
         }
         foreach (AssetCategory item in list)
         {
             db.Entry(item).State = EntityState.Unchanged;
             AssetCategories.Remove(item);
             db.Entry(item).State = EntityState.Deleted;
         }
         await UpdateDatabase(db);
     }
 }