79 lines
2.6 KiB
C#
79 lines
2.6 KiB
C#
using _0_Framework.Application;
|
|
using CompanyManagment.App.Contracts.FinancialStatment;
|
|
using CompanyManagment.App.Contracts.Workshop;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using ServiceHost.BaseControllers;
|
|
|
|
namespace ServiceHost.Areas.Client.Controllers;
|
|
|
|
public record GetClientProfileDetails(long Id, string Fullname, string Mobile, List<int> Permissions, List<WorkshopClaim> Workshops, string WorkshopSlug, double DebtAmount);
|
|
|
|
public class LoginController : ClientBaseController
|
|
{
|
|
private readonly IAuthHelper _authHelper;
|
|
private readonly IFinancialStatmentApplication _financialStatmentApplication;
|
|
|
|
public LoginController(IAuthHelper authHelper, IFinancialStatmentApplication financialStatmentApplication)
|
|
{
|
|
_authHelper = authHelper;
|
|
_financialStatmentApplication = financialStatmentApplication;
|
|
}
|
|
/// <summary>
|
|
/// جزئیات پروفایل کاربر کلاینت را برمی گرداند
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("Profile")]
|
|
public async Task<ActionResult<GetClientProfileDetails>> GetProfile()
|
|
{
|
|
if (!_authHelper.IsAuthenticated())
|
|
return Unauthorized();
|
|
var data = _authHelper.CurrentAccountInfo();
|
|
|
|
if (data == null)
|
|
return Unauthorized();
|
|
|
|
if (_authHelper.GetUserTypeWithId().userType is not UserType.Client and not UserType.SubAccount)
|
|
return Unauthorized();
|
|
|
|
var debtAmount = await _financialStatmentApplication.GetClientDebtAmount(data.Id);
|
|
var details = new GetClientProfileDetails(
|
|
data.Id,
|
|
data.Fullname,
|
|
data.Mobile,
|
|
data.Permissions,
|
|
data.WorkshopList,
|
|
data.WorkshopSlug,
|
|
debtAmount
|
|
);
|
|
return details;
|
|
}
|
|
|
|
/// <summary>
|
|
/// انتخاب کارگاه
|
|
/// </summary>
|
|
/// <param name="slug"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("select-workshop")]
|
|
public IActionResult SelectWorkshop(string slug)
|
|
{
|
|
var selectedWorkshop = _authHelper.CurrentAccountInfo().WorkshopList.FirstOrDefault(x => x.Slug == slug);
|
|
if (selectedWorkshop != null)
|
|
{
|
|
_authHelper.UpdateWorkshopSlugClaim(selectedWorkshop.Slug, selectedWorkshop.Name);
|
|
|
|
return new JsonResult(new
|
|
{
|
|
isSuccedded = true,
|
|
message = "کارگاه مورد نظر شما انتخاب شد"
|
|
});
|
|
}
|
|
else
|
|
{
|
|
return new JsonResult(new
|
|
{
|
|
isSuccedded = false,
|
|
message = "کارگاه مورد نظر شما یافت نشد"
|
|
});
|
|
}
|
|
}
|
|
} |