258 lines
6.7 KiB
C#
258 lines
6.7 KiB
C#
using _0_Framework.Application;
|
|
using _0_Framework.Application.Sms;
|
|
using AccountManagement.Application.Contracts.Account;
|
|
using AccountManagement.Application.Contracts.Role;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using ServiceHost.Hubs;
|
|
|
|
namespace ServiceHost.Areas.Admin.Pages.Accounts.Account;
|
|
|
|
[Authorize]
|
|
public class IndexModel : PageModel
|
|
{
|
|
private readonly IAccountApplication _accountApplication;
|
|
private readonly IAuthHelper _authHelper;
|
|
private readonly IHubContext<SendAccountMessage> _hubContext;
|
|
private readonly IRoleApplication _roleApplication;
|
|
private readonly ISmsService _smsService;
|
|
public List<AccountViewModel> AdminAccounts;
|
|
public List<AccountViewModel> ClientAccounts;
|
|
public long CurrntAccountId;
|
|
public SelectList Roles;
|
|
public List<RoleViewModel> Roless;
|
|
|
|
public AccountSearchModel SearchModel;
|
|
|
|
public IndexModel(IAccountApplication accountApplication, IRoleApplication roleApplication, IAuthHelper authHelper,
|
|
ISmsService smsService, IHubContext<SendAccountMessage> hubContext)
|
|
{
|
|
_accountApplication = accountApplication;
|
|
_roleApplication = roleApplication;
|
|
|
|
_authHelper = authHelper;
|
|
_smsService = smsService;
|
|
_hubContext = hubContext;
|
|
}
|
|
|
|
|
|
public void OnGet(AccountSearchModel searchModel)
|
|
{
|
|
Roles = new SelectList(_roleApplication.List(), "Id", "Name");
|
|
AdminAccounts = _accountApplication.Search(searchModel).Where(x => x.RoleId != 15).ToList();
|
|
ClientAccounts = _accountApplication.Search(searchModel).Where(x => x.RoleId == 15).ToList();
|
|
Roless = _roleApplication.List();
|
|
|
|
CurrntAccountId = _authHelper.CurrentAccountId();
|
|
}
|
|
|
|
|
|
public IActionResult OnGetCreate()
|
|
{
|
|
var command = new CreateAccount
|
|
{
|
|
Roles = _roleApplication.List()
|
|
};
|
|
return Partial("./Create", command);
|
|
}
|
|
|
|
|
|
public IActionResult OnPostCreate(CreateAccount command)
|
|
{
|
|
var result = _accountApplication.Create(command);
|
|
return new JsonResult(result);
|
|
}
|
|
|
|
public IActionResult OnGetCreateRole()
|
|
{
|
|
var command = new CreateRole();
|
|
|
|
return Partial("./CreateRole", command);
|
|
}
|
|
|
|
public IActionResult OnPostCreateRole(CreateRole command)
|
|
{
|
|
var result = _roleApplication.Create(command);
|
|
return new JsonResult(result);
|
|
}
|
|
|
|
|
|
public IActionResult OnGetEdit(long id)
|
|
{
|
|
var account = _accountApplication.GetDetails(id);
|
|
account.Roles = _roleApplication.List();
|
|
return Partial("Edit", account);
|
|
}
|
|
|
|
|
|
public JsonResult OnPostEdit(EditAccount command)
|
|
{
|
|
var result = _accountApplication.Edit(command);
|
|
return new JsonResult(result);
|
|
}
|
|
|
|
public IActionResult OnGetEditRole(long id)
|
|
{
|
|
var role = _roleApplication.GetDetails(id);
|
|
var rol = new List<int>();
|
|
foreach (var item in role.MappedPermissions) rol.Add(item.Code);
|
|
|
|
role.Permissions = rol;
|
|
|
|
return Partial("EditRole", role);
|
|
}
|
|
|
|
public JsonResult OnPostEditRole(EditRole command)
|
|
{
|
|
var result = _roleApplication.Edit(command);
|
|
return new JsonResult(result);
|
|
}
|
|
|
|
public IActionResult OnGetChangePassword(long id)
|
|
{
|
|
var command = new ChangePassword { Id = id };
|
|
return Partial("ChangePassword", command);
|
|
}
|
|
|
|
public IActionResult OnGetSendAccountSms()
|
|
{
|
|
var currntAcc = _authHelper.CurrentAccountId();
|
|
|
|
|
|
var fix = _accountApplication.GetClientsAccount();
|
|
var falseIds = new List<long> { 182, 191, 192, 219, 229, 254, 268, 276, 289 };
|
|
var accountsList = fix.Where(x => falseIds.Contains(x.Id)).ToList();
|
|
double maxNumber = accountsList.Count;
|
|
var n = 1;
|
|
foreach (var account in accountsList)
|
|
{
|
|
var sendResult = _smsService.SendAccountsInfo(account.Mobile, account.Fullname, account.Username);
|
|
if (sendResult)
|
|
Console.WriteLine(sendResult + " - id : " + account.Id + " - " + account.Username);
|
|
else
|
|
Console.WriteLine(sendResult + " - id : " + account.Id + " - " + account.Username);
|
|
|
|
var percent = n / maxNumber * 100;
|
|
_hubContext.Clients.Group(SendAccountMessage.GetGroupName(currntAcc))
|
|
.SendAsync("showStatus", (int)percent);
|
|
|
|
n += 1;
|
|
Thread.Sleep(3000);
|
|
}
|
|
|
|
if (n >= accountsList.Count)
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = true,
|
|
contractCount = n
|
|
});
|
|
|
|
var failds = accountsList.Count - n;
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = false,
|
|
contractCount = failds
|
|
});
|
|
}
|
|
|
|
public JsonResult OnPostChangePassword(ChangePassword command)
|
|
{
|
|
var result = _accountApplication.ChangePassword(command);
|
|
return new JsonResult(result);
|
|
}
|
|
|
|
public IActionResult OnGetDeActive(long id)
|
|
{
|
|
var result = _accountApplication.DeActive(id);
|
|
|
|
if (result.IsSuccedded)
|
|
return new JsonResult(new
|
|
{
|
|
isSuccedded = true
|
|
});
|
|
return new JsonResult(new
|
|
{
|
|
isSuccedded = false
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetActive(long id)
|
|
{
|
|
var result = _accountApplication.Active(id);
|
|
if (result.IsSuccedded)
|
|
return new JsonResult(new
|
|
{
|
|
isSuccedded = true
|
|
});
|
|
return new JsonResult(new
|
|
{
|
|
isSuccedded = false
|
|
});
|
|
}
|
|
|
|
|
|
public IActionResult OnPostLoginToClient(long id)
|
|
{
|
|
var result = _accountApplication.DirectLogin(id);
|
|
if (result.IsSuccedded)
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = true
|
|
});
|
|
|
|
return new JsonResult(new
|
|
{
|
|
isSuccess = false
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetAccountWorkshop(long id)
|
|
{
|
|
var res = _accountApplication.WorkshopList(id);
|
|
|
|
|
|
|
|
return Partial("AccountLeftWork", res);
|
|
}
|
|
|
|
public IActionResult OnPostCreateAccountLeftWork(
|
|
List<WorkshopAccountlistViewModel> workshopAccountlistViewModel,
|
|
string startDate,
|
|
string leftDate,
|
|
long accountId)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(startDate))
|
|
return (IActionResult)new JsonResult((object)new
|
|
{
|
|
isSuccess = false,
|
|
mess = "تاریخ شروع بکار خالی است"
|
|
});
|
|
OperationResult operationResult = _accountApplication.SaveWorkshopAccount(workshopAccountlistViewModel, startDate, leftDate, accountId);
|
|
return operationResult.IsSuccedded ? (IActionResult)new JsonResult((object)new
|
|
{
|
|
isSuccess = true,
|
|
mess = operationResult.Message
|
|
}) : (IActionResult)new JsonResult((object)new
|
|
{
|
|
isSuccess = false,
|
|
mess = operationResult.Message
|
|
});
|
|
}
|
|
|
|
public IActionResult OnGetCopyWorkshopToNewAccount(long currentAccountId, long newAccountId)
|
|
{
|
|
OperationResult newWorkshopAccount = this._accountApplication.CreateNewWorkshopAccount(currentAccountId, newAccountId);
|
|
return newWorkshopAccount.IsSuccedded ? (IActionResult)new JsonResult((object)new
|
|
{
|
|
isSuccess = true
|
|
}) : (IActionResult)new JsonResult((object)new
|
|
{
|
|
isSuccess = false,
|
|
message = newWorkshopAccount.Message
|
|
});
|
|
}
|
|
}
|