55 lines
2.1 KiB
C#
55 lines
2.1 KiB
C#
using Common.Dtos;
|
|
using Common.Dtos.Company;
|
|
using Hushian.Application.Constants;
|
|
using Hushian.Application.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Hushian.WebApi.Controllers.v1
|
|
{
|
|
[Route("api/v1/[controller]")]
|
|
[ApiController]
|
|
public class CompanyController : ControllerBase
|
|
{
|
|
private readonly CompanyService _companyService;
|
|
|
|
public CompanyController(CompanyService companyService)
|
|
{
|
|
_companyService = companyService;
|
|
}
|
|
|
|
[HttpPost("NewCompany")]
|
|
public async Task<ActionResult<int>> NewCompany([FromBody] RegisterCompanyDto request)
|
|
{
|
|
var response = await _companyService.RegisterCompany(request);
|
|
return response.Success ? Ok(response.Value)
|
|
: BadRequest(response.Errors);
|
|
}
|
|
[HttpGet("GetCompany/{CompanyID}")]
|
|
public async Task<ActionResult<ReadANDUpdate_CompanyDto>> GetCompany(int CompanyID)
|
|
{
|
|
var response = await _companyService.GETCompanyinformation(CompanyID);
|
|
return response!=null ? Ok(response): NotFound();
|
|
}
|
|
[HttpPut("UpdateCompany")]
|
|
[Authorize(Roles = "Company")]
|
|
public async Task<ActionResult> UpdateCompany([FromBody] ReadANDUpdate_CompanyDto model)
|
|
{
|
|
string CompanyID = User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First();
|
|
var response = await _companyService.EditCompany(model,Convert.ToInt32(CompanyID));
|
|
return response.Success && response.Value ? NoContent()
|
|
: BadRequest(response.Errors);
|
|
}
|
|
[HttpPut("ChangePasswordCompany")]
|
|
[Authorize(Roles = "Company")]
|
|
public async Task<ActionResult> ChangePasswordCompany([FromBody] ChangePasswordDto item)
|
|
{
|
|
var response = await _companyService.ChangePasswordCompany(item, Convert.ToInt32(User.Claims.Where(w => w.Type == CustomClaimTypes.Uid).Select(s => s.Value).First()));
|
|
return response.Success && response.Value ? NoContent()
|
|
: BadRequest(response.Errors);
|
|
}
|
|
|
|
|
|
}
|
|
}
|