You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

139 lines
5.7 KiB

using Business.Remit;
using Common;
using Common.Model.Remit;
using JsonRx.AuthFilter;
using log4net;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.ModelBinding;
namespace JsonRx.Api
{
[RoutePrefix("api/v1")]
public class RemitController : ApiController
{
private readonly IRemitBusiness _requestServices;
private static readonly ILog Log = LogManager.GetLogger(typeof(RemitController));
public RemitController() { }
public RemitController(IRemitBusiness requestServices)
{
_requestServices = requestServices;
}
/// <summary>
/// This method is used to search cash transaction for wallet topup
/// </summary>
/// <returns></returns>
[HttpPost]
[TokenAuthentication]
[Route("mobile/searchTxnByControlNumber")]
public IHttpActionResult SearchTxnByControlNumber(SearchTxnModel searchTxn)
{
string processId = Guid.NewGuid().ToString();
LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = processId;
LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = searchTxn.userID;
LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "SearchTxnByControlNumber";
Log.Debug("User trying to initiate search transaction." + JsonConvert.SerializeObject(searchTxn));
searchTxn.ProcessId = processId;
if (ModelState.IsValid)
{
var initBalanceTransferResponse = _requestServices.SearchTxnByControlNumber(searchTxn);
return Ok(initBalanceTransferResponse);
}
return ModelValidationError(ModelState);
}
/// <summary>
/// This method is used to confirm cash transaction for wallet topup
/// </summary>
/// <returns></returns>
[HttpPost]
[TokenAuthentication]
[Route("mobile/redeemCashPayment")]
public IHttpActionResult RedeemCashPayment(ConfirmTxnModel redeemTxn)
{
string processId = Guid.NewGuid().ToString();
LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = processId;
LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = redeemTxn.userID;
LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "RedeemCashPayment";
Log.Debug("User trying to initiate redeem cash txn." + JsonConvert.SerializeObject(redeemTxn));
redeemTxn.ProcessId = processId;
if (ModelState.IsValid)
{
var initBalanceTransferResponse = _requestServices.RedeemCashPayment(redeemTxn);
return Ok(initBalanceTransferResponse);
}
return ModelValidationError(ModelState);
}
/// <summary>
/// This method is used to withdraw from wallet
/// </summary>
/// <returns></returns>
[HttpPost]
[TokenAuthentication]
[Route("mobile/withdrawWalletRequest")]
public IHttpActionResult WithdrawWalletRequest(WithdrawWalletRequestModel withdrawWalletRequest)
{
string processId = Guid.NewGuid().ToString();
LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = processId;
LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = withdrawWalletRequest.userID;
LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "WithdrawWalletRequest";
Log.Debug("User trying to initiate Withdraw Wallet Request." + JsonConvert.SerializeObject(withdrawWalletRequest));
withdrawWalletRequest.ProcessId = processId;
if (ModelState.IsValid)
{
var initBalanceTransferResponse = _requestServices.WithdrawWalletRequest(withdrawWalletRequest);
return Ok(initBalanceTransferResponse);
}
return ModelValidationError(ModelState);
}
/// <summary>
/// This method is used to withdraw from wallet
/// </summary>
/// <returns></returns>
[HttpPost]
[TokenAuthentication]
[Route("mobile/withdrawFromWallet")]
public IHttpActionResult WithdrawFromWallet(WithdrawFromWalletModel withdrawFromWallet)
{
string processId = Guid.NewGuid().ToString();
LogicalThreadContext.Properties[LoggerProperty.PROCESSID] = processId;
LogicalThreadContext.Properties[LoggerProperty.CREATEDBY] = withdrawFromWallet.userID;
LogicalThreadContext.Properties[LoggerProperty.METHODNAME] = "WithdrawFromWallet";
Log.Debug("User trying to initiate Withdraw Wallet Request." + JsonConvert.SerializeObject(withdrawFromWallet));
withdrawFromWallet.ProcessId = processId;
if (ModelState.IsValid)
{
var initBalanceTransferResponse = _requestServices.WithdrawFromWallet(withdrawFromWallet);
return Ok(initBalanceTransferResponse);
}
return ModelValidationError(ModelState);
}
protected IHttpActionResult ModelValidationError(ModelStateDictionary modelState)
{
var modelErrors = modelState.Select(x => x.Value.Errors)
.Where(y => y.Count > 0)
.First()[0].ErrorMessage;
JsonRxResponse jsonRx = new JsonRxResponse()
{
ErrorCode = "1",
Msg = string.IsNullOrEmpty(modelErrors) ? "It seems like incorrect Json input(s)." : modelErrors,
Data = ""
};
return Ok(jsonRx);
}
}
}