namespace FrontOffice.Main.Utilities; /// /// هر action ای که نیاز به لاگین دارد را از طریق این سرویس اجرا کنید. /// اگر کاربر لاگین نباشد، مودال ورود نشان داده می‌شود. /// پس از ورود موفق، action به صورت خودکار اجرا می‌شود. /// public class GuestActionGate { private readonly AuthService _authService; private readonly AuthDialogService _authDialogService; public GuestActionGate(AuthService authService, AuthDialogService authDialogService) { _authService = authService; _authDialogService = authDialogService; } /// /// اگر کاربر لاگین باشد action را اجرا می‌کند. /// در غیر این صورت مودال لاگین را باز کرده و پس از ورود موفق، action را اجرا می‌کند. /// /// true اگر action اجرا شد، false اگر کاربر لاگین نکرد. public async Task RunAsync(Func action) { if (await _authService.IsAuthenticatedAsync()) { await action(); return true; } await _authDialogService.ShowAuthDialogAsync(); if (await _authService.IsAuthenticatedAsync()) { await action(); return true; } return false; } }