Files
Hushian/Presentation/Hushian.WebApi/Controllers/v1/ExperController.cs

119 lines
5.4 KiB
C#
Raw Normal View History

2025-07-11 20:37:28 +03:30

using Azure;
using Common.Dtos;
using Common.Dtos.Exper;
using Hushian.Application.Constants;
using Hushian.Application.Services;
using Hushian.Domain.Entites;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.IdentityModel.Tokens.Jwt;
namespace Hushian.WebApi.Controllers.v1
{
[Route("api/v1/[controller]")]
[ApiController]
public class ExperController : ControllerBase
{
private readonly ExperService _experService;
[HttpPost("AddExper")]
[Authorize(Roles = "Company")]
public async Task<ActionResult> AddExper([FromBody] ADD_ExperDto userDto)
{
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
int CompanyID = Convert.ToInt32(strCompanyID);
var response = await _experService.ADDExper(userDto, CompanyID);
return response.Success ? NoContent()
: BadRequest(response.Errors);
}
[HttpGet("GetExpersCompany/{CompanyID}")]
[Authorize]
public async Task<ActionResult> GetExpersCompany(int CompanyID, int PageIndex = 1, int PageSize = 10)
{
var response = await _experService.GetExpersInCompany(CompanyID);
return Ok(response);
}
[HttpPut("EditUserYourself")] //ویرایش کاربران توسط خود
[Authorize(Roles = "Exper")]
public async Task<ActionResult> EditUserYourself([FromBody] Update_ExperDto editUser)
{
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
int ExperID = Convert.ToInt32(strExperID);
var response = await _experService.UpdateExper(editUser,ExperID);
return response ? NoContent()
: BadRequest(new List<string> { "یافت نشد" });
}
[HttpGet("GetCurrentExper")]
[Authorize(Roles = "Exper")]
public async Task<ActionResult> GetCurrentUser()
{
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
int ExperID = Convert.ToInt32(strExperID);
var response = await _experService.GetInfoExper(ExperID);
return response!=null ? Ok(response) : BadRequest(new List<string> { "یافت نشد" });
}
[HttpPut("ExperEditingFromManager/{ExperID}")] //ویرایش کارشناس توسط مدیرش
[Authorize(Roles = "Company")]
public async Task<ActionResult> ExperEditingFromManager(int ExperID,[FromBody] Update_ExperDto editUser)
{
var response = await _experService.UpdateExper(editUser, ExperID);
return response ? NoContent()
: BadRequest(new List<string> { "یافت نشد" });
}
//---
[HttpPut("ChangePasswordYourself")] //تغییر کلمه عبور کاربران توسط خود
[Authorize(Roles = "Exper")]
public async Task<ActionResult> ChangePasswordYourself([FromBody] ChangePasswordDto item)
{
string strExperID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
int ExperID = Convert.ToInt32(strExperID);
var response = await _experService.ChangePasswordExperFromExper(item,ExperID);
return response.Success && response.Value ? NoContent()
: BadRequest(response.Errors);
}
[HttpPut("ChangePasswordFromManager/{ExperID}")] //تغییر کلمه عبور کارشناس توسط مدیرش
[Authorize(Roles = "Company")]
public async Task<ActionResult> ChangePasswordFromManager(int ExperID,[FromBody] ChangePasswordDto item)
{
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
int CompanyID = Convert.ToInt32(strCompanyID);
var response = await _experService.ChangePasswordExperFromCompanyManaget(item, ExperID,CompanyID);
return response.Success && response.Value ? NoContent()
: BadRequest(response.Errors);
}
[HttpPut("ChangeAvailableExperFromManager/{ExperID}")] //تغییر وضعیت در دسترس بودن یا نبودن کارشناس توسط مدیرش
[Authorize(Roles = "Company")]
public async Task<ActionResult> ChangeAvailableExperFromManager(int ExperID, bool Available)
{
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
int CompanyID = Convert.ToInt32(strCompanyID);
var response = await _experService.ChangeAvailableExper(ExperID,CompanyID,Available);
return response ? NoContent()
: BadRequest(new List<string> { "یافت نشد"});
}
[HttpDelete("DeleteExperFromManager/{ExperID}")]
[Authorize(Roles = "Company")]
public async Task<ActionResult> DeleteExperFromManager(int ExperID)
{
string strCompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
int CompanyID = Convert.ToInt32(strCompanyID);
var response = await _experService.DeleteExper(ExperID, CompanyID);
return response ? NoContent()
: BadRequest(new List<string> { "یافت نشد" });
}
}
}