public async Task <bool> AddUpdateTransferAsync(deposit_transferform model) { try { if (model.TransferFormId > 0) { var itemToUpdate = await _dataContext.deposit_transferform.FindAsync(model.TransferFormId); _dataContext.Entry(itemToUpdate).CurrentValues.SetValues(model); } else { await _dataContext.deposit_transferform.AddAsync(model); } return(await _dataContext.SaveChangesAsync() > 0); } catch (Exception ex) { throw ex; } }
public async Task <ActionResult <TransferFormRegRespObj> > AddUpDateTransfer([FromBody] AddUpdateTransferFormObj model) { try { var user = await _identityServer.UserDataAsync(); deposit_transferform item = null; if (model.TransferFormId > 0) { item = await _repo.GetTransferByIdAsync(model.TransferFormId); if (item == null) { return new TransferFormRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Item does not Exist" } } } } ; } var domainObj = new deposit_transferform(); domainObj.TransferFormId = model.TransferFormId > 0 ? model.TransferFormId : 0; domainObj.Structure = model.Structure; domainObj.Product = model.Product; domainObj.TransactionDate = model.TransactionDate; domainObj.ValueDate = model.ValueDate; domainObj.ExternalReference = model.ExternalReference; domainObj.TransactionReference = model.TransactionReference; domainObj.PayingAccountNumber = model.PayingAccountNumber; domainObj.PayingAccountName = model.PayingAccountName; domainObj.PayingAccountCurrency = model.PayingAccountCurrency; domainObj.Amount = model.Amount; domainObj.BeneficiaryAccountNumber = model.BeneficiaryAccountNumber; domainObj.BeneficiaryAccountName = model.BeneficiaryAccountName; domainObj.BeneficiaryAccountCurrency = model.BeneficiaryAccountCurrency; domainObj.TransactionNarration = model.TransactionNarration; domainObj.ExchangeRate = model.ExchangeRate; domainObj.TotalCharge = model.TotalCharge; domainObj.Active = true; domainObj.CreatedOn = DateTime.Today; domainObj.CreatedBy = user.UserName; domainObj.Deleted = false; domainObj.UpdatedOn = model.TransferFormId > 0 ? DateTime.Today : DateTime.Today; domainObj.UpdatedBy = user.UserName; var isDone = await _repo.AddUpdateTransferAsync(domainObj); return(new TransferFormRegRespObj { TransferFormId = domainObj.TransferFormId, 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 TransferFormRegRespObj { Status = new APIResponseStatus { IsSuccessful = false, Message = new APIResponseMessage { FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode } } }); } }