implement brand, material and customer and change the response format when got bad request
This commit is contained in:
parent
ad9694f85d
commit
18891cd584
|
|
@ -727,13 +727,13 @@ namespace OnlineSalesAutoCrop.CoreAPI.Models
|
||||||
|
|
||||||
public enum UserRoleTypeEnum
|
public enum UserRoleTypeEnum
|
||||||
{
|
{
|
||||||
[Description("SAP User")]
|
|
||||||
SapUser = 1,
|
|
||||||
[Description("Order Collector")]
|
[Description("Order Collector")]
|
||||||
OrderCollector = 2,
|
OrderCollector = 1,
|
||||||
[Description("OrderValidator")]
|
[Description("OrderValidator")]
|
||||||
OrderValidator = 3,
|
OrderValidator = 2,
|
||||||
[Description("OrderApprover")]
|
[Description("OrderApprover")]
|
||||||
OrderApprover =4
|
OrderApprover = 3 ,
|
||||||
|
[Description("SAP User")]
|
||||||
|
SapUser = 4 ,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,4 +27,13 @@ namespace OnlineSalesAutoCrop.CoreAPI.Models.Requests
|
||||||
{
|
{
|
||||||
public string AuthenticationId { get; set; }
|
public string AuthenticationId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract class PagedRequest
|
||||||
|
{
|
||||||
|
[Range(1, int.MaxValue, ErrorMessage = "PageNumber must be at least 1.")]
|
||||||
|
public int PageNumber { get; set; } = 1;
|
||||||
|
|
||||||
|
[Range(1, 1000, ErrorMessage = "PageSize must be between 1 and 1000.")]
|
||||||
|
public int PageSize { get; set; } = 1000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,21 @@ public class GetMarketHeirarchyByEmpRequest
|
||||||
[Required, NotNull, StringLength(maximumLength: 10, MinimumLength = 3, ErrorMessage = "EmployeeNumber must be between 3 and 10 characters.")]
|
[Required, NotNull, StringLength(maximumLength: 10, MinimumLength = 3, ErrorMessage = "EmployeeNumber must be between 3 and 10 characters.")]
|
||||||
public string EmployeeNumber { get; set; }
|
public string EmployeeNumber { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class GetBrandsRequest : PagedRequest
|
||||||
|
{
|
||||||
|
public string? BrandCode { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class GetMaterialsRequest : PagedRequest
|
||||||
|
{
|
||||||
|
public string? BrandCode { get; set; }
|
||||||
|
public string? MaterialCode { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetCustomersRequest : PagedRequest
|
||||||
|
{
|
||||||
|
public string? TeritoryCode { get; set; }
|
||||||
|
public string? CustomerCode { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,133 @@
|
||||||
namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses.MobileApp;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses.MobileApp;
|
||||||
|
|
||||||
public class MarketHeirarchyByEmpResponse
|
public class MarketHeirarchyByEmpResponse
|
||||||
{
|
{
|
||||||
|
public MarketHeirarchyByEmpResponse()
|
||||||
|
{
|
||||||
|
Companies = new List<EmpCompanyResponse>();
|
||||||
|
SalesOrgs = new List<SalesOrgResponse>();
|
||||||
|
DistributionChannels = new List<DistibutionChannleResponse>();
|
||||||
|
Regions = new List<RegionResponse>();
|
||||||
|
Areas = new List<AreaResponse>();
|
||||||
|
Teritories = new List<TeritoryResponse>();
|
||||||
|
Plants = new List<PlantResponse>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IList<EmpCompanyResponse> Companies { get; set; }
|
||||||
|
public IList<SalesOrgResponse> SalesOrgs { get; set; }
|
||||||
|
public IList<DistibutionChannleResponse> DistributionChannels { get; set; }
|
||||||
|
public IList<RegionResponse> Regions { get; set; }
|
||||||
|
public IList<AreaResponse> Areas { get; set; }
|
||||||
|
public IList<TeritoryResponse> Teritories { get; set; }
|
||||||
|
public IList<PlantResponse> Plants { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EmpCompanyResponse
|
||||||
|
{
|
||||||
|
public string Code { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SalesOrgResponse
|
||||||
|
{
|
||||||
|
public string CompanyCode { get; set; }
|
||||||
|
public string Code { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DistibutionChannleResponse
|
||||||
|
{
|
||||||
|
public string CompanyCode { get; set; }
|
||||||
|
public string SalesOrgCode { get; set; }
|
||||||
|
public string Code { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RegionResponse
|
||||||
|
{
|
||||||
|
public string CompanyCode { get; set; }
|
||||||
|
public string SalesOrgCode { get; set; }
|
||||||
|
public string Code { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AreaResponse
|
||||||
|
{
|
||||||
|
public string CompanyCode { get; set; }
|
||||||
|
public string SalesOrgCode { get; set; }
|
||||||
|
public string RegionCode { get; set; }
|
||||||
|
public string Code { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TeritoryResponse
|
||||||
|
{
|
||||||
|
public string CompanyCode { get; set; }
|
||||||
|
public string SalesOrgCode { get; set; }
|
||||||
|
public string RegionCode { get; set; }
|
||||||
|
public string AreaCode { get; set; }
|
||||||
|
public string Code { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PlantResponse
|
||||||
|
{
|
||||||
|
public string CompanyCode { get; set; }
|
||||||
|
public string SalesOrgCode { get; set; }
|
||||||
|
public string Code { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class GetBrandResponse
|
||||||
|
{
|
||||||
|
public string BrandCode { get; set; } = string.Empty;
|
||||||
|
public string BrandName { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class GetMaterialResponse
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Code { get; set; }
|
||||||
|
public string TypeCode { get; set; }
|
||||||
|
public string TypeName { get; set; }
|
||||||
|
public string GroupCode { get; set; }
|
||||||
|
public string GroupName { get; set; }
|
||||||
|
public string BaseUnitMeasurement { get; set; }
|
||||||
|
public string SalesUnitMeasurement { get; set; }
|
||||||
|
public decimal UnitConversionValue { get; set; }
|
||||||
|
public string BrandCode { get; set; }
|
||||||
|
public string BrandName { get; set; }
|
||||||
|
public string SalesOrg { get; set; }
|
||||||
|
public decimal BasePrice { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class GetCustomerResponse
|
||||||
|
{
|
||||||
|
public string Code { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string AccountGroupCode { get; set; }
|
||||||
|
public string AccountGroupDescription { get; set; }
|
||||||
|
public string DistributionChannelCode { get; set; }
|
||||||
|
public string DistributionChannelName { get; set; }
|
||||||
|
public string DivisionCode { get; set; }
|
||||||
|
public string DivisionName { get; set; }
|
||||||
|
public string MobileNumber { get; set; }
|
||||||
|
public string EmailAddress { get; set; }
|
||||||
|
public string TaxNumber { get; set; }
|
||||||
|
public string SalesGroupCode { get; set; }
|
||||||
|
public string SalesGroupName { get; set; }
|
||||||
|
public string CustomerGroupCode { get; set; }
|
||||||
|
public string CustomerGroupName { get; set; }
|
||||||
|
public string CustomerPriceGroupCode { get; set; }
|
||||||
|
public string CustomerPriceGroupName { get; set; }
|
||||||
|
public string PaymentTermCode { get; set; }
|
||||||
|
public string TeritoryCode { get; set; }
|
||||||
|
public string PlantCode { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Global;
|
using OnlineSalesAutoCrop.CoreAPI.Models.Global;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Objects;
|
using OnlineSalesAutoCrop.CoreAPI.Models.Objects;
|
||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses
|
namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses
|
||||||
{
|
{
|
||||||
|
|
@ -64,4 +66,15 @@ namespace OnlineSalesAutoCrop.CoreAPI.Models.Responses
|
||||||
{
|
{
|
||||||
public List<FoundKeywordItem> FoundKeywords { get; set; }
|
public List<FoundKeywordItem> FoundKeywords { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class PagedResult<T>
|
||||||
|
{
|
||||||
|
public IList<T> Items { get; set; } = [];
|
||||||
|
public int TotalCount { get; set; }
|
||||||
|
public int PageNumber { get; set; } = 1;
|
||||||
|
public int PageSize { get; set; } = 10000;
|
||||||
|
public int TotalPages => (int)Math.Ceiling((double)TotalCount / PageSize);
|
||||||
|
public bool HasNextPage => PageNumber < TotalPages;
|
||||||
|
public bool HasPreviousPage => PageNumber > 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.MobileApp;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.MobileApp;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OnlineSalesAutoCrop.CoreAPI.Services.Contracts.MobileApp;
|
||||||
|
|
||||||
|
public interface IMobileMasterDataService
|
||||||
|
{
|
||||||
|
Task<MarketHeirarchyByEmpResponse> GetMarketHeirarchiesByEmpAsync(GetMarketHeirarchyByEmpRequest request);
|
||||||
|
Task<PagedResult<GetBrandResponse>> GetBrandsAsync(GetBrandsRequest request);
|
||||||
|
Task<PagedResult<GetMaterialResponse>> GetMaterialsAsync(GetMaterialsRequest request);
|
||||||
|
Task<PagedResult<GetCustomerResponse>> GetCustomersAsync(GetCustomersRequest request);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,505 @@
|
||||||
|
using Ease.NetCore.DataAccess;
|
||||||
|
using Ease.NetCore.DataAccess.SQL;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using MySqlX.XDevAPI.Common;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Global;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.MobileApp;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.MobileApp;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.MobileApp;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Systems;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OnlineSalesAutoCrop.CoreAPI.Services.Services.MobileApp;
|
||||||
|
|
||||||
|
public class MobileMasterDataService : IMobileMasterDataService
|
||||||
|
{
|
||||||
|
private readonly AppSettings _settings;
|
||||||
|
private readonly IUserService _userService;
|
||||||
|
|
||||||
|
public MobileMasterDataService(IOptions<AppSettings> options, IUserService userService)
|
||||||
|
{
|
||||||
|
_settings = options.Value;
|
||||||
|
_userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MarketHeirarchyByEmpResponse> GetMarketHeirarchiesByEmpAsync(GetMarketHeirarchyByEmpRequest request)
|
||||||
|
{
|
||||||
|
|
||||||
|
MarketHeirarchyByEmpResponse response = new();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string employeeNumber = request.EmployeeNumber;
|
||||||
|
|
||||||
|
response.Companies = await GetCompaniesByEmployeeNumberAsync(tc, employeeNumber);
|
||||||
|
response.SalesOrgs = await GetSalesOrgsByEmployeeNumberAsync(tc, employeeNumber);
|
||||||
|
response.DistributionChannels = await GetDistributionChannelsByEmployeeNumberAsync(tc, employeeNumber);
|
||||||
|
response.Regions = await GetRegionsByEmployeeNumberAsync(tc, employeeNumber);
|
||||||
|
response.Areas = await GetAreasByEmployeeNumberAsync(tc, employeeNumber);
|
||||||
|
response.Teritories = await GetTerritoriesByEmployeeNumberAsync(tc, employeeNumber);
|
||||||
|
response.Plants = await GetPlantsByEmployeeNumberAsync(tc, employeeNumber);
|
||||||
|
|
||||||
|
tc.End();
|
||||||
|
}
|
||||||
|
catch (Exception ie)
|
||||||
|
{
|
||||||
|
tc?.HandleError();
|
||||||
|
|
||||||
|
throw DBCustomError.GenerateCustomError(ie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PagedResult<GetBrandResponse>> GetBrandsAsync(GetBrandsRequest request)
|
||||||
|
{
|
||||||
|
PagedResult<GetBrandResponse> response = new();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@BrandCode", pType: SqlDbType.VarChar, pValue: request.BrandCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@PageNumber", pType: SqlDbType.Int, pValue: request.PageNumber),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@PageSize", pType: SqlDbType.Int, pValue: request.PageSize)
|
||||||
|
];
|
||||||
|
|
||||||
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetBrandsPaginated", parameterValues: p))
|
||||||
|
{
|
||||||
|
if (dr.Read())
|
||||||
|
{
|
||||||
|
response.TotalCount = dr.GetInt32(0);
|
||||||
|
response.PageNumber = request.PageNumber;
|
||||||
|
response.PageSize = request.PageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second result set: paginated brand data
|
||||||
|
dr.NextResult();
|
||||||
|
|
||||||
|
|
||||||
|
while (dr.Read())
|
||||||
|
{
|
||||||
|
response.Items.Add(new GetBrandResponse
|
||||||
|
{
|
||||||
|
BrandCode = dr.GetString(0),
|
||||||
|
BrandName = dr.GetString(1)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dr.Close();
|
||||||
|
|
||||||
|
}
|
||||||
|
tc.End();
|
||||||
|
}
|
||||||
|
catch (Exception ie)
|
||||||
|
{
|
||||||
|
tc?.HandleError();
|
||||||
|
|
||||||
|
throw DBCustomError.GenerateCustomError(ie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<PagedResult<GetMaterialResponse>> GetMaterialsAsync(GetMaterialsRequest request)
|
||||||
|
{
|
||||||
|
PagedResult<GetMaterialResponse> response = new();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@BrandCode", pType: SqlDbType.VarChar, pValue: request.BrandCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@MaterialCode", pType: SqlDbType.VarChar, pValue: request.MaterialCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@PageNumber", pType: SqlDbType.Int, pValue: request.PageNumber),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@PageSize", pType: SqlDbType.Int, pValue: request.PageSize)
|
||||||
|
];
|
||||||
|
|
||||||
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetMaterialsPaginated", parameterValues: p))
|
||||||
|
{
|
||||||
|
if (dr.Read())
|
||||||
|
{
|
||||||
|
response.TotalCount = dr.GetInt32(0);
|
||||||
|
response.PageNumber = request.PageNumber;
|
||||||
|
response.PageSize = request.PageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second result set: paginated brand data
|
||||||
|
dr.NextResult();
|
||||||
|
|
||||||
|
|
||||||
|
while (dr.Read())
|
||||||
|
{
|
||||||
|
response.Items.Add(new GetMaterialResponse
|
||||||
|
{
|
||||||
|
Code = dr.GetString(0),
|
||||||
|
Name = dr.GetString(1),
|
||||||
|
TypeCode = dr.GetString(2),
|
||||||
|
TypeName = dr.GetString(3),
|
||||||
|
GroupCode = dr.GetString(4),
|
||||||
|
GroupName = dr.GetString(5),
|
||||||
|
BaseUnitMeasurement = dr.GetString(6),
|
||||||
|
SalesUnitMeasurement = dr.GetString(7),
|
||||||
|
UnitConversionValue = dr.GetDecimal(8),
|
||||||
|
BrandCode = dr.GetString(9),
|
||||||
|
BrandName = dr.GetString(10),
|
||||||
|
SalesOrg = dr.GetString(11),
|
||||||
|
BasePrice = dr.GetDecimal(12)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dr.Close();
|
||||||
|
|
||||||
|
}
|
||||||
|
tc.End();
|
||||||
|
}
|
||||||
|
catch (Exception ie)
|
||||||
|
{
|
||||||
|
tc?.HandleError();
|
||||||
|
|
||||||
|
throw DBCustomError.GenerateCustomError(ie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PagedResult<GetCustomerResponse>> GetCustomersAsync(GetCustomersRequest request)
|
||||||
|
{
|
||||||
|
PagedResult<GetCustomerResponse> response = new();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using TransactionContext tc = await TransactionContext.BeginAsync(_settings.DefaultConnection.ConnectionNode);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@TeritoryCode", pType: SqlDbType.VarChar, pValue: request.TeritoryCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@CustomerCode", pType: SqlDbType.VarChar, pValue: request.CustomerCode),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@PageNumber", pType: SqlDbType.Int, pValue: request.PageNumber),
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@PageSize", pType: SqlDbType.Int, pValue: request.PageSize)
|
||||||
|
];
|
||||||
|
|
||||||
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetCustomersPaginated", parameterValues: p))
|
||||||
|
{
|
||||||
|
if (dr.Read())
|
||||||
|
{
|
||||||
|
response.TotalCount = dr.GetInt32(0);
|
||||||
|
response.PageNumber = request.PageNumber;
|
||||||
|
response.PageSize = request.PageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second result set: paginated brand data
|
||||||
|
dr.NextResult();
|
||||||
|
|
||||||
|
|
||||||
|
while (dr.Read())
|
||||||
|
{
|
||||||
|
response.Items.Add(new GetCustomerResponse
|
||||||
|
{
|
||||||
|
Code = dr.GetString(0),
|
||||||
|
Name = dr.GetString(1),
|
||||||
|
AccountGroupCode = dr.GetString(2),
|
||||||
|
AccountGroupDescription = dr.GetString(3),
|
||||||
|
DistributionChannelCode = dr.GetString(4),
|
||||||
|
DistributionChannelName = dr.GetString(5),
|
||||||
|
DivisionCode = dr.GetString(6),
|
||||||
|
DivisionName = dr.GetString(7),
|
||||||
|
MobileNumber = dr.GetString(8),
|
||||||
|
EmailAddress = dr.GetString(9),
|
||||||
|
TaxNumber = dr.GetString(10),
|
||||||
|
SalesGroupCode = dr.GetString(11),
|
||||||
|
SalesGroupName = dr.GetString(12),
|
||||||
|
CustomerGroupCode = dr.GetString(13),
|
||||||
|
CustomerGroupName = dr.GetString(14),
|
||||||
|
CustomerPriceGroupCode = dr.GetString(15),
|
||||||
|
CustomerPriceGroupName = dr.GetString(16),
|
||||||
|
PaymentTermCode = dr.GetString(17),
|
||||||
|
TeritoryCode = dr.GetString(18),
|
||||||
|
PlantCode = dr.GetString(19)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dr.Close();
|
||||||
|
|
||||||
|
}
|
||||||
|
tc.End();
|
||||||
|
}
|
||||||
|
catch (Exception ie)
|
||||||
|
{
|
||||||
|
tc?.HandleError();
|
||||||
|
|
||||||
|
throw DBCustomError.GenerateCustomError(ie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<List<EmpCompanyResponse>> GetCompaniesByEmployeeNumberAsync(TransactionContext tc, string employeeNumber)
|
||||||
|
{
|
||||||
|
List<EmpCompanyResponse> response = [];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeNumber", pType: SqlDbType.NVarChar, pValue: employeeNumber)
|
||||||
|
];
|
||||||
|
|
||||||
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetCompaniesByEmployeeNumber", parameterValues: p))
|
||||||
|
{
|
||||||
|
while (dr.Read())
|
||||||
|
{
|
||||||
|
response.Add(new EmpCompanyResponse
|
||||||
|
{
|
||||||
|
Code = dr.GetString(0),
|
||||||
|
Name = dr.GetString(1)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dr.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw DBCustomError.GenerateCustomError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<List<SalesOrgResponse>> GetSalesOrgsByEmployeeNumberAsync(TransactionContext tc, string employeeNumber)
|
||||||
|
{
|
||||||
|
List<SalesOrgResponse> response = [];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeNumber", pType: SqlDbType.NVarChar, pValue: employeeNumber)
|
||||||
|
];
|
||||||
|
|
||||||
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetSalesOrgsByEmployeeNumber", parameterValues: p))
|
||||||
|
{
|
||||||
|
while (dr.Read())
|
||||||
|
{
|
||||||
|
response.Add(new SalesOrgResponse
|
||||||
|
{
|
||||||
|
CompanyCode = dr.GetString(0),
|
||||||
|
Code = dr.GetString(1),
|
||||||
|
Name = dr.GetString(2)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dr.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw DBCustomError.GenerateCustomError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<List<DistibutionChannleResponse>> GetDistributionChannelsByEmployeeNumberAsync(TransactionContext tc, string employeeNumber)
|
||||||
|
{
|
||||||
|
List<DistibutionChannleResponse> response = [];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeNumber", pType: SqlDbType.NVarChar, pValue: employeeNumber)
|
||||||
|
];
|
||||||
|
|
||||||
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetDistributionChannelsByEmployeeNumber", parameterValues: p))
|
||||||
|
{
|
||||||
|
while (dr.Read())
|
||||||
|
{
|
||||||
|
response.Add(new DistibutionChannleResponse
|
||||||
|
{
|
||||||
|
CompanyCode = dr.GetString(0),
|
||||||
|
SalesOrgCode = dr.GetString(1),
|
||||||
|
Code = dr.GetString(2),
|
||||||
|
Name = dr.GetString(3)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dr.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw DBCustomError.GenerateCustomError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<List<RegionResponse>> GetRegionsByEmployeeNumberAsync(TransactionContext tc, string employeeNumber)
|
||||||
|
{
|
||||||
|
List<RegionResponse> response = [];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeNumber", pType: SqlDbType.NVarChar, pValue: employeeNumber)
|
||||||
|
];
|
||||||
|
|
||||||
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetRegionsByEmployeeNumber", parameterValues: p))
|
||||||
|
{
|
||||||
|
while (dr.Read())
|
||||||
|
{
|
||||||
|
response.Add(new RegionResponse
|
||||||
|
{
|
||||||
|
CompanyCode = dr.GetString(0),
|
||||||
|
SalesOrgCode = dr.GetString(1),
|
||||||
|
Code = dr.GetString(2),
|
||||||
|
Name = dr.GetString(3)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dr.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw DBCustomError.GenerateCustomError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<List<AreaResponse>> GetAreasByEmployeeNumberAsync(TransactionContext tc, string employeeNumber)
|
||||||
|
{
|
||||||
|
List<AreaResponse> response = [];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeNumber", pType: SqlDbType.NVarChar, pValue: employeeNumber)
|
||||||
|
];
|
||||||
|
|
||||||
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetAreasByEmployeeNumber", parameterValues: p))
|
||||||
|
{
|
||||||
|
while (dr.Read())
|
||||||
|
{
|
||||||
|
response.Add(new AreaResponse
|
||||||
|
{
|
||||||
|
CompanyCode = dr.GetString(0),
|
||||||
|
SalesOrgCode = dr.GetString(1),
|
||||||
|
RegionCode = dr.GetString(2),
|
||||||
|
Code = dr.GetString(3),
|
||||||
|
Name = dr.GetString(4)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dr.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw DBCustomError.GenerateCustomError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<List<TeritoryResponse>> GetTerritoriesByEmployeeNumberAsync(TransactionContext tc, string employeeNumber)
|
||||||
|
{
|
||||||
|
List<TeritoryResponse> response = [];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeNumber", pType: SqlDbType.NVarChar, pValue: employeeNumber)
|
||||||
|
];
|
||||||
|
|
||||||
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetTerritoriesByEmployeeNumber", parameterValues: p))
|
||||||
|
{
|
||||||
|
while (dr.Read())
|
||||||
|
{
|
||||||
|
response.Add(new TeritoryResponse
|
||||||
|
{
|
||||||
|
CompanyCode = dr.GetString(0),
|
||||||
|
SalesOrgCode = dr.GetString(1),
|
||||||
|
RegionCode = dr.GetString(2),
|
||||||
|
AreaCode = dr.GetString(3),
|
||||||
|
Code = dr.GetString(4),
|
||||||
|
Name = dr.GetString(5)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dr.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw DBCustomError.GenerateCustomError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<List<PlantResponse>> GetPlantsByEmployeeNumberAsync(TransactionContext tc, string employeeNumber)
|
||||||
|
{
|
||||||
|
List<PlantResponse> response = [];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SqlParameter[] p =
|
||||||
|
[
|
||||||
|
SqlHelperExtension.CreateInParam(pName: "@EmployeeNumber", pType: SqlDbType.NVarChar, pValue: employeeNumber)
|
||||||
|
];
|
||||||
|
|
||||||
|
using (IDataReader dr = await tc.ExecuteReaderSpAsync("dbo.GetPlantsByEmployeeNumber", parameterValues: p))
|
||||||
|
{
|
||||||
|
while (dr.Read())
|
||||||
|
{
|
||||||
|
response.Add(new PlantResponse
|
||||||
|
{
|
||||||
|
CompanyCode = dr.GetString(0),
|
||||||
|
SalesOrgCode = dr.GetString(1),
|
||||||
|
Code = dr.GetString(2),
|
||||||
|
Name = dr.GetString(3)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
dr.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw DBCustomError.GenerateCustomError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -406,16 +406,18 @@ namespace OnlineSalesAutoCrop.CoreAPI.Services.Services.Systems
|
||||||
if (user is null)
|
if (user is null)
|
||||||
{
|
{
|
||||||
tc.End();
|
tc.End();
|
||||||
throw new InvalidOperationException($"User not found with login: {request.LoginId}");
|
response.IsAuthorized = true;
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!password.Equals(user.Password))
|
if (!password.Equals(user.Password))
|
||||||
{
|
{
|
||||||
tc.End();
|
tc.End();
|
||||||
throw new InvalidOperationException($"Password mismatch for login: {request.LoginId}");
|
response.IsAuthorized = false;
|
||||||
|
response.LoginStatus = EnumLoginStatus.Unsuccessful;
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region If the user was locked, try set set unlock if Time expired
|
#region If the user was locked, try set set unlock if Time expired
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Auth;
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Auth;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Integrations;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.MobileApp;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Setups;
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Setups;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Systems;
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Systems;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Auth;
|
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Auth;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Integrations;
|
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Integrations;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Services.Services.MobileApp;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Setups;
|
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Setups;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Systems;
|
using OnlineSalesAutoCrop.CoreAPI.Services.Services.Systems;
|
||||||
|
|
||||||
|
|
@ -31,6 +33,7 @@ namespace OnlineSalesAutoCrop.CoreAPI.Configuration.DI
|
||||||
services.AddTransient<IAuthModulesService, AuthModulesService>();
|
services.AddTransient<IAuthModulesService, AuthModulesService>();
|
||||||
services.AddTransient<IRefreshTokenService, RefreshTokenService>();
|
services.AddTransient<IRefreshTokenService, RefreshTokenService>();
|
||||||
services.AddScoped<IIntegrationService, IntegrationService>();
|
services.AddScoped<IIntegrationService, IntegrationService>();
|
||||||
|
services.AddScoped<IMobileMasterDataService, MobileMasterDataService>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,13 +76,13 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers
|
||||||
if (string.IsNullOrEmpty(request.LoginId))
|
if (string.IsNullOrEmpty(request.LoginId))
|
||||||
{
|
{
|
||||||
string message = "Login ID is required.";
|
string message = "Login ID is required.";
|
||||||
return BadRequest(MobileResponseBase<AppAuthUserResponse>.Failure(message, StatusCodes.Status417ExpectationFailed));
|
return BadRequest(MobileResponseBase<AppAuthUserResponse>.Failure(message, StatusCodes.Status400BadRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(request.Password))
|
if (string.IsNullOrEmpty(request.Password))
|
||||||
{
|
{
|
||||||
string message = "Password is required.";
|
string message = "Password is required.";
|
||||||
return BadRequest(MobileResponseBase<AppAuthUserResponse>.Failure(message, StatusCodes.Status417ExpectationFailed));
|
return BadRequest(MobileResponseBase<AppAuthUserResponse>.Failure(message, StatusCodes.Status400BadRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -104,26 +104,25 @@ namespace OnlineSalesAutoCrop.CoreAPI.Controllers
|
||||||
if (loginReponse == null || loginReponse.UserId == 0)
|
if (loginReponse == null || loginReponse.UserId == 0)
|
||||||
{
|
{
|
||||||
string message = "Login ID/Password is invalid.\" : \"You are not Authorized to login into the System.";
|
string message = "Login ID/Password is invalid.\" : \"You are not Authorized to login into the System.";
|
||||||
return Unauthorized(MobileResponseBase<AppAuthUserResponse>.Failure(message, StatusCodes.Status403Forbidden));
|
return Unauthorized(MobileResponseBase<AppAuthUserResponse>.Failure(message, StatusCodes.Status401Unauthorized));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (loginReponse.LoginStatus == EnumLoginStatus.Unsuccessful)
|
if (loginReponse.LoginStatus == EnumLoginStatus.Unsuccessful)
|
||||||
{
|
{
|
||||||
string message = checkPwd ? $"Login ID/Password is invalid for {request.LoginId}." : "You are not Authorized to login into the System";
|
string message = checkPwd ? $"Login ID/Password is invalid for {request.LoginId}." : "You are not Authorized to login into the System";
|
||||||
return Unauthorized(MobileResponseBase<AppAuthUserResponse>.Failure(message, StatusCodes.Status403Forbidden));
|
return Unauthorized(MobileResponseBase<AppAuthUserResponse>.Failure(message, StatusCodes.Status401Unauthorized));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loginReponse.IsLocked)
|
if (loginReponse.IsLocked)
|
||||||
{
|
{
|
||||||
string message =$"Your Account is locked . Please try again after few minutes";
|
string message =$"Your Account is locked . Please try again after few minutes";
|
||||||
return Unauthorized(MobileResponseBase<AppAuthUserResponse>.Failure(message, StatusCodes.Status403Forbidden));
|
return Unauthorized(MobileResponseBase<AppAuthUserResponse>.Failure(message, StatusCodes.Status401Unauthorized));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loginReponse.IsAuthorized )
|
if (!loginReponse.IsAuthorized )
|
||||||
{
|
{
|
||||||
string message = $"You are not Authorized to Login into the System, Please contact with System Administrator.";
|
string message = $"You are not Authorized to Login into the System, Please contact with System Administrator.";
|
||||||
return Unauthorized(MobileResponseBase<AppAuthUserResponse>.Failure(message, StatusCodes.Status403Forbidden));
|
return Unauthorized(MobileResponseBase<AppAuthUserResponse>.Failure(message, StatusCodes.Status401Unauthorized));
|
||||||
}
|
}
|
||||||
|
|
||||||
string pwdSecretKey = GlobalFunctions.ConvertFromBase64String(_appSettings.PwdSecretKey);
|
string pwdSecretKey = GlobalFunctions.ConvertFromBase64String(_appSettings.PwdSecretKey);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,161 @@
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Global;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Objects.Systems;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.Common;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.Integrations;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.MobileApp;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Integrations;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.MobileApp;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.Systems;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Auth;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.MobileApp;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Systems;
|
||||||
|
using System;
|
||||||
|
using System.DirectoryServices;
|
||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using System.Runtime.Versioning;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OnlineSalesAutoCrop.CoreAPI.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="service"></param>
|
||||||
|
/// <param name="appSettings"></param>
|
||||||
|
/// <param name="cache"></param>
|
||||||
|
/// <param name="logger"></param>
|
||||||
|
[Authorize]
|
||||||
|
[ApiController]
|
||||||
|
[ApiVersion("1.0")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
[Route("api/mobile/v{version:apiVersion}/masterdata")]
|
||||||
|
public class MobileMasterDataController(IMobileMasterDataService service, IOptions<AppSettings> appSettings, IEaseCache cache, ILogger<IntegrationAuthController> logger) : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger = logger;
|
||||||
|
private readonly IEaseCache _cache = cache;
|
||||||
|
private readonly IMobileMasterDataService _service = service;
|
||||||
|
private readonly AppSettings _appSettings = appSettings?.Value;
|
||||||
|
private readonly DateTimeOffset _options = Helper.CreateEaseCacheOptions();
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Login using your credential data retrieve from SqlServer
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <response code="200">If login successful Return MarketHierarchies List</response>
|
||||||
|
[HttpGet("MarketHierarchies")]
|
||||||
|
[IgnoreAntiforgeryToken]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(MarketHeirarchyByEmpResponse))]
|
||||||
|
public async Task<IActionResult> EmployeeMarketHierarchies([FromQuery] GetMarketHeirarchyByEmpRequest request)
|
||||||
|
{
|
||||||
|
MarketHeirarchyByEmpResponse response = new();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = await _service.GetMarketHeirarchiesByEmpAsync(request);
|
||||||
|
return Ok(MobileResponseBase<MarketHeirarchyByEmpResponse>.Success(response));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string msg = $"Exception occur on MarketHeirarchys endpoint with employee request - {request?.EmployeeNumber}";
|
||||||
|
_logger.LogError(exception: ex, message: msg);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase<AppAuthUserResponse>.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Login using your credential data retrieve from SqlServer
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <response code="200">If login successful Return Brands List</response>
|
||||||
|
[HttpGet("Brands")]
|
||||||
|
[IgnoreAntiforgeryToken]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(MarketHeirarchyByEmpResponse))]
|
||||||
|
public async Task<IActionResult> Brands([FromQuery] GetBrandsRequest request)
|
||||||
|
{
|
||||||
|
PagedResult<GetBrandResponse> response = new();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = await _service.GetBrandsAsync(request);
|
||||||
|
return Ok(MobileResponseBase<PagedResult<GetBrandResponse>>.Success(response));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string msg = $"Exception occur on brands endpoint with employee request - {request?.BrandCode}";
|
||||||
|
_logger.LogError(exception: ex, message: msg);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase<AppAuthUserResponse>.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Login using your credential data retrieve from SqlServer
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <response code="200">If login successful Return Material List</response>
|
||||||
|
[HttpGet("Materials")]
|
||||||
|
[IgnoreAntiforgeryToken]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetMaterialResponse))]
|
||||||
|
public async Task<IActionResult> Materials([FromQuery] GetMaterialsRequest request)
|
||||||
|
{
|
||||||
|
PagedResult<GetMaterialResponse> response = new();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = await _service.GetMaterialsAsync(request);
|
||||||
|
return Ok(MobileResponseBase<PagedResult<GetMaterialResponse>>.Success(response));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string msg = $"Exception occur on Materials endpoint with employee request - {request?.BrandCode} -{request?.MaterialCode}";
|
||||||
|
_logger.LogError(exception: ex, message: msg);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase<AppAuthUserResponse>.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Login using your credential data retrieve from SqlServer
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <response code="200">If login successful Return Material List</response>
|
||||||
|
[HttpGet("Customers")]
|
||||||
|
[IgnoreAntiforgeryToken]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetCustomerResponse))]
|
||||||
|
public async Task<IActionResult> Customers([FromQuery] GetCustomersRequest request)
|
||||||
|
{
|
||||||
|
PagedResult<GetCustomerResponse> response = new();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = await _service.GetCustomersAsync(request);
|
||||||
|
return Ok(MobileResponseBase<PagedResult<GetCustomerResponse>>.Success(response));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
string msg = $"Exception occur on Materials endpoint with employee request - {request?.TeritoryCode} -{request?.CustomerCode}";
|
||||||
|
_logger.LogError(exception: ex, message: msg);
|
||||||
|
return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase<AppAuthUserResponse>.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<NameOfLastUsedPublishProfile>D:\Local\OnlineSalesAutoCrop\Api\OnlineSalesAutoCrop.CoreAPI\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
|
<NameOfLastUsedPublishProfile>FolderProfile</NameOfLastUsedPublishProfile>
|
||||||
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
|
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
|
||||||
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
|
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
|
||||||
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
|
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,5 @@
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using Asp.Versioning.ApiExplorer;
|
using Asp.Versioning.ApiExplorer;
|
||||||
using OnlineSalesAutoCrop.CoreAPI.API.Swagger;
|
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Configuration.DI;
|
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Configurations;
|
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models;
|
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Models.Global;
|
|
||||||
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Systems;
|
|
||||||
using OnlineSalesAutoCrop.CoreAPI.SignalRHub;
|
|
||||||
using Hangfire;
|
using Hangfire;
|
||||||
using Hangfire.SqlServer;
|
using Hangfire.SqlServer;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
|
@ -24,9 +17,18 @@ using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.API.Swagger;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Configuration.DI;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Configurations;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Global;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Models.Responses;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.Systems;
|
||||||
|
using OnlineSalesAutoCrop.CoreAPI.SignalRHub;
|
||||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
@ -82,6 +84,26 @@ namespace OnlineSalesAutoCrop.CoreAPI
|
||||||
options.Filters.Add(new ProducesAttribute("application/json"));
|
options.Filters.Add(new ProducesAttribute("application/json"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
services.Configure<ApiBehaviorOptions>(options =>
|
||||||
|
{
|
||||||
|
options.InvalidModelStateResponseFactory = context =>
|
||||||
|
{
|
||||||
|
var errors = context.ModelState
|
||||||
|
.Where(kvp => kvp.Value?.Errors.Count > 0)
|
||||||
|
.SelectMany(kvp => kvp.Value!.Errors.Select(e => e.ErrorMessage))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var response = new MobileResponseBase<object>
|
||||||
|
{
|
||||||
|
ReturnStatus = StatusCodes.Status400BadRequest,
|
||||||
|
ReturnMessage = errors,
|
||||||
|
Data = null
|
||||||
|
};
|
||||||
|
|
||||||
|
return new BadRequestObjectResult(response);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region API versioning
|
#region API versioning
|
||||||
|
|
|
||||||
13
Api/OnlineSalesAutoCrop.CoreAPI/dotnet-tools.json
Normal file
13
Api/OnlineSalesAutoCrop.CoreAPI/dotnet-tools.json
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"isRoot": true,
|
||||||
|
"tools": {
|
||||||
|
"dotnet-ef": {
|
||||||
|
"version": "10.0.9",
|
||||||
|
"commands": [
|
||||||
|
"dotnet-ef"
|
||||||
|
],
|
||||||
|
"rollForward": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user