diff --git a/0_Framework/Application/AuthHelper.cs b/0_Framework/Application/AuthHelper.cs index 50e221b2..ef510830 100644 --- a/0_Framework/Application/AuthHelper.cs +++ b/0_Framework/Application/AuthHelper.cs @@ -42,6 +42,7 @@ public class AuthHelper : IAuthHelper result.WorkshopName = claims.FirstOrDefault(x => x is { Type: "WorkshopName" })?.Value; result.Permissions = Tools.DeserializeFromBsonList(claims.FirstOrDefault(x => x is { Type: "permissions" })?.Value); result.RoleName = claims.FirstOrDefault(x => x is { Type: "RoleName" })?.Value; + result.WorkshopId = long.Parse(claims.FirstOrDefault(x => x.Type == "WorkshopId")?.Value??"0"); return result; } @@ -76,7 +77,7 @@ public class AuthHelper : IAuthHelper #region Vafa - public void UpdateWorkshopSlugClaim(string newWorkshopSlug, string newWorkshopName) + public void UpdateWorkshopSlugClaim(string newWorkshopSlug, string newWorkshopName,long newWorkshopId) { var user = _contextAccessor.HttpContext.User; @@ -85,6 +86,7 @@ public class AuthHelper : IAuthHelper var claimsIdentity = (ClaimsIdentity)user.Identity; var existingClaimSlug = claimsIdentity.FindFirst("WorkshopSlug"); var existingClaimName = claimsIdentity.FindFirst("WorkshopName"); + var existingWorkshopId = claimsIdentity.FindFirst("WorkshopId"); if (existingClaimSlug != null) { @@ -96,9 +98,14 @@ public class AuthHelper : IAuthHelper claimsIdentity.RemoveClaim(existingClaimName); } + if (existingWorkshopId != null) + { + claimsIdentity.RemoveClaim(existingWorkshopId); + } claimsIdentity.AddClaim(new Claim("WorkshopSlug", newWorkshopSlug)); claimsIdentity.AddClaim(new Claim("WorkshopName", newWorkshopName)); + claimsIdentity.AddClaim(new Claim("WorkshopId",newWorkshopId.ToString())); var authProperties = new AuthenticationProperties @@ -128,8 +135,16 @@ public class AuthHelper : IAuthHelper return ""; } + + #endregion + public long GetWorkshopId() + { + return long.Parse(_contextAccessor.HttpContext?.User.Claims.FirstOrDefault(x => x.Type == "WorkshopId")?.Value ?? "0"); + + + } public string CurrentAccountRole() { @@ -182,6 +197,7 @@ public class AuthHelper : IAuthHelper //mahanChanges new("workshopList",workshopBson), new("WorkshopSlug",slug), + new("WorkshopId", account.WorkshopId.ToString()), new("WorkshopName",account.WorkshopName??"") }; diff --git a/0_Framework/Application/AuthViewModel.cs b/0_Framework/Application/AuthViewModel.cs index dba5d198..d419bd67 100644 --- a/0_Framework/Application/AuthViewModel.cs +++ b/0_Framework/Application/AuthViewModel.cs @@ -20,6 +20,7 @@ public class AuthViewModel public int? PositionValue { get; set; } public string WorkshopSlug { get; set; } + public long WorkshopId { get; set; } public string WorkshopName { get; set; } public List WorkshopList { get; set; } diff --git a/0_Framework/Application/IAuthHelper.cs b/0_Framework/Application/IAuthHelper.cs index 281755aa..ab9cf572 100644 --- a/0_Framework/Application/IAuthHelper.cs +++ b/0_Framework/Application/IAuthHelper.cs @@ -17,11 +17,12 @@ public interface IAuthHelper #region Vafa - void UpdateWorkshopSlugClaim(string workshopSlug, string workshopName); + void UpdateWorkshopSlugClaim(string workshopSlug, string workshopName, long workshopId); #endregion long CurrentSubAccountId(); string GetWorkshopSlug(); string GetWorkshopName(); + long GetWorkshopId(); (long Id, UserType userType, long roleId) GetUserTypeWithId(); } \ No newline at end of file diff --git a/AccountManagement.Application/AccountApplication.cs b/AccountManagement.Application/AccountApplication.cs index 7c32b7db..ff4e5a25 100644 --- a/AccountManagement.Application/AccountApplication.cs +++ b/AccountManagement.Application/AccountApplication.cs @@ -259,7 +259,8 @@ public class AccountApplication : IAccountApplication var workshop = workshopList.First(); authViewModel.WorkshopName = workshop.Name; authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshop.Id); - } + authViewModel.WorkshopId = workshop.Id; + } } _authHelper.Signin(authViewModel); @@ -317,6 +318,7 @@ public class AccountApplication : IAccountApplication var workshop = workshopList.First(); authViewModel.WorkshopName = workshop.WorkshopName; authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshop.WorkshopId); + authViewModel.WorkshopId = workshop.WorkshopId; } _authHelper.Signin(authViewModel); idAutoriz = 2; @@ -368,6 +370,7 @@ public class AccountApplication : IAccountApplication var workshop = workshopList.First(); authViewModel.WorkshopName = workshop.Name; authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshop.Id); + authViewModel.WorkshopId = workshop.Id; } } @@ -515,6 +518,7 @@ public class AccountApplication : IAccountApplication var workshop = authViewModel.WorkshopList.First(); authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshop.Id); authViewModel.WorkshopName = workshop.Name; + authViewModel.WorkshopId = workshop.Id; } _authHelper.Signin(authViewModel); return operation.Succcedded(2); diff --git a/ServiceHost/Areas/Client/Controllers/LoginController.cs b/ServiceHost/Areas/Client/Controllers/LoginController.cs index c3e7cd9f..c84755fa 100644 --- a/ServiceHost/Areas/Client/Controllers/LoginController.cs +++ b/ServiceHost/Areas/Client/Controllers/LoginController.cs @@ -1,22 +1,27 @@ using _0_Framework.Application; using CompanyManagment.App.Contracts.FinancialStatment; +using CompanyManagment.App.Contracts.RollCallService; 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 Permissions, List Workshops, string WorkshopSlug, double DebtAmount,UserType UserType); +public record GetClientProfileDetails(long Id, string Fullname, string Mobile, + List Permissions, List Workshops, + string WorkshopSlug, double DebtAmount,UserType UserType,bool HasRollCallService,bool HasCustomizeCheckout); public class LoginController : ClientBaseController { private readonly IAuthHelper _authHelper; private readonly IFinancialStatmentApplication _financialStatmentApplication; + private readonly IRollCallServiceApplication _rollCallServiceApplication; - public LoginController(IAuthHelper authHelper, IFinancialStatmentApplication financialStatmentApplication) + public LoginController(IAuthHelper authHelper, IFinancialStatmentApplication financialStatmentApplication, IRollCallServiceApplication rollCallServiceApplication) { _authHelper = authHelper; _financialStatmentApplication = financialStatmentApplication; + _rollCallServiceApplication = rollCallServiceApplication; } /// /// جزئیات پروفایل کاربر کلاینت را برمی گرداند @@ -37,6 +42,12 @@ public class LoginController : ClientBaseController return Unauthorized(); var debtAmount = await _financialStatmentApplication.GetClientDebtAmount(data.Id); + + var rollCallService = _rollCallServiceApplication.GetActiveServiceByWorkshopId(_authHelper.GetWorkshopId()); + var hasRollCallService = rollCallService != null; + var hasCustomizeCheckout = rollCallService?.HasCustomizeCheckoutService=="true"; + + var details = new GetClientProfileDetails( data.Id, data.Fullname, @@ -45,7 +56,9 @@ public class LoginController : ClientBaseController data.WorkshopList, data.WorkshopSlug, debtAmount, - userTypeWithId.userType + userTypeWithId.userType, + hasRollCallService, + hasCustomizeCheckout ); return details; } @@ -61,7 +74,7 @@ public class LoginController : ClientBaseController var selectedWorkshop = _authHelper.CurrentAccountInfo().WorkshopList.FirstOrDefault(x => x.Slug == slug); if (selectedWorkshop != null) { - _authHelper.UpdateWorkshopSlugClaim(selectedWorkshop.Slug, selectedWorkshop.Name); + _authHelper.UpdateWorkshopSlugClaim(selectedWorkshop.Slug, selectedWorkshop.Name, selectedWorkshop.Id); return new JsonResult(new { diff --git a/ServiceHost/Areas/Client/Pages/Company/RollCall/Index.cshtml.cs b/ServiceHost/Areas/Client/Pages/Company/RollCall/Index.cshtml.cs index 2e067189..633f9518 100644 --- a/ServiceHost/Areas/Client/Pages/Company/RollCall/Index.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Company/RollCall/Index.cshtml.cs @@ -108,12 +108,14 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall var hasRollCallService = activeService != null; bool hasCameraAccount; + bool hasCustomizeCheckout = false; if (hasRollCallService) { var accountId = _authHelper.CurrentAccountId(); var cameraAccountExists = _cameraAccountApplication.HasCameraAccount(workshopId, accountId); hasCameraAccount = cameraAccountExists && hasPreviousService; + hasCustomizeCheckout = activeService.HasCustomizeCheckoutService=="true"; } else { @@ -124,7 +126,8 @@ namespace ServiceHost.Areas.Client.Pages.Company.RollCall { hasRollCallWorkshopSetting, hasCameraAccount, - hasRollCallService + hasRollCallService, + hasCustomizeCheckout, }); } diff --git a/ServiceHost/Areas/Client/Pages/Index.cshtml.cs b/ServiceHost/Areas/Client/Pages/Index.cshtml.cs index e0ed3c12..e61508cc 100644 --- a/ServiceHost/Areas/Client/Pages/Index.cshtml.cs +++ b/ServiceHost/Areas/Client/Pages/Index.cshtml.cs @@ -230,7 +230,7 @@ namespace ServiceHost.Areas.Client.Pages if (selectedWorkshop != null) { - _authHelper.UpdateWorkshopSlugClaim(selectedWorkshop.Slug,selectedWorkshop.WorkshopFullName); + _authHelper.UpdateWorkshopSlugClaim(selectedWorkshop.Slug,selectedWorkshop.WorkshopFullName,selectedWorkshop.Id); } return new JsonResult(new @@ -248,7 +248,7 @@ namespace ServiceHost.Areas.Client.Pages var workshop = _workshopApplication.SearchForClient(searchModel).FirstOrDefault(x => x.Id == workshopId); if (workshop != null) { - _authHelper.UpdateWorkshopSlugClaim(workshop.Slug,workshop.WorkshopFullName); + _authHelper.UpdateWorkshopSlugClaim(workshop.Slug,workshop.WorkshopFullName, workshop.Id); } return new JsonResult(new diff --git a/ServiceHost/Areas/Client/Pages/Shared/_ClientLayout.cshtml b/ServiceHost/Areas/Client/Pages/Shared/_ClientLayout.cshtml index 26b73405..11a70e26 100644 --- a/ServiceHost/Areas/Client/Pages/Shared/_ClientLayout.cshtml +++ b/ServiceHost/Areas/Client/Pages/Shared/_ClientLayout.cshtml @@ -141,6 +141,17 @@ } else { $('#RollCallSubMenu').addClass('disable'); } + const customizeCheckoutIds =[ + "customize-checkout-grouping", + "customize-checkout-temporary", + "customize-checkout-unofficial", + ]; + + customizeCheckoutIds.forEach(id => { + $(`#${id}`).toggleClass('disable',!response.hasCustomizeCheckout); + }) + + }); } diff --git a/ServiceHost/Areas/Client/Pages/Shared/_Menu.cshtml b/ServiceHost/Areas/Client/Pages/Shared/_Menu.cshtml index decb47b4..3887dd82 100644 --- a/ServiceHost/Areas/Client/Pages/Shared/_Menu.cshtml +++ b/ServiceHost/Areas/Client/Pages/Shared/_Menu.cshtml @@ -160,9 +160,9 @@