using Asp.Versioning;
using DocumentFormat.OpenXml.Office2010.ExcelAc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OnlineSalesAutoCrop.CoreAPI;
using OnlineSalesAutoCrop.CoreAPI.Models.Global;
using OnlineSalesAutoCrop.CoreAPI.Models.Requests.MobileApp;
using OnlineSalesAutoCrop.CoreAPI.Models.Responses;
using OnlineSalesAutoCrop.CoreAPI.Models.Responses.MobileApp;
using OnlineSalesAutoCrop.CoreAPI.Services.Contracts.MobileApp;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace OnlineSalesAutoCrop.CoreAPI.Controllers
{
///
///
///
///
///
///
///
///
///
///
[Authorize]
[ApiController]
[ApiVersion("1.0")]
[ValidateAntiForgeryToken]
[Route("api/mobile/v{version:apiVersion}/masterdata")]
public class MobileMasterDataController(IMobileMasterDataService service, IOptions appSettings, IEaseCache cache, ILogger 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();
///
/// Login using your credential data retrieve from SqlServer
///
///
///
///
/// If login successful Return MarketHierarchies List
[HttpGet("MarketHierarchies")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(MarketHeirarchyByEmpResponse))]
public async Task EmployeeMarketHierarchies([FromQuery] GetMarketHeirarchyByEmpRequest request)
{
MarketHeirarchyByEmpResponse response = new();
try
{
response = await _service.GetMarketHeirarchiesByEmpAsync(request);
return Ok(MobileResponseBase.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.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
}
}
///
/// Login using your credential data retrieve from SqlServer
///
///
///
///
/// If login successful Return Brands List
[HttpGet("Brands")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(MarketHeirarchyByEmpResponse))]
public async Task Brands([FromQuery] GetBrandsRequest request)
{
PagedResult response = new();
try
{
response = await _service.GetBrandsAsync(request);
return Ok(MobileResponseBase>.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.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
}
}
///
/// Login using your credential data retrieve from SqlServer
///
///
///
///
/// If login successful Return Material List
[HttpGet("Materials")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetMaterialResponse))]
public async Task Materials([FromQuery] GetMaterialsRequest request)
{
PagedResult response = new();
try
{
response = await _service.GetMaterialsAsync(request);
return Ok(MobileResponseBase>.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.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
}
}
///
/// Login using your credential data retrieve from SqlServer
///
///
///
///
/// If login successful Return Material List
[HttpGet("CustomerWiseMaterialPrices")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetMaterialPriceResponse))]
public async Task GetCustomerWiseMaterialPrices([FromQuery] GetMaterialPriceRequest request)
{
PagedResult response = new();
try
{
response = await _service.GetMaterialPricesAsync(request);
return Ok(MobileResponseBase>.Success(response));
}
catch (Exception ex)
{
string msg = $"Exception occur on Materials prices endpoint with employee request - {request?.MaterialCode} -{request?.EmployeeNumber}";
_logger.LogError(exception: ex, message: msg);
return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
}
}
///
/// Login using your credential data retrieve from SqlServer
///
///
///
///
/// If login successful Return Material List
[HttpGet("Customers")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetCustomerResponse))]
public async Task Customers([FromQuery] GetCustomersRequest request)
{
PagedResult response = new();
try
{
response = await _service.GetCustomersAsync(request);
return Ok(MobileResponseBase>.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.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
}
}
///
/// Login using your credential data retrieve from SqlServer
///
///
///
///
/// If login successful Return Attendance List
[HttpGet("Attendance")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetAttendanceByEmpResponse))]
public async Task GetAttendance([FromQuery] GetAttendanceByEmpRequest request)
{
GetAttendanceByEmpResponse response = new();
try
{
response = await _service.GetAttendanceByEmpAsync(request);
return Ok(MobileResponseBase.Success(response));
}
catch (Exception ex)
{
string msg = $"Exception occur on Get Attendance endpoint with employee request - {request?.EmployeeNumber} -{request?.AttendanceDate}";
_logger.LogError(exception: ex, message: msg);
return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
}
}
///
/// Login using your credential data retrieve from SqlServer
///
///
///
///
/// If login successful Return Attendance List
[HttpPost("SaveAttendance")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetAttendanceByEmpResponse))]
public async Task UpsertAttendance([FromBody] UpsertAttendanceByEmpRequest request)
{
GetAttendanceByEmpResponse response = new();
try
{
response = await _service.UpsertAttendanceByEmpAsync(request);
return Ok(MobileResponseBase.Success(response));
}
catch (Exception ex)
{
string msg = $"Exception occur on Save Attendance endpoint with employee request - {request?.EmployeeNumber}";
_logger.LogError(exception: ex, message: msg);
return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
}
}
///
/// Login using your credential data retrieve from SqlServer
///
///
///
///
/// If login successful Return Attendance List
[HttpGet("Discounts")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetDiscountResponse))]
public async Task GetDiscounts([FromQuery] GetDiscountRequest request)
{
PagedResult response = new();
try
{
response = await _service.GetDiscountAsync(request);
return Ok(MobileResponseBase>.Success(response));
}
catch (Exception ex)
{
string msg = $"Exception occur on Get Discounts endpoint with request - {request?.EmployeeNumber} -{request?.DiscountCode}";
_logger.LogError(exception: ex, message: msg);
return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
}
}
///
/// Login using your credential data retrieve from SqlServer
///
///
///
///
/// If login successful Return Attendance List
[HttpGet("DiscountMaterials")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetDiscountMaterialResponse))]
public async Task GetDiscountMaterials([FromQuery] GetDiscountMaterialRequest request)
{
PagedResult response = new();
try
{
response = await _service.GetDiscountMaterialsAsync(request);
return Ok(MobileResponseBase>.Success(response));
}
catch (Exception ex)
{
string msg = $"Exception occur on Get DiscountMaterials endpoint with request - {request?.MaterialCode} -{request?.DiscountCode}";
_logger.LogError(exception: ex, message: msg);
return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
}
}
///
/// Login using your credential data retrieve from SqlServer
///
///
///
///
/// If login successful Return Attendance List
[HttpGet("MaterialFOCs")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetFOCResponse))]
public async Task GetMaterialFOCs([FromQuery] GetFOCRequest request)
{
PagedResult response = new();
try
{
response = await _service.GetFOCsAsync(request);
return Ok(MobileResponseBase>.Success(response));
}
catch (Exception ex)
{
string msg = $"Exception occur on Get MaterialFOCs endpoint with request - {request?.EmployeeNumber} -{request?.FOCCode}";
_logger.LogError(exception: ex, message: msg);
return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
}
}
///
/// Login using your credential data retrieve from SqlServer
///
///
///
///
/// If login successful Return Attendance List
[HttpGet("FOCsMaterials")]
[IgnoreAntiforgeryToken]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(GetFOCMaterialResponse))]
public async Task GetFOCsMaterials([FromQuery] GetFOCMaterialRequest request)
{
PagedResult response = new();
try
{
response = await _service.GetFOCMaterialsAsync(request);
return Ok(MobileResponseBase>.Success(response));
}
catch (Exception ex)
{
string msg = $"Exception occur on Get FOCsMaterials endpoint with request - {request?.MaterialCode} -{request?.FOCCode}";
_logger.LogError(exception: ex, message: msg);
return StatusCode(StatusCodes.Status500InternalServerError, MobileResponseBase.Failure(ex.InnerException != null ? ex.InnerException.Message : ex.Message, StatusCodes.Status500InternalServerError));
}
}
}
}