373 lines
15 KiB
C#
373 lines
15 KiB
C#
using CPRNIMS.Domain.UIContracts.Common;
|
|
using CPRNIMS.Domain.UIContracts.PO;
|
|
using CPRNIMS.Infrastructure.Helper;
|
|
using CPRNIMS.Infrastructure.Models.Account;
|
|
using CPRNIMS.Infrastructure.Models.Common;
|
|
using CPRNIMS.Infrastructure.ViewModel.PO;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CPRNIMS.Domain.UIServices.PO
|
|
{
|
|
public class PurchaseOrder : IPurchaseOrder
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
private readonly TokenHelper _tokenHelper;
|
|
private readonly IApiConfigurationService _apiConfigurationService;
|
|
public PurchaseOrder(IConfiguration configuration, TokenHelper tokenHelper,
|
|
IApiConfigurationService apiConfigurationService)
|
|
{
|
|
_configuration = configuration;
|
|
_tokenHelper = tokenHelper;
|
|
_apiConfigurationService = apiConfigurationService;
|
|
}
|
|
#region SendRequest service
|
|
public async Task<POVM> SendPostApiRequest(User user,
|
|
POVM viewModel, string apiEndpoint)
|
|
{
|
|
var token = await _tokenHelper.GetValidTokenAsync();
|
|
var responseObject = new ResponseObject();
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
viewModel.UserId = user.UserId;
|
|
var jsonContent = JsonSerializer.Serialize(viewModel);
|
|
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
|
|
|
|
using (var httpClient = _apiConfigurationService.CreateHttpClientWithDefaultHeaders(token))
|
|
{
|
|
HttpResponseMessage response;
|
|
|
|
response = await httpClient.PostAsync(apiEndpoint, content);
|
|
responseObject = JsonSerializer.Deserialize<ResponseObject>(await response.Content.ReadAsStringAsync());
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
viewModel.Message = responseObject.message;
|
|
viewModel.messCode = 1;
|
|
viewModel.Data = responseObject.data;
|
|
return viewModel;
|
|
}
|
|
else
|
|
{
|
|
viewModel.Message = responseObject.message;
|
|
viewModel.messCode = 0;
|
|
return viewModel;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
viewModel.Message = responseObject.message;
|
|
viewModel.messCode = 0;
|
|
return viewModel;
|
|
}
|
|
}
|
|
public async Task<List<POVM>> SendGetApiRequest(User user,
|
|
POVM viewModel,
|
|
string apiEndpoint)
|
|
{
|
|
var token = await _tokenHelper.GetValidTokenAsync();
|
|
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
// Handle token retrieval failure
|
|
return null;
|
|
}
|
|
|
|
viewModel.UserId = user.UserId;
|
|
var jsonContent = JsonSerializer.Serialize(viewModel);
|
|
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
|
|
|
|
using (var httpClient = _apiConfigurationService.CreateHttpClientWithDefaultHeaders(token))
|
|
{
|
|
HttpResponseMessage response;
|
|
|
|
response = await httpClient.PostAsync(apiEndpoint, content);
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var jsonResponse = await response.Content.ReadAsStringAsync();
|
|
|
|
var options = new JsonSerializerOptions
|
|
{
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
|
};
|
|
var myPOs = JsonSerializer.Deserialize<List<POVM>>(jsonResponse, options);
|
|
if(myPOs.Count > 0) {
|
|
myPOs[0].URL = _configuration["CommonEndpoints:ApiDefaultHeaders:ESignaturePath"];
|
|
myPOs[0].URLImg = _configuration["CommonEndpoints:ApiDefaultHeaders:ItemImages"];
|
|
}
|
|
return myPOs;
|
|
}
|
|
else
|
|
{
|
|
// Handle API request failure
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Get
|
|
|
|
public async Task<List<POVM>?> GetIncotermsByName(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetIncotermsByName"]);
|
|
}
|
|
public async Task<List<POVM>?> GetPOListByTerm(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetPOListByTerm"]);
|
|
}
|
|
public async Task<List<POVM>?> GetIncomingShipment(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetIncomingShipment"]);
|
|
}
|
|
public async Task<List<POVM>> GetSupplierBidById(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetSupplierBidById"]);
|
|
}
|
|
public async Task<List<POVM>> GetForPO(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetForPO"]);
|
|
}
|
|
public async Task<List<POVM>> GetForPOApproval(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetForPOApproval"]);
|
|
}
|
|
public async Task<List<POVM>> GetForPOApprovalByPRNo(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetForPOApprovalByPRNo"]);
|
|
}
|
|
public async Task<List<POVM>> GetSupplierBidByItem(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetSupplierBidByItem"]);
|
|
}
|
|
public async Task<List<POVM>?> GetPOItemDetail(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetPOItemDetail"]);
|
|
}
|
|
public async Task<List<POVM>> GetSupplierBid(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:CanvassMgmt:GetSupplierBid"]);
|
|
}
|
|
public async Task<List<POVM>> GetForBiddingApproval(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetForBiddingApproval"]);
|
|
}
|
|
public async Task<List<POVM>> GetForPOPerSuppEmail(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetForPOPerSuppEmail"]);
|
|
}
|
|
public async Task<List<POVM>> GetApprovedPO(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetApprovedPO"]);
|
|
}
|
|
public async Task<List<POVM>> GetApprovedPOPerEmail(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetApprovedPOPerEmail"]);
|
|
}
|
|
public async Task<List<POVM>?> GetPaymentTerms(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetPaymentTerms"]);
|
|
}
|
|
public async Task<List<POVM>?> GetLatestPO(User user, POVM viewModels)
|
|
{
|
|
return await SendGetApiRequest(user, viewModels,
|
|
_configuration["LLI:NonInvent:POMgmt:GetLatestPO"]);
|
|
}
|
|
public async Task<List<POVM>?> GetLatestPO2(User user, POVM viewModels)
|
|
{
|
|
return await SendGetApiRequest(user, viewModels,
|
|
_configuration["LLI:NonInvent:POMgmt:GetLatestPO2"]);
|
|
}
|
|
public async Task<List<POVM>?> GetDocRequired(User user, POVM viewModels)
|
|
{
|
|
return await SendGetApiRequest(user, viewModels,
|
|
_configuration["LLI:NonInvent:POMgmt:GetDocRequired"]);
|
|
}
|
|
public async Task<List<POVM>?> GetOtherCharges(User user, POVM viewModels)
|
|
{
|
|
return await SendGetApiRequest(user, viewModels,
|
|
_configuration["LLI:NonInvent:POMgmt:GetOtherCharges"]);
|
|
}
|
|
public async Task<List<POVM>?> GetSuppliers(User user, POVM viewModels)
|
|
{
|
|
return await SendGetApiRequest(user, viewModels,
|
|
_configuration["LLI:NonInvent:POMgmt:GetSuppliers"]);
|
|
}
|
|
|
|
public async Task<List<POVM>?> GetPRWOCanvass(User user, POVM viewModels)
|
|
{
|
|
return await SendGetApiRequest(user, viewModels,
|
|
_configuration["LLI:NonInvent:POMgmt:GetPRWOCanvass"]);
|
|
}
|
|
public async Task<List<POVM>?> GetCreatedPO(User user, POVM viewModels)
|
|
{
|
|
return await SendGetApiRequest(user, viewModels,
|
|
_configuration["LLI:NonInvent:POMgmt:GetCreatedPO"]);
|
|
}
|
|
public async Task<List<POVM>?> GetCreatedPOPerSupId(User user, POVM viewModels)
|
|
{
|
|
return await SendGetApiRequest(user, viewModels,
|
|
_configuration["LLI:NonInvent:POMgmt:GetCreatedPOPerSupId"]);
|
|
}
|
|
public async Task<List<POVM>?> GetPRItemDetail(User user, POVM viewModels)
|
|
{
|
|
return await SendGetApiRequest(user, viewModels,
|
|
_configuration["LLI:NonInvent:POMgmt:GetPRItemDetail"]);
|
|
}
|
|
|
|
public async Task<List<POVM>?> GetMyCreatedPO(User user, POVM viewModels)
|
|
{
|
|
return await SendGetApiRequest(user, viewModels,
|
|
_configuration["LLI:NonInvent:POMgmt:GetMyCreatedPO"]);
|
|
}
|
|
public async Task<List<POVM>?> GetPODetailBySuppierId(User user, POVM viewModels)
|
|
{
|
|
return await SendGetApiRequest(user, viewModels,
|
|
_configuration["LLI:NonInvent:POMgmt:GetPODetailBySuppierId"]);
|
|
}
|
|
public async Task<List<POVM>?> GetIncoterms(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetIncoterms"]);
|
|
}
|
|
public async Task<List<POVM>?> GetPRPOSummaryReport(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetPRPOSummaryReport"]);
|
|
}
|
|
public async Task<List<POVM>?> GetPRPOSummaryItem(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetPRPOSummaryItem"]);
|
|
}
|
|
public async Task<List<POVM>?> GetIndexCard(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetIndexCard"]);
|
|
}
|
|
public async Task<List<POVM>?> GetPortOfDischarge(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetPortOfDischarge"]);
|
|
}
|
|
public async Task<List<POVM>> GetCurrencies(User user, POVM viewModel)
|
|
{
|
|
return await SendGetApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:GetCurrencies"]);
|
|
}
|
|
#endregion
|
|
#region Post Put
|
|
public async Task<POVM> PostApprovedSupplier(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PostApprovedSupplier"]);
|
|
}
|
|
public async Task<POVM> PostApprovedPO(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PostApprovedPO"]);
|
|
}
|
|
public async Task<POVM> PostApprovedSuggested(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PostApprovedSuggested"]);
|
|
}
|
|
public async Task<POVM> PostPutPO(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PostPutPO"]);
|
|
}
|
|
public async Task<POVM> PostPOToSupplier(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PostPOToSupplier"]);
|
|
}
|
|
public async Task<POVM> PostPutCustomPO(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PostPutCustomPO"]);
|
|
}
|
|
public async Task<POVM> PutPRItemDetails(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PutPRItemDetails"]);
|
|
}
|
|
public async Task<POVM> PutMyPONo(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PutMyPONo"]);
|
|
}
|
|
public async Task<POVM> PutPOItemDetail(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PutPOItemDetail"]);
|
|
}
|
|
public async Task<POVM> ApprovedSelectedPO(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:ApprovedSelectedPO"]);
|
|
}
|
|
public async Task<POVM> PostPutDocRequired(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PostPutDocRequired"]);
|
|
}
|
|
public async Task<POVM> PutPOCancel(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PutPOCancel"]);
|
|
}
|
|
public async Task<POVM> PostPutOtherCharges(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PostPutOtherCharges"]);
|
|
}
|
|
public async Task<POVM> PostPutIncoterms(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:PostPutIncoterms"]);
|
|
}
|
|
|
|
public async Task<POVM> DeleteIncShip(User user, POVM viewModel)
|
|
{
|
|
return await SendPostApiRequest(user, viewModel,
|
|
_configuration["LLI:NonInvent:POMgmt:DeleteIncShip"]);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|