public bool UpdatePendingTransactionAndItem(BusinessObject.ExpenseTransaction transaction, BusinessObject.TransactionItem updatedTransactionItem) { try { //Re-Map Object to Entity Object using (var db = new ExpenseManagerDBEntities()) { var myEntityObj = TransactionItemMapper.Map <BusinessObject.TransactionItem, TransactionItem>(updatedTransactionItem); if (myEntityObj == null) { return(false); } db.TransactionItems.Attach(myEntityObj); db.ObjectStateManager.ChangeObjectState(myEntityObj, EntityState.Modified); db.SaveChanges(); var totalPrice = db.TransactionItems.Where(x => x.ExpenseTransactionId == transaction.ExpenseTransactionId).ToList().Sum(m => m.RequestedQuantity * m.RequestedUnitPrice); transaction.TotalTransactionAmount = totalPrice; var transactionEntityToUpdate = ExpenseTransactionMapper.Map <BusinessObject.ExpenseTransaction, ExpenseTransaction>(transaction); db.ExpenseTransactions.Attach(transactionEntityToUpdate); db.ObjectStateManager.ChangeObjectState(transactionEntityToUpdate, EntityState.Modified); db.SaveChanges(); } return(true); } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(false); } }
public BusinessObject.ExpenseTransaction DeleteTransactionItemUpdateTotalAmount(int transactionItemId) { try { using (var db = new ExpenseManagerDBEntities()) { var myObj = db.TransactionItems.Single(s => s.TransactionItemId == transactionItemId); if (myObj == null) { return(new BusinessObject.ExpenseTransaction()); } db.TransactionItems.DeleteObject(myObj); db.SaveChanges(); var transactionAmount = db.TransactionItems.Where(m => m.ExpenseTransactionId == myObj.ExpenseTransactionId).Sum(m => m.RequestedQuantity * m.RequestedUnitPrice); var transaction = db.ExpenseTransactions.Single(m => m.ExpenseTransactionId == myObj.ExpenseTransactionId); transaction.TotalTransactionAmount = transactionAmount; if (transaction.Status == 2) { transaction.Status = 0; } db.ObjectStateManager.ChangeObjectState(transaction, EntityState.Modified); db.SaveChanges(); var myBusinessObj = ExpenseTransactionMapper.Map <ExpenseTransaction, BusinessObject.ExpenseTransaction>(transaction); return(myBusinessObj); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(new BusinessObject.ExpenseTransaction()); } }
public BusinessObject.ExpenseTransaction UpdateTransactionItemAndApprovedTotalAmount(BusinessObject.TransactionItem transactionItem) { try { //Re-Map Object to Entity Object var myEntityObj = TransactionItemMapper.Map <BusinessObject.TransactionItem, TransactionItem>(transactionItem); if (myEntityObj == null) { return(new BusinessObject.ExpenseTransaction()); } using (var db = new ExpenseManagerDBEntities()) { db.TransactionItems.Attach(myEntityObj); db.ObjectStateManager.ChangeObjectState(myEntityObj, EntityState.Modified); db.SaveChanges(); var transactionAmount = db.TransactionItems.Where(m => m.ExpenseTransactionId == myEntityObj.ExpenseTransactionId).Sum(m => m.RequestedQuantity * m.RequestedUnitPrice); var transaction = db.ExpenseTransactions.Single(m => m.ExpenseTransactionId == myEntityObj.ExpenseTransactionId); transaction.TotalTransactionAmount = transactionAmount; db.ExpenseTransactions.Attach(transaction); db.ObjectStateManager.ChangeObjectState(myEntityObj, EntityState.Modified); db.SaveChanges(); var myBusinessObj = ExpenseTransactionMapper.Map <ExpenseTransaction, BusinessObject.ExpenseTransaction>(transaction); return(myBusinessObj); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(new BusinessObject.ExpenseTransaction()); } }
public List <xPlug.BusinessObject.ExpenseTransaction> GetExpenseTransactionsByBeneficiaryTypeId(Int32 beneficiaryTypeId) { try { using (var db = new ExpenseManagerDBEntities()) { var myObjList = db.ExpenseTransactions.ToList().FindAll(m => m.BeneficiaryTypeId == beneficiaryTypeId); var myBusinessObjList = new List <xPlug.BusinessObject.ExpenseTransaction>(); if (myObjList == null) { return(myBusinessObjList); } //Re-Map each Entity Object to Business Object foreach (var item in myObjList) { var myBusinessObj = ExpenseTransactionMapper.Map <ExpenseTransaction, xPlug.BusinessObject.ExpenseTransaction>(item); if (myBusinessObj == null) { continue; } myBusinessObjList.Add(myBusinessObj); } return(myBusinessObjList); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(new List <xPlug.BusinessObject.ExpenseTransaction>()); } }
public xPlug.BusinessObject.ExpenseTransaction GetExpenseTransaction(long expenseTransactionId) { try { using (var db = new ExpenseManagerDBEntities()) { var myObj = db.ExpenseTransactions.SingleOrDefault(s => s.ExpenseTransactionId == expenseTransactionId); if (myObj == null) { return(new xPlug.BusinessObject.ExpenseTransaction()); } //Re-Map Entity Object to Business Object var myBusinessObj = ExpenseTransactionMapper.Map <ExpenseTransaction, xPlug.BusinessObject.ExpenseTransaction>(myObj); if (myBusinessObj == null) { return(new xPlug.BusinessObject.ExpenseTransaction()); } { return(myBusinessObj); } } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(new xPlug.BusinessObject.ExpenseTransaction()); } }
public Dictionary <List <BusinessObject.Beneficiary>, List <BusinessObject.Beneficiary> > GetFilteredBeneficiaries() { try { var beneficiaryList = new Dictionary <List <BusinessObject.Beneficiary>, List <BusinessObject.Beneficiary> >(); var beneficiariesWithUnApprovedTransactions = new List <BusinessObject.Beneficiary>(); var beneficiariesWithApprovedTransactions = new List <BusinessObject.Beneficiary>(); var myBusinessObjList = new List <BusinessObject.ExpenseTransaction>(); using (var db = new ExpenseManagerDBEntities()) { var myObjList = db.ExpenseTransactions.ToList(); if (!myObjList.Any()) { return(new Dictionary <List <BusinessObject.Beneficiary>, List <BusinessObject.Beneficiary> >()); } foreach (var item in myObjList) { var myBusinessObj = ExpenseTransactionMapper.Map <ExpenseTransaction, BusinessObject.ExpenseTransaction>(item); if (myBusinessObj == null) { continue; } myBusinessObjList.Add(myBusinessObj); } } foreach (var item in myBusinessObjList) { if (beneficiariesWithUnApprovedTransactions.All(m => m.BeneficiaryId != item.BeneficiaryId)) { beneficiariesWithUnApprovedTransactions.Add(item.Beneficiary); } if (beneficiariesWithApprovedTransactions.All(m => m.BeneficiaryId != item.BeneficiaryId && item.Status == 1)) { beneficiariesWithApprovedTransactions.Add(item.Beneficiary); } } if (!beneficiariesWithUnApprovedTransactions.Any() && !beneficiariesWithApprovedTransactions.Any()) { return(beneficiaryList); } beneficiaryList.Add(beneficiariesWithUnApprovedTransactions.OrderBy(m => m.FullName).ToList(), beneficiariesWithApprovedTransactions.OrderBy(m => m.FullName).ToList()); return(beneficiaryList); } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(new Dictionary <List <BusinessObject.Beneficiary>, List <BusinessObject.Beneficiary> >()); } }
public bool UpdateTransactionAndItems(BusinessObject.ExpenseTransaction transaction, List <BusinessObject.TransactionItem> updatedTransactionItemList) { try { //Re-Map Object to Entity Object double approvedTotalPrice = 0; using (var db = new ExpenseManagerDBEntities()) { foreach (var item in updatedTransactionItemList) { var myEntityObj = TransactionItemMapper.Map <BusinessObject.TransactionItem, TransactionItem>(item); if (myEntityObj == null) { continue; } myEntityObj.Status = 1; if (myEntityObj.ApprovedQuantity < 1) { myEntityObj.ApprovedQuantity = myEntityObj.RequestedQuantity; } if (myEntityObj.ApprovedUnitPrice < 1) { myEntityObj.ApprovedUnitPrice = myEntityObj.RequestedUnitPrice; } myEntityObj.ApprovedTotalPrice = myEntityObj.ApprovedQuantity * myEntityObj.ApprovedUnitPrice; approvedTotalPrice += myEntityObj.ApprovedTotalPrice; db.TransactionItems.Attach(myEntityObj); db.ObjectStateManager.ChangeObjectState(myEntityObj, EntityState.Modified); db.SaveChanges(); } var transactionEntityToUpdate = ExpenseTransactionMapper.Map <BusinessObject.ExpenseTransaction, ExpenseTransaction>(transaction); transactionEntityToUpdate.TotalApprovedAmount = approvedTotalPrice; db.ExpenseTransactions.Attach(transactionEntityToUpdate); db.ObjectStateManager.ChangeObjectState(transactionEntityToUpdate, EntityState.Modified); db.SaveChanges(); } return(true); } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(false); } }
public bool UpdateExpenseTransaction(xPlug.BusinessObject.ExpenseTransaction expenseTransaction) { try { //Re-Map Object to Entity Object var myEntityObj = ExpenseTransactionMapper.Map <xPlug.BusinessObject.ExpenseTransaction, ExpenseTransaction>(expenseTransaction); if (myEntityObj == null) { return(false); } using (var db = new ExpenseManagerDBEntities()) { db.ExpenseTransactions.Attach(myEntityObj); db.ObjectStateManager.ChangeObjectState(myEntityObj, EntityState.Modified); db.SaveChanges(); return(true); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(false); } }
public long AddExpenseTransaction(xPlug.BusinessObject.ExpenseTransaction expenseTransaction) { try { //Re-Map Object to Entity Object var myEntityObj = ExpenseTransactionMapper.Map <xPlug.BusinessObject.ExpenseTransaction, ExpenseTransaction>(expenseTransaction); if (myEntityObj == null) { return(-2); } using (var db = new ExpenseManagerDBEntities()) { db.AddToExpenseTransactions(myEntityObj); db.SaveChanges(); expenseTransaction.ExpenseTransactionId = myEntityObj.ExpenseTransactionId; return(expenseTransaction.ExpenseTransactionId); } } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public int AddTransactionItems(List <BusinessObject.TransactionItem> transactionItems, BusinessObject.ExpenseTransaction expenseTransaction) { try { //Re-Map Object to Entity Object double totalPrice = 0; if (!transactionItems.Any()) { return(-1); } using (var db = new ExpenseManagerDBEntities()) { if (transactionItems.Any(transactionItem => db.ExpenseTransactions.Count(m => m.TransactionDate == expenseTransaction.TransactionDate && m.Status == 0 && m.BeneficiaryId == expenseTransaction.BeneficiaryId && m.TransactionItems.Count(x => x.ExpensenseItemId == transactionItem.ExpensenseItemId) > 0) > 0)) { return(-3); } var transactionEntityObj = ExpenseTransactionMapper.Map <BusinessObject.ExpenseTransaction, ExpenseTransaction>(expenseTransaction); if (transactionEntityObj == null) { return(-2); } db.AddToExpenseTransactions(transactionEntityObj); db.SaveChanges(); expenseTransaction.ExpenseTransactionId = transactionEntityObj.ExpenseTransactionId; if (expenseTransaction.ExpenseTransactionId < 1) { return(-4); } foreach (var transactionItem in transactionItems) { transactionItem.ApprovedQuantity = 0; transactionItem.ApprovedTotalPrice = 0; transactionItem.ApprovedUnitPrice = 0; totalPrice += (transactionItem.RequestedQuantity * transactionItem.RequestedUnitPrice); transactionItem.ExpenseTransactionId = expenseTransaction.ExpenseTransactionId; var myEntityObj = TransactionItemMapper.Map <BusinessObject.TransactionItem, TransactionItem>(transactionItem); if (myEntityObj == null) { return(-5); } db.AddToTransactionItems(myEntityObj); db.SaveChanges(); transactionItem.TransactionItemId = myEntityObj.TransactionItemId; } var transactionEntityToUpdate = db.ExpenseTransactions.SingleOrDefault(m => m.ExpenseTransactionId == expenseTransaction.ExpenseTransactionId); if (transactionEntityToUpdate == null) { return(-6); } transactionEntityToUpdate.TotalTransactionAmount = totalPrice; db.ObjectStateManager.ChangeObjectState(transactionEntityToUpdate, EntityState.Modified); db.SaveChanges(); } return(1); } catch (Exception ex) { ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); return(0); } }