Example #1
0
        public async Task <bool> AddUpdateWithdrawalAsync(deposit_withdrawalform model)
        {
            try
            {
                if (model.WithdrawalFormId > 0)
                {
                    var itemToUpdate = await _dataContext.deposit_withdrawalform.FindAsync(model.WithdrawalFormId);

                    _dataContext.Entry(itemToUpdate).CurrentValues.SetValues(model);
                }
                else
                {
                    await _dataContext.deposit_withdrawalform.AddAsync(model);
                }
                return(await _dataContext.SaveChangesAsync() > 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <ActionResult <WithdrawalFormRegRespObj> > AddUpDateWithdrawal([FromBody] AddUpdateWithdrawalFormObj model)
        {
            try
            {
                var user = await _identityServer.UserDataAsync();

                deposit_withdrawalform item = null;
                if (model.WithdrawalFormId > 0)
                {
                    item = await _repo.GetWithdrawalByIdAsync(model.WithdrawalFormId);

                    if (item == null)
                    {
                        return new WithdrawalFormRegRespObj
                               {
                                   Status = new APIResponseStatus {
                                       IsSuccessful = false, Message = new APIResponseMessage {
                                           FriendlyMessage = "Item does not Exist"
                                       }
                                   }
                               }
                    }
                    ;
                }

                var domainObj = new deposit_withdrawalform();

                domainObj.WithdrawalFormId     = model.WithdrawalFormId > 0 ? model.WithdrawalFormId : 0;
                domainObj.Structure            = model.Structure;
                domainObj.Product              = model.Product;
                domainObj.TransactionReference = model.TransactionReference;
                domainObj.AccountNumber        = model.AccountNumber;
                domainObj.AccountType          = model.AccountType;
                domainObj.Currency             = model.Currency;
                domainObj.Amount = model.Amount;
                domainObj.TransactionDescription = model.TransactionDescription;
                domainObj.TransactionDate        = model.TransactionDate;
                domainObj.ValueDate        = model.ValueDate;
                domainObj.WithdrawalType   = model.WithdrawalType;
                domainObj.InstrumentNumber = model.InstrumentNumber;
                domainObj.InstrumentDate   = model.InstrumentDate;
                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.WithdrawalFormId > 0 ? DateTime.Today : DateTime.Today;
                domainObj.UpdatedBy        = user.UserName;


                var isDone = await _repo.AddUpdateWithdrawalAsync(domainObj);

                return(new WithdrawalFormRegRespObj
                {
                    WithdrawalFormId = domainObj.WithdrawalFormId,
                    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 WithdrawalFormRegRespObj
                {
                    Status = new APIResponseStatus {
                        IsSuccessful = false, Message = new APIResponseMessage {
                            FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode
                        }
                    }
                });
            }
        }