using System; using System.Collections; using _0_Framework.Application; using AccountManagement.Application.Contracts.Account; using AccountManagement.Domain.AccountAgg; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using _0_Framework.Application.Sms; using AccountManagement.Domain.AccountLeftWorkAgg; using AccountManagement.Domain.CameraAccountAgg; using AccountManagement.Domain.RoleAgg; using CompanyManagment.App.Contracts.Workshop; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; using Company.Domain.WorkshopAgg; using System.Security.Claims; using AccountManagement.Domain.PositionAgg; using AccountManagement.Domain.SubAccountAgg; using AccountManagement.Domain.SubAccountPermissionSubtitle1Agg; using AccountManagement.Domain.SubAccountRoleAgg; using Company.Domain.WorkshopSubAccountAgg; //using AccountManagement.Domain.RoleAgg; namespace AccountManagement.Application; public class AccountApplication : IAccountApplication { private readonly IFileUploader _fileUploader; private readonly IPasswordHasher _passwordHasher; private readonly IAccountRepository _accountRepository; private readonly IAuthHelper _authHelper; private readonly IRoleRepository _roleRepository; private readonly ISmsService _smsService; private readonly ICameraAccountRepository _cameraAccountRepository; private readonly IPositionRepository _positionRepository; private readonly IAccountLeftworkRepository _accountLeftworkRepository; private readonly IWorkshopRepository _workshopRepository; private readonly ISubAccountRepository _subAccountRepository; private readonly ISubAccountRoleRepository _subAccountRoleRepository; private readonly IWorkshopSubAccountRepository _workshopSubAccountRepository; private readonly ISubAccountPermissionSubtitle1Repository _accountPermissionSubtitle1Repository; public AccountApplication(IAccountRepository accountRepository, IPasswordHasher passwordHasher, IFileUploader fileUploader, IAuthHelper authHelper, IRoleRepository roleRepository, IWorker worker, ISmsService smsService, ICameraAccountRepository cameraAccountRepository, IPositionRepository positionRepository, IAccountLeftworkRepository accountLeftworkRepository, IWorkshopRepository workshopRepository, ISubAccountRepository subAccountRepository, ISubAccountRoleRepository subAccountRoleRepository, IWorkshopSubAccountRepository workshopSubAccountRepository, ISubAccountPermissionSubtitle1Repository accountPermissionSubtitle1Repository) { _authHelper = authHelper; _roleRepository = roleRepository; _smsService = smsService; _cameraAccountRepository = cameraAccountRepository; _positionRepository = positionRepository; _accountLeftworkRepository = accountLeftworkRepository; _workshopRepository = workshopRepository; _subAccountRepository = subAccountRepository; _subAccountRoleRepository = subAccountRoleRepository; _workshopSubAccountRepository = workshopSubAccountRepository; _accountPermissionSubtitle1Repository = accountPermissionSubtitle1Repository; _fileUploader = fileUploader; _passwordHasher = passwordHasher; _accountRepository = accountRepository; } public OperationResult EditClient(EditClientAccount command) { var opreation = new OperationResult(); var editAccount = _accountRepository.Get(command.Id); if (editAccount == null) return opreation.Failed(ApplicationMessages.RecordNotFound); if (string.IsNullOrWhiteSpace(command.Fullname) || string.IsNullOrWhiteSpace(command.Username) || string.IsNullOrWhiteSpace(command.Mobile) || string.IsNullOrWhiteSpace(command.NationalCode)) return opreation.Failed("پر کردنموارد ستاره دار الزامی است"); if (_accountRepository.Exists(x => (x.Username == command.Username && x.id != command.Id))) return opreation.Failed("نام کاربری تکراری است"); if (_accountRepository.Exists(x => (x.Mobile == command.Mobile && x.id != command.Id))) return opreation.Failed("شماره موبایل تکراری است"); if (_accountRepository.Exists(x => (x.NationalCode == command.NationalCode && !string.IsNullOrWhiteSpace(x.NationalCode) && x.id != command.Id))) return opreation.Failed("کد ملی تکراری است"); if (_accountRepository.Exists(x => (x.Email == command.Email && !string.IsNullOrWhiteSpace(x.Email) && x.id != command.Id))) return opreation.Failed("ایمیل تکراری است"); var path = $"profilePhotos"; var picturePath = _fileUploader.Upload(command.ProfilePhoto, path); editAccount.EditClient(command.Fullname,command.Username,command.Mobile,picturePath,command.Email,command.NationalCode); _accountRepository.SaveChanges(); return opreation.Succcedded(); } public OperationResult ChangePassword(ChangePassword command) { var operation = new OperationResult(); var account = _accountRepository.Get(command.Id); if (account == null) return operation.Failed(ApplicationMessages.RecordNotFound); if (command.Password != command.RePassword) return operation.Failed(ApplicationMessages.PasswordsNotMatch); var password = _passwordHasher.Hash(command.Password); account.ChangePassword(password); _accountRepository.SaveChanges(); return operation.Succcedded(); } public AccountViewModel GetAccountBy(long id) { var account = _accountRepository.Get(id); return new AccountViewModel() { Fullname = account.Fullname, Mobile = account.Mobile }; } public OperationResult Create(CreateAccount command) { var operation = new OperationResult(); if (_accountRepository.Exists(x => x.Username == command.Username || x.Mobile == command.Mobile)) return operation.Failed(ApplicationMessages.DuplicatedRecord); var password = _passwordHasher.Hash(command.Password); var roleName = _roleRepository.GetDetails(command.RoleId); var path = $"profilePhotos"; if (_fileUploader != null) { var picturePath = _fileUploader.Upload(command.ProfilePhoto, path); var account = new Account(command.Fullname, command.Username, password, command.Mobile, command.RoleId, picturePath, roleName.Name,"true","false"); _accountRepository.Create(account); } _accountRepository.SaveChanges(); return operation.Succcedded(); } public OperationResult RegisterClient(RegisterAccount command) { var opreation = new OperationResult(); if (string.IsNullOrWhiteSpace(command.Fullname) || string.IsNullOrWhiteSpace(command.Username) || string.IsNullOrWhiteSpace(command.Mobile) || string.IsNullOrWhiteSpace(command.NationalCode) || string.IsNullOrWhiteSpace(command.Password)) return opreation.Failed("پر کردن تمامی فیلدها الزامی است"); if (_accountRepository.Exists(x => x.Username == command.Username)) return opreation.Failed("نام کاربری تکراری است"); if (_accountRepository.Exists(x => x.Mobile == command.Mobile && x.IsActiveString =="true")) return opreation.Failed("مقادیر وارد شده تکراری است"); //var nationalCodeValidation = command.NationalCode.NationalCodeValid(); //switch (nationalCodeValidation) //{ // case "incorrect": // return opreation.Failed("اعداد وارد شده برای کد ملی صحیح نیست"); // break; // case "invalid": // return opreation.Failed("کد ملی وارد شده معتبر نیست"); // break; // case "lessThan10": // return opreation.Failed("کد ملی وارد شده کمتر از 10 رقم است"); // break; //} var password = _passwordHasher.Hash(command.Password); var register =new Account(command.Fullname,command.Username, password, command.Mobile, command.NationalCode); _accountRepository.Create(register); _accountRepository.SaveChanges(); return opreation.Succcedded(register.id,message: "ثبت نام شما با موفقیت انجام شد"); } public OperationResult Edit(EditAccount command) { var operation = new OperationResult(); var account = _accountRepository.Get(command.Id); if (account == null) return operation.Failed(ApplicationMessages.RecordNotFound); if (_accountRepository.Exists(x => (x.Username == command.Username || x.Mobile == command.Mobile) && x.id != command.Id)) return operation.Failed(ApplicationMessages.DuplicatedRecord); var roleName = _roleRepository.GetDetails(command.RoleId); var path = $"profilePhotos"; var picturePath = _fileUploader.Upload(command.ProfilePhoto, path); account.Edit(command.Fullname, command.Username, command.Mobile, command.RoleId, picturePath, roleName.Name); _accountRepository.SaveChanges(); return operation.Succcedded(); } public EditAccount GetDetails(long id) { return _accountRepository.GetDetails(id); } public OperationResult Login(Login command) { long idAutoriz = 0; var operation = new OperationResult(); if (string.IsNullOrWhiteSpace(command.Password)) return operation.Failed(ApplicationMessages.EmptyPassword); if (string.IsNullOrWhiteSpace(command.Username)) return operation.Failed(ApplicationMessages.EmptyUsername); var account = _accountRepository.GetBy(command.Username); var cameraAccount = _cameraAccountRepository.GetBy(command.Username); SubAccount subAccount = _subAccountRepository.GetBy(command.Username); if (account == null && cameraAccount == null && subAccount == null) return operation.Failed(ApplicationMessages.WrongUserPass); if (account != null) { (bool Verified, bool NeedUpgrade) result = _passwordHasher.Check(account.Password, command.Password); if (!result.Verified) return operation.Failed(ApplicationMessages.WrongUserPass); var permissions = _roleRepository.Get(account.RoleId) .Permissions .Select(x => x.Code) .ToList(); int? positionValue; if (account.PositionId != null) { positionValue = _positionRepository.Get((long)account.PositionId).PositionValue; } else { positionValue = null; } var authViewModel = new AuthViewModel(account.id, account.RoleId, account.Fullname , account.Username, account.Mobile, account.ProfilePhoto, permissions, account.RoleName, account.AdminAreaPermission, account.ClientAriaPermission, positionValue); if (account.ClientAriaPermission == "true" && account.AdminAreaPermission == "false" && account.IsActiveString == "true") { var clientPermissions = _accountPermissionSubtitle1Repository.GetAllPermissionCodes(); authViewModel.Permissions = clientPermissions; var workshopList = _workshopRepository.GetWorkshopsByClientAccountId(account.id).Select(x => new WorkshopClaim { PersonnelCount = x.PersonnelCount, Id = x.Id, Name = x.WorkshopFullName, Slug = _passwordHasher.SlugHasher(x.Id) }).OrderByDescending(x => x.PersonnelCount).ToList(); authViewModel.WorkshopList = workshopList; if (workshopList.Any()) { var workshop = workshopList.First(); authViewModel.WorkshopName = workshop.Name; authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshop.Id); authViewModel.WorkshopId = workshop.Id; } } _authHelper.Signin(authViewModel); if ((account.AdminAreaPermission == "true" && account.ClientAriaPermission == "true" && account.IsActiveString == "true") || (account.AdminAreaPermission == "true" && account.ClientAriaPermission == "false" && account.IsActiveString == "true")) idAutoriz = 1; if (account.ClientAriaPermission == "true" && account.AdminAreaPermission == "false" && account.IsActiveString == "true") idAutoriz = 2; } if (cameraAccount != null) { (bool Verified, bool NeedUpgrade) result = _passwordHasher.Check(cameraAccount.Password, command.Password); if (!result.Verified) return operation.Failed(ApplicationMessages.WrongUserPass); var mobile = string.IsNullOrWhiteSpace(cameraAccount.Mobile) ? " " : cameraAccount.Mobile; var authViewModel = new CameraAuthViewModel(cameraAccount.id, cameraAccount.WorkshopId, cameraAccount.Username, mobile, cameraAccount.WorkshopName, cameraAccount.AccountId,cameraAccount.IsActiveSting); if (cameraAccount.IsActiveSting == "true") { _authHelper.CameraSignIn(authViewModel); idAutoriz = 3; } else { idAutoriz = 0; } } if (subAccount != null) { (bool Verified, bool NeedUpgrade) result = _passwordHasher.Check(subAccount.Password, command.Password); if (!result.Verified) return operation.Failed(ApplicationMessages.WrongUserPass); var role = _subAccountRoleRepository.Get(subAccount.SubAccountRoleId); var permissions = role.RolePermissions.Select(x => x.PermissionCode).ToList(); var authViewModel = new AuthViewModel(subAccount.AccountId, subAccount.SubAccountRoleId, subAccount.FullName , subAccount.Username, subAccount.PhoneNumber, "", permissions, role.Title, "false", "true", 0, subAccount.id); var workshopList = _workshopSubAccountRepository.GetWorkshopsBySubAccountId(subAccount.id); authViewModel.WorkshopList = workshopList.Select(x => new WorkshopClaim() { Slug = _passwordHasher.SlugHasher(x.WorkshopId), Name = x.WorkshopName, PersonnelCount = x.PersonnelCount, Id = x.WorkshopId }).ToList(); if (workshopList.Any()) { var workshop = workshopList.First(); authViewModel.WorkshopName = workshop.WorkshopName; authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshop.WorkshopId); authViewModel.WorkshopId = workshop.WorkshopId; } _authHelper.Signin(authViewModel); idAutoriz = 2; } return operation.Succcedded(idAutoriz); } public OperationResult LoginWithMobile(long id) { var operation = new OperationResult(); var account = _accountRepository.GetById(id); if (account == null) return operation.Failed(ApplicationMessages.WrongUserPass); var permissions = _roleRepository.Get(account.RoleId) .Permissions .Select(x => x.Code) .ToList(); int? positionValue; if (account.PositionId != null) { positionValue = _positionRepository.Get((long)account.PositionId).PositionValue; } else { positionValue = null; } var authViewModel = new AuthViewModel(account.id, account.RoleId, account.Fullname , account.Username, account.Mobile, account.ProfilePhoto, permissions, account.RoleName, account.AdminAreaPermission, account.ClientAriaPermission, positionValue); if (account.ClientAriaPermission == "true" && account.AdminAreaPermission == "false" && account.IsActiveString == "true") { var clientPermissions = _accountPermissionSubtitle1Repository.GetAllPermissionCodes(); authViewModel.Permissions = clientPermissions; var workshopList = _workshopRepository.GetWorkshopsByClientAccountId(account.id).Select(x => new WorkshopClaim { PersonnelCount = x.PersonnelCount, Id = x.Id, Name = x.WorkshopFullName, Slug = _passwordHasher.SlugHasher(x.Id) }).OrderByDescending(x => x.PersonnelCount).ToList(); authViewModel.WorkshopList = workshopList; if (workshopList.Any()) { var workshop = workshopList.First(); authViewModel.WorkshopName = workshop.Name; authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshop.Id); authViewModel.WorkshopId = workshop.Id; } } _authHelper.Signin(authViewModel); long idAutoriz = 0; if (account.AdminAreaPermission == "true" && account.ClientAriaPermission == "true" || account.AdminAreaPermission == "true" && account.ClientAriaPermission == "false") idAutoriz = 1; if (account.ClientAriaPermission == "true" && account.AdminAreaPermission == "false") idAutoriz = 2; return operation.Succcedded(idAutoriz); } public void Logout() { _authHelper.SignOut(); } public List GetAccounts() { return _accountRepository.GetAccounts(); } public List GetClientsAccount() { return _accountRepository.GetClientsAccount(); } public async Task SendVerifyCodeToChangingPass(string phone, long id) { var operation = new OperationResult(); var account = _accountRepository.Get(id); if (account == null) return operation.Failed(ApplicationMessages.RecordNotFound); //var verifyCodeHash = _passwordHasher.Hash(verifyCode); Random generator = new Random(); String r = generator.Next(1, 1000000).ToString("D6"); account.SetVerifyCode(r); _accountRepository.SaveChanges(); _smsService.VerifySend(phone, r); TimeSpan delay = TimeSpan.FromSeconds(130); await Task.Delay(delay); account.SetVerifyCode(""); _accountRepository.SaveChanges(); return operation.Succcedded(); } public EditAccount GetByVerifyCode(string code, string phone) { return _accountRepository.GetByVerifyCode(code, phone); } public EditAccount GetByUserNameAndId(long id, string username) { return _accountRepository.GetByUserNameAndId(id, username); } public async Task SetVerifyCode(string phone, long id) { var operation = new OperationResult(); var account = _accountRepository.Get(id); if (account == null || account.IsActiveString == "false") return operation.Failed(ApplicationMessages.RecordNotFound); //var verifyCodeHash = _passwordHasher.Hash(verifyCode); Random generator = new Random(); String r = generator.Next(1, 1000000).ToString("D6"); account.SetVerifyCode(r); _accountRepository.SaveChanges(); _smsService.LoginSend(phone, r); //TimeSpan delay = TimeSpan.FromSeconds(30); await _accountRepository.RemoveCode(id); return operation.Succcedded(); } public List Search(AccountSearchModel searchModel) { return _accountRepository.Search(searchModel); } public OperationResult Active(long id) { var opration = new OperationResult(); var acc = _accountRepository.Get(id); if (acc == null) return opration.Failed("رکورد مورد نظر یافت نشد"); acc.Active(); _accountRepository.SaveChanges(); return opration.Succcedded(); } public OperationResult DeActive(long id) { var opration = new OperationResult(); var acc = _accountRepository.Get(id); if (acc == null) return opration.Failed("رکورد مورد نظر یافت نشد"); acc.DeActive(); _accountRepository.SaveChanges(); return opration.Succcedded(); } public OperationResult DirectLogin(long id) { var prAcc = _authHelper.CurrentAccountInfo(); var operation = new OperationResult(); var account = _accountRepository.GetById(id); if (account == null) return operation.Failed("این اکانت وجود ندارد"); var permissions = _roleRepository.Get(account.RoleId) .Permissions .Select(x => x.Code) .ToList(); _authHelper.SignOut(); var authViewModel = new AuthViewModel(account.id, account.RoleId, account.Fullname , account.Username, account.Mobile, account.ProfilePhoto, permissions, account.RoleName, "false", "true",null); var workshopList = _workshopRepository.GetWorkshopsByClientAccountId(account.id).Select(x => new WorkshopClaim { PersonnelCount = x.PersonnelCount, Id = x.Id, Name = x.WorkshopFullName, Slug = _passwordHasher.SlugHasher(x.Id) }).OrderByDescending(x => x.PersonnelCount).ToList(); authViewModel.WorkshopList = workshopList; var clientPermissions = _accountPermissionSubtitle1Repository.GetAllPermissionCodes(); authViewModel.Permissions = clientPermissions; if (authViewModel.WorkshopList.Any()) { 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); } public OperationResult DirectCameraLogin(long cameraAccountId) { var prAcc = _authHelper.CurrentAccountInfo(); var operation = new OperationResult(); var cameraAccount = _cameraAccountRepository.GetById(cameraAccountId); if (cameraAccount == null) return operation.Failed("این اکانت وجود ندارد"); _authHelper.SignOut(); var mobile = string.IsNullOrWhiteSpace(cameraAccount.Mobile) ? " " : cameraAccount.Mobile; var authViewModel = new CameraAuthViewModel(cameraAccount.id, cameraAccount.WorkshopId, cameraAccount.Username, mobile, cameraAccount.WorkshopName, cameraAccount.AccountId, cameraAccount.IsActiveSting); if (cameraAccount.IsActiveSting == "true") { _authHelper.CameraSignIn(authViewModel); } else { return operation.Failed("این اکانت غیر فعال شده است"); } return operation.Succcedded(2); } public AccountLeftWorkViewModel WorkshopList(long accountId) { string fullname = this._accountRepository.GetById(accountId).Fullname; List source =_accountLeftworkRepository.WorkshopList(accountId); List userWorkshopIds = source.Select(x => x.WorkshopId).ToList(); List allWorkshops = this._accountLeftworkRepository.GetAllWorkshops(); List accountSelectList = this._accountRepository.GetAdminAccountSelectList(); (string StartWorkFa, string LeftWorkFa) byAccountId = this._accountLeftworkRepository.GetByAccountId(accountId); return new AccountLeftWorkViewModel() { AccountId = accountId, AccountFullName = fullname, StartDateFa = byAccountId.StartWorkFa, LeftDateFa = byAccountId.LeftWorkFa, WorkshopAccountlist = source, WorkshopSelectList = new SelectList(allWorkshops.Where(x => !userWorkshopIds.Contains(x.Id)), "Id", "WorkshopFullName"), AccountSelectList = new SelectList(accountSelectList, "Id", "Fullname") }; } public OperationResult SaveWorkshopAccount( List workshopAccountList, string startDate, string leftDate, long accountId) { return this._accountLeftworkRepository.SaveWorkshopAccount(workshopAccountList, startDate, leftDate, accountId); } public OperationResult CreateNewWorkshopAccount(long currentAccountId, long newAccountId) { return this._accountLeftworkRepository.CopyWorkshopToNewAccount(currentAccountId, newAccountId); } #region Mahan public List AccountsForAssign(long taskId) { return _accountRepository.AccountsForAssign(taskId); } public List GetAccountsByPositionId(long positionId) { if (!_positionRepository.Exists(x => x.id == positionId)) { return new List(); } return _accountRepository.GetAccountsByPositionId(positionId); } public List GetAccountEqualToLowerPositionValue() { return _accountRepository.GetAccountEqualToLowerPositionValue(); } public OperationResult ReLogin() { var prAcc = _authHelper.CurrentAccountInfo(); var operation = new OperationResult(); var account = _accountRepository.GetIncludePositions(prAcc.Id); if (account == null) return operation.Failed("این اکانت وجود ندارد"); var permissions = _roleRepository.Get(account.RoleId) .Permissions .Select(x => x.Code) .ToList(); _authHelper.SignOut(); var authViewModel = new AuthViewModel(account.id, account.RoleId, account.Fullname , account.Username, account.Mobile, account.ProfilePhoto, permissions, account.RoleName, account.AdminAreaPermission, account.ClientAriaPermission, account.Position.PositionValue); _authHelper.Signin(authViewModel); return operation.Succcedded(2); } public async Task> GetAdminSelectList() { return await _accountRepository.GetAdminSelectList(); } #endregion #region Pooya public OperationResult IsPhoneNumberAndPasswordValid(long accountId, string phoneNumber, string password, string rePassword) { OperationResult op = new(); var entity = _accountRepository.Get(accountId); if (entity == null) return op.Failed(ApplicationMessages.RecordNotFound); if (!string.IsNullOrWhiteSpace(rePassword) || !string.IsNullOrWhiteSpace(password)) { if (rePassword != password) return op.Failed("تکرار رمز عبور با رمز عبور مطابقت ندارد"); if (password.Length < 8) return op.Failed("رمز عبور نمی تواند کمتر از 8 کاراکتر باشد"); } if ((string.IsNullOrWhiteSpace(phoneNumber) || entity.Mobile == phoneNumber) && string.IsNullOrWhiteSpace(rePassword)) return op.Failed("چیزی برای تغییر وجود ندارد"); if (!string.IsNullOrWhiteSpace(phoneNumber) && entity.Mobile != phoneNumber) { phoneNumber = phoneNumber.Trim(); if (phoneNumber.Length != 11) return op.Failed("شماره تلفن همراه به درستی وارد نشده است"); if (_accountRepository.Exists(x => x.Mobile == phoneNumber && x.id != accountId) || _subAccountRepository.Exists(x => x.PhoneNumber == phoneNumber) || _cameraAccountRepository.Exists(x => x.Mobile == phoneNumber)) return op.Failed("قبلا یک حساب با این شماره ثبت شده است"); } return op.Succcedded(); } public OperationResult ChangePasswordAndPhoneNumber(AccountChangePasswordAndPhoneNumber command) { OperationResult op = new(); command.PhoneNumber = command.PhoneNumber.Trim(); var entity = _accountRepository.Get(command.AccountId); if (entity == null) return op.Failed(ApplicationMessages.RecordNotFound); var validationResult = IsPhoneNumberAndPasswordValid(command.AccountId, command.PhoneNumber, command.Password, command.RePassword); if (validationResult.IsSuccedded == false) return validationResult; if (!string.IsNullOrWhiteSpace(command.RePassword)) { entity.ChangePassword(_passwordHasher.Hash(command.Password)); } if (!string.IsNullOrWhiteSpace(command.PhoneNumber)) { entity.Edit(entity.Fullname, entity.Username, command.PhoneNumber, entity.RoleId, entity.ProfilePhoto, entity.RoleName); } _accountRepository.SaveChanges(); return op.Succcedded(); } //public UserClaimsResponseDTO GetClaimsForSignIn(Login command) //{ // var operation = new OperationResult(); // var claimsResponse = new UserClaimsResponseDTO() { UserType = UserType.Anonymous }; // if (string.IsNullOrWhiteSpace(command.Password)) // return claimsResponse.Failed(ApplicationMessages.EmptyPassword); // if (string.IsNullOrWhiteSpace(command.Username)) // return claimsResponse.Failed(ApplicationMessages.EmptyUsername); // var account = _accountRepository.GetBy(command.Username); // var cameraAccount = _cameraAccountRepository.GetBy(command.Username); // if (account == null && cameraAccount == null) // return claimsResponse.Failed(ApplicationMessages.WrongUserPass); // if (account != null) // { // (bool Verified, bool NeedUpgrade) result = _passwordHasher.Check(account.Password, command.Password); // if (!result.Verified) // return claimsResponse.Failed(ApplicationMessages.WrongUserPass); // var permissions = _roleRepository.Get(account.RoleId) // .Permissions // .Select(x => x.Code) // .ToList(); // int? positionValue; // if (account.PositionId != null) // { // positionValue = _positionRepository.Get((long)account.PositionId).PositionValue; // } // else // { // positionValue = null; // } // var authViewModel = new AuthViewModel(account.id, account.RoleId, account.Fullname // , account.Username, account.Mobile, account.ProfilePhoto, permissions, account.RoleName, account.AdminAreaPermission, account.ClientAriaPermission, positionValue); // if (account.ClientAriaPermission == "true" && account.AdminAreaPermission == "false" && // account.IsActiveString == "true") // { // var workshopList = _workshopRepository.SearchForClient(new WorkshopSearchModel() { AccountId = account.id }) // .OrderByDescending(x => x.PersonnelCount).ToList().Select(x => new WorkshopClaim() // { // Slug = _passwordHasher.SlugHasher(x.Id), // Name = x.WorkshopFullName, // PersonnelCount = x.PersonnelCount, // Id = x.Id // } // ).ToList(); // authViewModel.WorkshopList = workshopList; // if (workshopList.Any()) // authViewModel.WorkshopSlug = _passwordHasher.SlugHasher(workshopList.First().Id); // ClaimsIdentity claims = _authHelper.GetClaimsIdentityForSignIn(authViewModel); // var encryptedClaim = Tools.SerializeToBson(claims); // return claimsResponse.Succeeded(UserType.Client, encryptedClaim); // } // if ((account.AdminAreaPermission == "true" && account.ClientAriaPermission == "true" && // account.IsActiveString == "true") || (account.AdminAreaPermission == "true" && // account.ClientAriaPermission == "false" && // account.IsActiveString == "true")) // { // ClaimsIdentity claims = _authHelper.GetClaimsIdentityForSignIn(authViewModel); // var encryptedClaim = Tools.SerializeToBson(claims); // return claimsResponse.Succeeded(UserType.Admin, encryptedClaim); // } // } // if (cameraAccount != null) // { // (bool Verified, bool NeedUpgrade) result = _passwordHasher.Check(cameraAccount.Password, command.Password); // if (!result.Verified) // return claimsResponse.Failed(ApplicationMessages.WrongUserPass); // var mobile = string.IsNullOrWhiteSpace(cameraAccount.Mobile) ? " " : cameraAccount.Mobile; // var authViewModel = new CameraAuthViewModel(cameraAccount.id, cameraAccount.WorkshopId, // cameraAccount.Username, mobile, cameraAccount.WorkshopName, cameraAccount.AccountId, cameraAccount.IsActiveSting); // if (cameraAccount.IsActiveSting == "true") // { // var claims = _authHelper.GetCameraClaimsIdentityForSignIn(authViewModel); // var serializedClaims = Tools.SerializeToBson(claims); // return claimsResponse.Succeeded(UserType.Admin, serializedClaims); // } // } // return claimsResponse.Failed(ApplicationMessages.WrongUserPass); //} #endregion public bool CheckExistClientAccount(string userName) { return _accountRepository.CheckExistClientAccount(userName); } public List GetAdminAccountsNew() { return _accountRepository.GetAdminAccountsNew(); } }