public async Task <IActionResult> PutUser(long id, User user) { if (id != user.Id) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutAssetNotes(long id, AssetNotes assetNotes) { if (id != assetNotes.IdNote) { return(BadRequest()); } _context.Entry(assetNotes).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AssetNotesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutAcquisitionMethod(int id, AcquisitionMethod acquisitionMethod) { if (id != acquisitionMethod.ID) { return(BadRequest()); } _context.Entry(acquisitionMethod).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AcquisitionMethodExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutConfiguration(int id, Configuration configuration) { if (id != configuration.IdConfig) { return(BadRequest()); } _context.Entry(configuration).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConfigurationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <IEnumerable <Asset> > > GetDepreciation(int id, bool project) { var depreciation = await _context.Depreciations.FindAsync(id); var _assets = _context.Assets.Where(x => x.Depreciation.Id == id); string oldDetails, newDetails; if (depreciation == null) { return(NotFound()); } foreach (var a in _assets) { var _newPrice = a.CurrentPrice - (a.CurrentPrice * depreciation.Percentage); oldDetails = a.ToString(); a.CurrentPrice = _newPrice; newDetails = a.ToString(); if (!project) { _context.AssetsHistory.Add(new AssetHistory() { AssetID = a.Id, NewDetails = newDetails, PreviewsDetails = oldDetails, UpdateDate = DateTime.Now }); } } if (!project) { await _context.SaveChangesAsync(); } return(_assets.ToList()); }
public async Task InsertASMasterProductType(ASMasterProductType objADMasterProductType) { try { _Context.ASMasterProductTypes.Add(objADMasterProductType); await _Context.SaveChangesAsync(); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task InsertASMasterCategory(ASMasterCategory objADMasterCategory) { try { _Context.ASMasterCategories.Add(objADMasterCategory); await _Context.SaveChangesAsync(); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task InsertASMasterBrand(ASMasterBrand objADMasterBrand) { try { _Context.ASMasterBrands.Add(objADMasterBrand); await _Context.SaveChangesAsync(); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <IActionResult> PutLocation(int id, Location location) { if (id != location.ID) { return(BadRequest()); } var _old = _context.Locations.FirstOrDefault(x => x.ID == id); if (_old.Responsible1 == null && _old.Responsible2 == null) { setReponsibleByLocation(location); } else if (_old.Responsible1.ID != location.Responsible1.ID && _old.Responsible2.ID != location.Responsible1.ID && _old.Responsible1.ID != location.Responsible2.ID && _old.Responsible2.ID != location.Responsible2.ID) { setReponsibleByLocation(location); } else if (_old.Responsible1.ID != location.Responsible1.ID && _old.Responsible1.ID != location.Responsible2.ID) { setReponsibleByLocation(location, true, false); } else if (_old.Responsible2.ID != location.Responsible1.ID && _old.Responsible2.ID != location.Responsible2.ID) { setReponsibleByLocation(location, false, true); } _old.Responsible1 = location.Responsible1; _old.Responsible2 = location.Responsible2; _context.Entry(_old).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LocationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutAsset(long id, Asset asset) { if (id != asset.Id) { return(BadRequest()); } var _asset = await _context.Assets.FindAsync(id); var props = typeof(Asset).GetProperties(); _context.AssetsHistory.Add(new AssetHistory() { AssetID = asset.Id, NewDetails = asset.ToString(), PreviewsDetails = _asset.ToString(), UpdateDate = DateTime.Now, Action = "Edit" }); foreach (var prop in props) { prop.SetValue(_asset, prop.GetValue(asset)); } _context.Entry(_asset).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AssetExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task InsertASTransactionProductHistory(ASTransactionProductHistory objADTransactionProductHistory) { using (var transaction = _Context.Database.BeginTransaction()) { try { _Context.ASTransactionProductHistorys.Add(objADTransactionProductHistory); await _Context.SaveChangesAsync(); ASMasterProductChild objASMasterProductChild = _Context.ASMasterProductChilds.Find(objADTransactionProductHistory.MasterProductChildId); objASMasterProductChild.WarrantyExpiryDate = objADTransactionProductHistory.SubscriptionExpiryDate; _Context.Entry(objASMasterProductChild).State = EntityState.Modified; await _Context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new Exception(ex.Message); } } }
public async Task InsertASMasterAssetsAssignment(ASMasterAssetsAssignment objADMasterAssetsAssignment) { try { _Context.ASMasterAssetsAssignments.Add(objADMasterAssetsAssignment); await _Context.SaveChangesAsync(); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task InsertASMasterProduct(ASMasterProductMerge objASMasterProductMerge) { using (var transaction = _Context.Database.BeginTransaction()) { try { ASMasterProduct objASMasterProduct = objASMasterProductMerge.ASMasterProduct; ASMasterProductChild objASMasterProductChild = objASMasterProductMerge.ASMasterProductChild; ASMasterAssetsAssignment objASMasterAssetsAssignment = objASMasterProductMerge.ASMasterAssetsAssignment; _Context.ASMasterProducts.Add(objASMasterProduct); await _Context.SaveChangesAsync(); objASMasterProductChild.MasterProductId = objASMasterProduct.MasterProductId; objASMasterProductChild.ProductChildTitle = objASMasterProduct.ProductTitle; objASMasterProductChild.IsActive = true; objASMasterProductChild.IsDeadAssets = false; objASMasterProductChild.IsSaleProduct = false; _Context.ASMasterProductChilds.Add(objASMasterProductChild); await _Context.SaveChangesAsync(); //Insert in TransactionProductHistory ASTransactionProductHistory objASTransactionProductHistory = new ASTransactionProductHistory(); if (objASMasterProductChild.MasterEmployeeId != null && objASMasterProductChild.MasterEmployeeId > 0) { objASTransactionProductHistory.MasterProductChildId = objASMasterProductChild.MasterProductChildId; objASTransactionProductHistory.MasterSubscriptionTypeId = 1; objASTransactionProductHistory.MasterSubscriptionVendorId = objASMasterProductChild.MasterVendorId; objASTransactionProductHistory.SubscriptionPrice = objASMasterProductChild.PurchasePrice; objASTransactionProductHistory.SubscriptionDate = objASMasterProductChild.PurchaseDate; objASTransactionProductHistory.SubscriptionStartDate = objASMasterProductChild.WarrantyStartDate; objASTransactionProductHistory.SubscriptionExpiryDate = objASMasterProductChild.WarrantyExpiryDate; _Context.ASTransactionProductHistorys.Add(objASTransactionProductHistory); await _Context.SaveChangesAsync(); } if (objASMasterProductChild.MasterEmployeeId != null && objASMasterProductChild.MasterEmployeeId > 0) { //ASMasterAssetsAssignment objASMasterAssetsAssignment.MasterAssetsAssignmentId = 0; objASMasterAssetsAssignment.IsActive = true; objASMasterAssetsAssignment.AssetsAssignmentDate = objASMasterAssetsAssignment.AssetsAssignmentDate; objASMasterAssetsAssignment.MasterProductChildId = objASMasterProductChild.MasterProductChildId; objASMasterAssetsAssignment.MasterEmployeeId = objASMasterProductChild.MasterEmployeeId; _Context.ASMasterAssetsAssignments.Add(objASMasterAssetsAssignment); await _Context.SaveChangesAsync(); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new Exception(ex.Message); } } }
public async Task <bool> SaveChangeAsync() { return((await _context.SaveChangesAsync()) > 0); }