123 lines
4.3 KiB
C#
123 lines
4.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.Extensions.Logging;
|
|
using TTSW.Controllers;
|
|
using TTSW.EF;
|
|
using TTSW.Utils;
|
|
using TTSW.Constant;
|
|
using TTSW.Common;
|
|
using TodoAPI2.Models;
|
|
using System.Data;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System.IO;
|
|
using System.Net;
|
|
|
|
namespace TodoAPI2.Controllers
|
|
{
|
|
//[Authorize]
|
|
[Produces("application/json")]
|
|
[Route("api/rep_position_salary")]
|
|
public class rep_position_salaryController : BaseController
|
|
{
|
|
#region Private Variables
|
|
private ILogger<rep_position_salaryController> _logger;
|
|
private Irep_position_salaryService _repository;
|
|
private IConfiguration Configuration { get; set; }
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Default constructure for dependency injection
|
|
/// </summary>
|
|
/// <param name="repository"></param>
|
|
/// <param name="configuration"></param>
|
|
/// <param name="logger"></param>
|
|
public rep_position_salaryController(ILogger<rep_position_salaryController> logger, Irep_position_salaryService repository, IConfiguration configuration)
|
|
{
|
|
_logger = logger;
|
|
_repository = repository;
|
|
Configuration = configuration;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get Blank Item
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <returns>Return a blank item</returns>
|
|
/// <response code="200">Returns the item</response>
|
|
/// <response code="500">Error Occurred</response>
|
|
[HttpGet("GetBlankItem")]
|
|
[ProducesResponseType(typeof(rep_position_salaryWithSelectionViewModel), 200)]
|
|
[ProducesResponseType(400)]
|
|
[ProducesResponseType(500)]
|
|
//[ValidateAntiForgeryToken]
|
|
public IActionResult GetBlankItem()
|
|
{
|
|
try
|
|
{
|
|
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
|
|
var result = _repository.GetBlankItem();
|
|
|
|
return Ok(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogCritical($"Exception in IActionResult GetBlankItem.", ex);
|
|
return StatusCode(500, $"Exception in IActionResult GetBlankItem. {ex.Message}");
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Download Report
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// </remarks>
|
|
/// <returns>Return list of items by specifced keyword</returns>
|
|
/// <response code="200">Returns the item</response>
|
|
/// <response code="500">Error Occurred</response>
|
|
[HttpGet("rep_position_salary_report")]
|
|
[ProducesResponseType(typeof(FileStreamResult), 200)]
|
|
[ProducesResponseType(400)]
|
|
[ProducesResponseType(500)]
|
|
//[ValidateAntiForgeryToken]
|
|
public IActionResult rep_position_salary_report(rep_position_salaryReportRequestModel model)
|
|
{
|
|
try
|
|
{
|
|
if (!MyHelper.checkAuth(Configuration, HttpContext)) return Unauthorized();
|
|
//var httpclient = MyHelper.getHttpClient(Configuration);
|
|
var httpclient = new WebClient();
|
|
|
|
string mainurl = MyHelper.GetConfig(Configuration, "JasperReportServer:MainURL");
|
|
string reportsite = MyHelper.GetConfig(Configuration, "JasperReportServer:reportsite");
|
|
string username = MyHelper.GetConfig(Configuration, "JasperReportServer:username");
|
|
string password = MyHelper.GetConfig(Configuration, "JasperReportServer:password");
|
|
|
|
string url = $"{mainurl}{reportsite}/rep_position_salary.{model.filetype}?{MyHelper.GetParameterForJasperReport(model)}&j_username={username}&j_password={password}";
|
|
|
|
var data = httpclient.DownloadData(url);
|
|
var stream = new MemoryStream(data);
|
|
|
|
return File(stream, model.contentType);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogCritical($"Exception while GetReport.", ex);
|
|
return StatusCode(500, $"Exception while GetReport. {ex.Message}");
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|