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 <ActionResult <MasterProductChildResult> > PutASMasterProductChild(long MasterProductChildid, ASMasterProductChild objADMasterProductChild) { if (MasterProductChildid != objADMasterProductChild.MasterProductChildId) { return(BadRequest()); } try { await _IMasterProductChildInterface.UpdateASMasterProductChild(objADMasterProductChild); return(_IMasterProductChildInterface.GetASMasterProductChildByID(MasterProductChildid)); } catch (DbUpdateConcurrencyException) { if (!_IMasterProductChildInterface.ASMasterProductChildExists(MasterProductChildid)) { return(NotFound()); } else { throw; } } catch (Exception ex) { throw new Exception(ex.Message); } return(NoContent()); }
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 <ActionResult <MasterProductChildResult> > PostASMasterProductChild(ASMasterProductChild objADMasterProductChild) { try { await _IMasterProductChildInterface.InsertASMasterProductChild(objADMasterProductChild); return(CreatedAtAction("GetASMasterProductChild", new { id = objADMasterProductChild.MasterProductChildId }, objADMasterProductChild)); } catch (Exception ex) { throw new Exception(ex.Message); } }