using BuddyFinance.Common.Encryption;
using BuddyFinance.Integration;
using BuddyFinance.Integration.Models;
using BuddyFinance.Integration.Models.Enums;
using BuddyFinance.Integration.Models.ManageCash;
using BuddyFinance.WebApi.Extensions;
using BuddyFinance.WebApi.Filters;
using System.Web.Http;
namespace BuddyFinance.WebApi.Controllers
{
///
/// Manage Cash
///
[RoutePrefix("api/managecash")]
[Authenticate]
public class ManageCashController : BaseController
{
private ManageCashIntergrator _cashwithdrawalIntergrator;
///
///
///
public ManageCashController()
{
_cashwithdrawalIntergrator = new ManageCashIntergrator();
}
///
/// Get cash withdrawal history
///
///
///
[HttpGet]
[Route("withdrawals")]
public CashWithdrawalsResult CashWithdrawals(int? profileId = null)
{
return _cashwithdrawalIntergrator.CashWithdrawals(profileId);
}
///
/// Get cash withdrawal history
///
///
///
[HttpGet]
[Route("withdrawalhistory")]
public CashWithdrawalsResult CashWithdrawals(string profileId)
{
var pId = profileId.ToDecryptedInt();
return _cashwithdrawalIntergrator.CashWithdrawals(pId);
}
///
/// Get cash deposit history
///
///
[HttpGet]
[Route("deposits")]
public CashDepositsResult CashDeposits(int? profileId = null)
{
var token = System.Web.HttpContext.Current.Request.Headers["X-Auth-Token"];
return _cashwithdrawalIntergrator.CashDeposits(profileId);
}
///
/// Returns profile diposits and withdrawals history
///
/// Profile Id
///
[HttpGet]
[Route("funds")]
public BaseResult Funds(int profileId)
{
return _cashwithdrawalIntergrator.Funds(profileId);
}
///
/// Credits profile funds
///
/// Profile Id
/// Amount to credit with
///
/// Comments about this deposit
///
[HttpPost]
[Route("deposit")]
public CashDepositResult SaveFundsToProfile(int id, double amount, string userId, string comment)
{
//var token = System.Web.HttpContext.Current.Request.Headers["X-Auth-Token"];
return _cashwithdrawalIntergrator.SaveFundsToProfile(id, amount, userId, comment);
}
///
/// Validate Withdrawal Request
///
///
///
[HttpPost]
[Route("validatewithdrawalrequest")]
public ValidateWithdrawalRequestResult Validatewithdrawalrequest(WithdrawalRequestModel manageCashModel)
{
return _cashwithdrawalIntergrator.ValidateWithdrawalRequest(manageCashModel);
}
///
///
///
///
///
[HttpPost]
[Route("requestwithdrawal")]
public WithdrawalRequestResult WithdrawalRequest(WithdrawalRequestModel manageCashModel)
{
return _cashwithdrawalIntergrator.RequestCashWithdrawal(manageCashModel);
}
///
///
///
///
///
[HttpGet]
[Route("availablecash")]
public GetManageAvailableCash AvailableCash(int id)
{
return _cashwithdrawalIntergrator.ManageAvailableCash(id);
}
///
///
///
///
///
[HttpGet]
[Route("cashwithdrawal")]
public GetManageCashWithdrawal CashWithdrawal(int id)
{
return _cashwithdrawalIntergrator.ManageCashWithdrawal(id);
}
///
///
///
///
///
[HttpGet]
[Route("cashdeposit")]
public GetManageCashDeposit CashDeposit(int id)
{
return _cashwithdrawalIntergrator.ManageCashDeposit(id);
}
///
///
///
///
///
[HttpGet]
[Route("cashWithdrawalHistory")]
public CashWithdrawalsResult CashWithdrawalHistory(int profileId)
{
return _cashwithdrawalIntergrator.CashWithdrawalsResult(profileId);
}
///
///
///
///
///
///
[HttpPost]
public AcceptCashWithdrawal AcceptCashWithdrawal(int id, string userId)
{
return _cashwithdrawalIntergrator.AcceptCashWithdrawal(id, userId.ToDecryptedInt());
}
///
///
///
///
[HttpGet]
public CashWithdrawalsResult WithdrawalRequests()
{
return _cashwithdrawalIntergrator.WithdrawalRequests();
}
///
///
///
///
///
///
///
[HttpPost]
public RejectCashWithdrawalRequest RejectCashWithdrawalRequest(int id, string comment, string userId)
{
return _cashwithdrawalIntergrator.RejectCashWithdrawalRequest(id, userId.ToDecryptedInt(), comment);
}
///
///
///
///
///
[HttpPost]
public CancelCashWithdrawaRequest CancelCashWithdrawaRequest(int id)
{
return _cashwithdrawalIntergrator.CancelCashWithdrawalRequest(id);
}
///
/// Gets all or profile-specific deductions
///
///
///
///
[HttpGet]
[Route("manualdeductions")]
public ManualDeductionsResult ManualDeductions(int? profileId = null)
{
return _cashwithdrawalIntergrator.ManualDeductions(profileId);
}
///
/// Create or Update a Manual Deduction again Lender funds
///
///
///
[HttpPost]
[Route("manualdeduction")]
public ManualDeductionResult SaveManualDeduction(ManualDeduction manualDeduction)
{
if (!ModelState.IsValid)
return new ManualDeductionResult
{
ErrorCode = (int)ResponseCodes.ValidationError,
ErrorMessage = ModelState.GetValidationErrors()
};
return _cashwithdrawalIntergrator.SaveManualDeduction(manualDeduction);
}
}
}