DigitalData.StaffDBServer/StaffDBServer/Controllers/WindreamSearchToDepartmentController.cs

54 lines
2.2 KiB
C#

using DAL.Models.Entities;
using DAL.Models.Filters;
using DAL.Repositories;
using HRD.LDAPService.JWT;
using HRD.WebApi.Controllers;
using HRD.WebApi.Repositories;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace StaffDBServer.Controllers
{
[JWTAuthorize]
public class WindreamSearchToDepartmentController : BaseController<WindreamSearchToDepartment>
{
public WindreamSearchToDepartmentController(IBaseRepository<WindreamSearchToDepartment> repositoryBase) : base(repositoryBase)
{
}
[HttpPost("DepartmentFilter")]
public async Task<IActionResult> GetWindreamSearchToDepartmentListAsync([FromBody] DepartmentFilter filter)
{
try
{
var list = await ((WindreamSearchToDepartmentRepository)EntityRepository).GetListByFilterAsync(filter);
return new OkObjectResult(list);
}
catch (Exception ex)
{
this.WriteLogException(ex);
return StatusCode(StatusCodes.Status400BadRequest, $"Cann't get the filtered list of {typeof(WindreamSearchToDepartment).Name}");
}
}
[HttpPut("CopyWindreamTile/{WindreamSearchToDepartmentId}")]
public async Task<IActionResult> GetVisitorListAsync(int WindreamSearchToDepartmentId, [FromBody] List<int> trgDepartmentIds)
{
var strTrgDepartmentIds = string.Join(",", trgDepartmentIds);
try
{
await ((WindreamSearchToDepartmentRepository)EntityRepository).AddWindreamTile(WindreamSearchToDepartmentId, strTrgDepartmentIds);
this.WriteLogWarn($"Windream Search Tile Id={WindreamSearchToDepartmentId} is added to Departments wit Ids={strTrgDepartmentIds}");
return new OkObjectResult(true);
}
catch (Exception ex)
{
this.WriteLogException(ex);
return StatusCode(StatusCodes.Status400BadRequest, $"Cann't add Windream Search Tile Id={WindreamSearchToDepartmentId} to Departments wit Ids={strTrgDepartmentIds}");
}
}
}
}