public IActionResult Add([FromBody] dynamic employeeLoanData) { ValidateSession(); var result = ""; try { if (employeeLoanData != null) { Lms_EmployeeLoanPoco employeeLoanPoco = JsonConvert.DeserializeObject <Lms_EmployeeLoanPoco>(JsonConvert.SerializeObject(employeeLoanData[0])); if (employeeLoanPoco.EmployeeId < 1 && employeeLoanPoco.LoanAmount > 0) { using (var scope = new TransactionScope()) { employeeLoanPoco.CreatedBy = sessionData.UserId; var loanId = _employeeLoanLogic.Add(employeeLoanPoco); if (!string.IsNullOrEmpty(loanId.ToString())) { result = loanId.ToString(); scope.Complete(); } } } } } catch (Exception ex) { } return(Json(result)); }
public IActionResult Add([FromBody] dynamic employeeLoanData) { ValidateSession(); var result = ""; try { if (employeeLoanData != null) { Lms_EmployeeLoanPoco employeeLoanPoco = JsonConvert.DeserializeObject <Lms_EmployeeLoanPoco>(JsonConvert.SerializeObject(employeeLoanData[0])); if (employeeLoanPoco.LoanAmount > 0) { using (var scope = new TransactionScope()) { var _transactionController = new TransactionController(_cache, _dbContext); var _configLogic = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext)); var configInfo = _configLogic.GetSingleById(1); var employeeInfo = _employeeLogic.GetSingleById(employeeLoanPoco.EmployeeId); List <TransactionModel> debitTransactionModelList = new List <TransactionModel>(); TransactionModel debitTransactionModel = new TransactionModel(); debitTransactionModel.AccountId = employeeInfo.AccountId; debitTransactionModel.TxnAmount = employeeLoanPoco.LoanAmount; debitTransactionModelList.Add(debitTransactionModel); List <TransactionModel> creditTransactionModelList = new List <TransactionModel>(); TransactionModel creditTransactionModel = new TransactionModel(); creditTransactionModel.AccountId = (int)configInfo.LoanIncomeAccount; creditTransactionModel.TxnAmount = employeeLoanPoco.LoanAmount; creditTransactionModelList.Add(creditTransactionModel); var txnId = _transactionController.MakeTransaction(debitTransactionModelList, creditTransactionModelList, employeeLoanPoco.LoanAmount, DateTime.Now, DateTime.Now, employeeLoanPoco.Remarks); employeeLoanPoco.TransactionId = txnId; employeeLoanPoco.CreatedBy = sessionData.UserId; var loanId = _employeeLoanLogic.Add(employeeLoanPoco); if (!string.IsNullOrEmpty(loanId.ToString())) { result = loanId.ToString(); scope.Complete(); } } } } } catch (Exception ex) { } return(Json(result)); }
public IActionResult Update([FromBody] dynamic employeeLoanData) { ValidateSession(); var result = ""; try { if (employeeLoanData != null) { Lms_EmployeeLoanPoco employeeLoanPoco = JsonConvert.DeserializeObject <Lms_EmployeeLoanPoco>(JsonConvert.SerializeObject(employeeLoanData[0])); if (employeeLoanPoco.EmployeeId < 1 && employeeLoanPoco.LoanAmount > 0) { using (var scope = new TransactionScope()) { var existingLoan = _employeeLoanLogic.GetList().Where(c => c.EmployeeId == employeeLoanPoco.EmployeeId).FirstOrDefault(); existingLoan.LoanAmount = employeeLoanPoco.LoanAmount; existingLoan.LoanTakenOn = employeeLoanPoco.LoanTakenOn; existingLoan.PaidAmount = employeeLoanPoco.PaidAmount; existingLoan.Remarks = employeeLoanPoco.Remarks; var loanId = _employeeLoanLogic.Update(existingLoan); if (!string.IsNullOrEmpty(loanId.ToString())) { result = loanId.ToString(); scope.Complete(); } } } } } catch (Exception ex) { } return(Json(result)); }