Files
Backend-Api/ServiceHost/Areas/Admin/Controllers/LawController.cs

76 lines
2.2 KiB
C#

using _0_Framework.Application;
using CompanyManagment.App.Contracts.Law;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ServiceHost.BaseControllers;
namespace ServiceHost.Areas.Admin.Controllers;
public class LawController : AdminBaseController
{
private readonly ILawApplication _lawApplication;
public LawController(ILawApplication lawApplication)
{
_lawApplication = lawApplication;
}
/// <summary>
/// لیست قوانین بر اساس انواع تعریف شده در enum
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<ActionResult<List<LawViewModel>>> GetList(LawSearchModel searchModel)
{
return await _lawApplication.GetList(searchModel);
}
/// <summary>
/// جزئیات قانون بر اساس نوع
/// </summary>
/// <param name="type">نوع قانون</param>
/// <returns></returns>
[HttpGet("by-type/{type}")]
[AllowAnonymous]
public async Task<ActionResult<LawViewModel>> GetLawByType(LawType type)
{
return await _lawApplication.GetLawByType(type);
}
/// <summary>
/// ایجاد یا ویرایش قانون بر اساس نوع
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
[HttpPut("upsert")]
public ActionResult<OperationResult> UpsertLaw([FromBody] EditLaw command)
{
var result = _lawApplication.UpsertLaw(command);
return result;
}
/// <summary>
/// فعال‌سازی قانون
/// </summary>
/// <param name="type">نوع قانون</param>
/// <returns></returns>
[HttpPatch("{type}/activate")]
public ActionResult<OperationResult> Activate(LawType type)
{
var result = _lawApplication.ActivateByType(type);
return result;
}
/// <summary>
/// غیرفعال‌سازی قانون
/// </summary>
/// <param name="type">نوع قانون</param>
/// <returns></returns>
[HttpPatch("{type}/deactivate")]
public ActionResult<OperationResult> Deactivate(LawType type)
{
var result = _lawApplication.DeactivateByType(type);
return result;
}
}