//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); } } }
public object Get(AssetCategories request) { ApiUser hdUser = request.ApiUser; CheckAssets(hdUser); return(Models.AssetCategories.GetAssetCategories(hdUser.OrganizationId, hdUser.DepartmentId)); }
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); } }
public async static Task AddAssetCategory(AssetCategory itemPara) { using (var db = new SalesContext()) { db.AssetCategories.Add(itemPara); await UpdateDatabase(db); AssetCategories.Add(itemPara); } }
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); } }