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 UpdateASMasterAssetsAssignment(ASMasterAssetsAssignment objADMasterAssetsAssignment) { using (var transaction = _Context.Database.BeginTransaction()) { try { //Get MasterProductChild Detail var _MasterProductChild = _Context.ASMasterProductChilds.Find(objADMasterAssetsAssignment.MasterProductChildId); _MasterProductChild.MasterEmployeeId = objADMasterAssetsAssignment.MasterEmployeeId; _Context.Entry(_MasterProductChild).State = EntityState.Modified; await _Context.SaveChangesAsync(); ASMasterAssetsAssignment objASMasterAssetsAssignment = new ASMasterAssetsAssignment(); objASMasterAssetsAssignment.MasterAssetsAssignmentId = 0; //Assignment Date is passed through ManufacturingDate objASMasterAssetsAssignment.AssetsAssignmentDate = DateTime.Now; objASMasterAssetsAssignment.MasterProductChildId = _MasterProductChild.MasterProductChildId; objASMasterAssetsAssignment.MasterEmployeeId = _MasterProductChild.MasterEmployeeId; objASMasterAssetsAssignment.MasterLocationId = _MasterProductChild.MasterBranchId; objASMasterAssetsAssignment.IsActive = true; objASMasterAssetsAssignment.IsAssetsDeAssign = false; if (_MasterProductChild.MasterEmployeeId == 0) { objASMasterAssetsAssignment.IsActive = false; objASMasterAssetsAssignment.IsAssetsDeAssign = true; } objASMasterAssetsAssignment.EnterById = _MasterProductChild.EnterById; objASMasterAssetsAssignment.EnterDate = _MasterProductChild.EnterDate; objASMasterAssetsAssignment.ModifiedById = _MasterProductChild.ModifiedById; objASMasterAssetsAssignment.ModifiedDate = _MasterProductChild.ModifiedDate; //Check Whether record already exist or not long MasterAssetsAssignmentId; if (objADMasterAssetsAssignment.MasterAssetsAssignmentId == 0) { MasterAssetsAssignmentId = _Context.ASMasterAssetsAssignments.Where(a => a.MasterProductChildId == objADMasterAssetsAssignment.MasterProductChildId).Select(a => a.MasterAssetsAssignmentId).FirstOrDefault(); } else { MasterAssetsAssignmentId = objADMasterAssetsAssignment.MasterAssetsAssignmentId; } if (MasterAssetsAssignmentId == null || MasterAssetsAssignmentId == 0) { if (_MasterProductChild.MasterEmployeeId != null && _MasterProductChild.MasterEmployeeId > 0) { _Context.ASMasterAssetsAssignments.Add(objASMasterAssetsAssignment); await _Context.SaveChangesAsync(); } } else if (MasterAssetsAssignmentId != null && MasterAssetsAssignmentId > 0) { objASMasterAssetsAssignment.MasterAssetsAssignmentId = MasterAssetsAssignmentId; if (_MasterProductChild.MasterEmployeeId != null && _MasterProductChild.MasterEmployeeId > 0) { _Context.Entry(objASMasterAssetsAssignment).State = EntityState.Modified; await _Context.SaveChangesAsync(); } else { var ASMasterAssetsAssignmentNew = _Context.ASMasterAssetsAssignments.Find(MasterAssetsAssignmentId); _Context.ASMasterAssetsAssignments.Remove(ASMasterAssetsAssignmentNew); await _Context.SaveChangesAsync(); } } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw new Exception(ex.Message); } } }
public async Task <ActionResult <MasterAssetsAssignmentResult> > PutASMasterAssetsAssignment(long id, ASMasterAssetsAssignment objASMasterAssetsAssignment) { if (id != objASMasterAssetsAssignment.MasterEmployeeId) { return(BadRequest()); } try { await _IMasterAssetsAssignmentInterface.UpdateASMasterAssetsAssignment(objASMasterAssetsAssignment); return(_IMasterAssetsAssignmentInterface.GetAllASMasterAssetsAssignment(id).FirstOrDefault()); } catch (DbUpdateConcurrencyException) { if (!_IMasterAssetsAssignmentInterface.ASMasterAssetsAssignmentExists(id)) { return(NotFound()); } else { throw; } } catch (Exception ex) { throw new Exception(ex.Message); } return(NoContent()); }
public async Task <ActionResult <MasterAssetsAssignmentResult> > PostASMasterAssetsAssignment(ASMasterAssetsAssignment objASMasterAssetsAssignment) { try { await _IMasterAssetsAssignmentInterface.InsertASMasterAssetsAssignment(objASMasterAssetsAssignment); return(CreatedAtAction("GetASMasterAssetsAssignment", new { id = objASMasterAssetsAssignment.MasterAssetsAssignmentId }, objASMasterAssetsAssignment)); } catch (Exception ex) { throw new Exception(ex.Message); } }