public async Task <bool> AddUpdateWithdrawalSetupAsync(deposit_withdrawalsetup model) { try { if (model.WithdrawalSetupId > 0) { var itemToUpdate = await _dataContext.deposit_withdrawalsetup.FindAsync(model.WithdrawalSetupId); _dataContext.Entry(itemToUpdate).CurrentValues.SetValues(model); } else { await _dataContext.deposit_withdrawalsetup.AddAsync(model); } return(await _dataContext.SaveChangesAsync() > 0); } catch (Exception ex) { throw ex; } }
public async Task <bool> UploadWithdrawalSetupAsync(List <byte[]> record, string createdBy) { try { if (record == null) { return(false); } ExcelPackage.LicenseContext = LicenseContext.NonCommercial; List <deposit_withdrawalsetup> uploadedRecord = new List <deposit_withdrawalsetup>(); if (record.Count() > 0) { foreach (var byteItem in record) { using (MemoryStream stream = new MemoryStream(byteItem)) using (ExcelPackage excelPackage = new ExcelPackage(stream)) { ExcelWorksheet workSheet = excelPackage.Workbook.Worksheets[0]; int totalRows = workSheet.Dimension.Rows; for (int i = 2; i <= totalRows; i++) { var item = new deposit_withdrawalsetup { //can = workSheet.Cells[i, 1].Value.ToString(), //CanApply = workSheet.Cells[i, 2].Value.ToString() }; uploadedRecord.Add(item); } } } } if (uploadedRecord.Count > 0) { foreach (var item in uploadedRecord) { var Withdrawalexist = _dataContext.deposit_withdrawalsetup.Where(x => x.WithdrawalSetupId == item.WithdrawalSetupId && x.Deleted == false).FirstOrDefault(); if (Withdrawalexist != null) { Withdrawalexist.Product = item.Product; //Withdrawalexist.can = item.CanApply; Withdrawalexist.Active = true; Withdrawalexist.Deleted = false; Withdrawalexist.UpdatedBy = item.UpdatedBy; Withdrawalexist.UpdatedOn = DateTime.Now; } else { var Withdrawal = new deposit_withdrawalsetup { Product = item.Product, //Description = item.Description, Active = true, Deleted = false, CreatedBy = createdBy, CreatedOn = DateTime.Now, }; await _dataContext.deposit_withdrawalsetup.AddAsync(Withdrawal); } } } var response = _dataContext.SaveChanges() > 0; return(response); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <ActionResult <WithdrawalSetupRegRespObj> > AddUpdateWithdrawalSetupAsync([FromBody] AddUpdateWithdrawalSetupObj model) { try { var user = await _identityServer.UserDataAsync(); deposit_withdrawalsetup item = null; if (model.WithdrawalSetupId > 0) { item = await _repo.GetWithdrawalSetupByIdAsync(model.WithdrawalSetupId); if (item == null) { return new WithdrawalSetupRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Item does not Exist" } } } } ; } var domainObj = new deposit_withdrawalsetup(); domainObj.WithdrawalSetupId = model.WithdrawalSetupId > 0 ? model.WithdrawalSetupId : 0; domainObj.Structure = model.Structure; domainObj.Product = model.Product; domainObj.PresetChart = model.PresetChart; domainObj.AccountType = model.AccountType; domainObj.DailyWithdrawalLimit = model.DailyWithdrawalLimit; domainObj.WithdrawalCharges = model.WithdrawalCharges; domainObj.Charge = model.Charge; domainObj.Amount = model.Amount; domainObj.ChargeType = model.ChargeType; domainObj.Active = true; domainObj.CreatedOn = DateTime.Today; domainObj.CreatedBy = user.UserName; domainObj.Deleted = false; domainObj.UpdatedOn = model.WithdrawalSetupId > 0 ? DateTime.Today : DateTime.Today; domainObj.UpdatedBy = user.UserName; var isDone = await _repo.AddUpdateWithdrawalSetupAsync(domainObj); return(new WithdrawalSetupRegRespObj { WithdrawalSetupId = domainObj.WithdrawalSetupId, 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 WithdrawalSetupRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode } } }); } }