public async Task UpdateASMasterProduct(ASMasterProduct objASMasterProduct) { try { _Context.Entry(objASMasterProduct).State = EntityState.Modified; await _Context.SaveChangesAsync(); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task<ActionResult<MasterProductResult>> PostASMasterProduct(ASMasterProductMerge objASMasterProductMerge) { try { await _IMasterProductInterface.InsertASMasterProduct(objASMasterProductMerge); ASMasterProduct objASMasterProduct = objASMasterProductMerge.ASMasterProduct; return CreatedAtAction("GetASMasterProduct", new { id = objASMasterProduct.MasterProductId }, objASMasterProduct); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task<ActionResult<MasterProductResult>> PutASMasterProduct(long id, ASMasterProduct objASMasterProduct) { if (id != objASMasterProduct.MasterProductId) { return BadRequest(); } try { await _IMasterProductInterface.UpdateASMasterProduct(objASMasterProduct); return _IMasterProductInterface.GetASMasterProductByID(id); } catch (DbUpdateConcurrencyException) { if (!_IMasterProductInterface.ASMasterProductExists(id)) { 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); } } }