public async Task <bool> AddUpdateAccountSetupAsync(deposit_accountsetup model) { using (var trans = _dataContext.Database.BeginTransaction()) { try { var output = _dataContext.SaveChanges() > 0; var response = AddUpdateItems(model.DepositAccountId, model.ApplicableChargesId, model.ApplicableTaxId, model.CreatedBy); if (response) { trans.Commit(); return(true); } return(false); } catch (Exception ex) { throw ex; } } }
public async Task <bool> UploadAccountSetupAsync(byte[] record, string createdBy) { try { if (record == null) { return(false); } List <deposit_accountsetup> uploadedRecord = new List <deposit_accountsetup>(); using (MemoryStream stream = new MemoryStream(record)) using (ExcelPackage excelPackage = new ExcelPackage(stream)) { //Use first sheet by default ExcelWorksheet workSheet = excelPackage.Workbook.Worksheets[1]; int totalRows = workSheet.Dimension.Rows; //First row is considered as the header for (int i = 2; i <= totalRows; i++) { uploadedRecord.Add(new deposit_accountsetup { AccountName = workSheet.Cells[i, 1].Value != null ? workSheet.Cells[i, 1].Value.ToString() : null, //AccountTypeId = workSheet.Cells[i, 2].Value != null ? workSheet.Cells[i, 2].Value.ToString() : null, DormancyDays = workSheet.Cells[i, 3].Value != null ? workSheet.Cells[i, 3].Value.ToString() : null, InitialDeposit = workSheet.Cells[i, 4].Value != null ? decimal.Parse(workSheet.Cells[i, 4].Value.ToString()) : 0, //CategoryId = workSheet.Cells[i, 5].Value != null ? workSheet.Cells[i, 5].Value.ToString() : null, InterestType = workSheet.Cells[i, 6].Value != null ? workSheet.Cells[i, 6].Value.ToString() : null, InterestRate = workSheet.Cells[i, 7].Value != null ? decimal.Parse(workSheet.Cells[i, 7].Value.ToString()) : 0, //CurrencyId = workSheet.Cells[i, 8].Value != null ? workSheet.Cells[i, 8].Value.ToString() : null, MaturityType = workSheet.Cells[i, 9].Value != null ? workSheet.Cells[i, 9].Value.ToString() : null, //InterestAccrual = workSheet.Cells[i, 10].Value != null ? workSheet.Cells[i, 10].Value.ToString() : null, TransactionPrefix = workSheet.Cells[i, 11].Value != null ? workSheet.Cells[i, 11].Value.ToString() : null, CancelPrefix = workSheet.Cells[i, 12].Value != null ? workSheet.Cells[i, 12].Value.ToString() : null, RefundPrefix = workSheet.Cells[i, 13].Value != null ? workSheet.Cells[i, 13].Value.ToString() : null, OperatedByAnother = workSheet.Cells[i, 14].Value != null ? bool.Parse(workSheet.Cells[i, 14].Value.ToString()) : false, UsePresetChartofAccount = workSheet.Cells[i, 15].Value != null ? bool.Parse(workSheet.Cells[i, 15].Value.ToString()) : false, PreTerminationLiquidationCharge = workSheet.Cells[i, 16].Value != null ? bool.Parse(workSheet.Cells[i, 16].Value.ToString()) : false, Status = workSheet.Cells[i, 17].Value != null ? bool.Parse(workSheet.Cells[i, 17].Value.ToString()) : false, CanNominateBenefactor = workSheet.Cells[i, 18].Value != null ? bool.Parse(workSheet.Cells[i, 18].Value.ToString()) : false, Useworkflow = workSheet.Cells[i, 19].Value != null ? bool.Parse(workSheet.Cells[i, 19].Value.ToString()) : false, CheckCollecting = workSheet.Cells[i, 20].Value != null ? bool.Parse(workSheet.Cells[i, 20].Value.ToString()) : false, CanPlaceOnLien = workSheet.Cells[i, 21].Value != null ? bool.Parse(workSheet.Cells[i, 21].Value.ToString()) : false, }); } } if (uploadedRecord.Count > 0) { foreach (var entity in uploadedRecord) { var accountTypeExist = _dataContext.deposit_accountsetup.Where(x => x.AccountName.ToLower() == entity.AccountName.ToLower()).FirstOrDefault(); if (accountTypeExist != null) { accountTypeExist.AccountName = entity.AccountName; //accountTypeExist.AccountTypeId = accountTypename.AccountTypeId; accountTypeExist.DormancyDays = entity.DormancyDays; accountTypeExist.InitialDeposit = entity.InitialDeposit; //accountTypeExist.CategoryId = categoryName.CategoryId; accountTypeExist.InterestType = entity.InterestType; accountTypeExist.InterestRate = entity.InterestRate; //accountTypeExist.CurrencyId = currencyName.CurrencyId; accountTypeExist.MaturityType = entity.MaturityType; accountTypeExist.InterestAccrual = entity.InterestAccrual; accountTypeExist.TransactionPrefix = entity.TransactionPrefix; accountTypeExist.CancelPrefix = entity.CancelPrefix; accountTypeExist.RefundPrefix = entity.RefundPrefix; accountTypeExist.OperatedByAnother = entity.OperatedByAnother; accountTypeExist.UsePresetChartofAccount = entity.UsePresetChartofAccount; accountTypeExist.PreTerminationLiquidationCharge = entity.PreTerminationLiquidationCharge; accountTypeExist.Status = entity.Status; accountTypeExist.CanNominateBenefactor = entity.CanNominateBenefactor; accountTypeExist.Useworkflow = entity.Useworkflow; accountTypeExist.CheckCollecting = entity.CheckCollecting; accountTypeExist.CanPlaceOnLien = entity.CanPlaceOnLien; accountTypeExist.Active = true; accountTypeExist.Deleted = false; accountTypeExist.UpdatedBy = entity.UpdatedBy; accountTypeExist.UpdatedOn = DateTime.Now; } else { var accountType = new deposit_accountsetup { AccountName = entity.AccountName, //AccountTypeId = accountTypename.AccountTypeId, DormancyDays = entity.DormancyDays, InitialDeposit = entity.InitialDeposit, //CategoryId = categoryName.CategoryId, InterestType = entity.InterestType, InterestRate = entity.InterestRate, //CurrencyId = currencyName.CurrencyId, MaturityType = entity.MaturityType, InterestAccrual = entity.InterestAccrual, TransactionPrefix = entity.TransactionPrefix, CancelPrefix = entity.CancelPrefix, RefundPrefix = entity.RefundPrefix, OperatedByAnother = entity.OperatedByAnother, UsePresetChartofAccount = entity.UsePresetChartofAccount, PreTerminationLiquidationCharge = entity.PreTerminationLiquidationCharge, Status = entity.Status, CanNominateBenefactor = entity.CanNominateBenefactor, Useworkflow = entity.Useworkflow, CheckCollecting = entity.CheckCollecting, CanPlaceOnLien = entity.CanPlaceOnLien, Active = true, Deleted = false, CreatedBy = entity.CreatedBy, CreatedOn = DateTime.Now, }; await _dataContext.deposit_accountsetup.AddAsync(accountType); } } } var response = _dataContext.SaveChanges() > 0; return(response); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <ActionResult <AccountSetupRegRespObj> > AddUpDateAccountSetup([FromBody] AddUpdateAccountSetupObj model) { try { var user = await _identityServer.UserDataAsync(); DepositAccountObj item = null; if (model.DepositAccountId > 0) { item = await _repo.GetAccountSetupByIdAsync(model.DepositAccountId); if (item == null) { return new AccountSetupRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Item does not Exist" } } } } ; } var domainObj = new deposit_accountsetup(); domainObj.DepositAccountId = model.DepositAccountId > 0 ? model.DepositAccountId : 0; domainObj.Active = true; domainObj.CreatedBy = user.UserName; domainObj.CreatedOn = DateTime.Today; domainObj.Deleted = false; domainObj.Description = model.Description; domainObj.AccountName = model.AccountName; domainObj.AccountTypeId = model.AccountTypeId; domainObj.DormancyDays = model.DormancyDays; domainObj.InitialDeposit = model.InitialDeposit; domainObj.CategoryId = model.CategoryId; domainObj.BusinessCategoryId = model.BusinessCategoryId; domainObj.GLMapping = model.GLMapping; domainObj.CurrencyId = model.CurrencyId; domainObj.BankGl = model.BankGl; domainObj.InterestRate = model.InterestRate; domainObj.InterestType = model.InterestType; domainObj.CheckCollecting = model.CheckCollecting; domainObj.MaturityType = model.MaturityType; domainObj.PreTerminationLiquidationCharge = model.PreTerminationLiquidationCharge; domainObj.InterestAccrual = model.InterestAccrual; domainObj.Status = model.Status; domainObj.OperatedByAnother = model.OperatedByAnother; domainObj.CanNominateBenefactor = model.CanNominateBenefactor; domainObj.UsePresetChartofAccount = model.UsePresetChartofAccount; domainObj.TransactionPrefix = model.TransactionPrefix; domainObj.CancelPrefix = model.CancelPrefix; domainObj.RefundPrefix = model.RefundPrefix; domainObj.Useworkflow = model.Useworkflow; domainObj.CanPlaceOnLien = model.CanPlaceOnLien; domainObj.UpdatedBy = user.UserName; domainObj.UpdatedOn = model.DepositAccountId > 0 ? DateTime.Today : DateTime.Today; var isDone = await _repo.AddUpdateAccountSetupAsync(domainObj); return(new AccountSetupRegRespObj { DepositAccountId = domainObj.DepositAccountId, Status = new APIResponseStatus { IsSuccessful = isDone ? true : false, Message = new APIResponseMessage { FriendlyMessage = isDone ? "successful" : "Unsuccessful" } } }); } catch (Exception ex) { var errorCode = ErrorID.Generate(5); _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"); return(new AccountSetupRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode } } }); } }