public void RemoveAccount(long accountId) { var account = new GetAccountByIdQueryHandler(new DataBaseContext()).Handle(new GetAccountByIdQuery { UserId = accountId, SearchDeleted = true }); new DeleteUserCommandHandler(new DataBaseContext()).Handle(new DeleteUserCommand { AccountId = accountId }); var jobModel = new RemoveAccountJobsModel() { AccountId = account.Id, Login = account.Login }; _jobService.RemoveAccountJobs(jobModel); _backgroundJobService.RemoveAllBackgroundJobs(jobModel); }
public bool RefreshCookies(AccountViewModel account, bool forSpy, IBackgroundJobService backgroundJob) { if (account.Proxy != null) { var proxyIsFailed = new CheckProxyEngine().Execute(new CheckProxyModel { Driver = _seleniumManager.RegisterNewDriver(account) }); if (proxyIsFailed) { if (forSpy) { new UpdateFailSpyAccountInformationCommandHandler(new DataBaseContext()).Handle( new UpdateFailSpyAccountInformationCommand { AccountId = account.Id, ProxyDataIsFailed = true }); } else { new UpdateFailAccountInformationCommandHandler(new DataBaseContext()).Handle( new UpdateFailAccountInformationCommand { AccountId = account.Id, ProxyDataIsFailed = true }); } backgroundJob.RemoveAllBackgroundJobs(new RemoveAccountJobsModel { AccountId = account.Id, IsForSpy = forSpy, Login = account.Login }); return(false); } } var cookieResponse = new GetNewCookiesEngine().Execute(new GetNewCookiesModel { Login = account.Login, Password = account.Password, Driver = _seleniumManager.RegisterNewDriver(account), Cookie = account.Cookie }); if (cookieResponse == null || cookieResponse.AuthorizationError) { if (forSpy) { new UpdateFailSpyAccountInformationCommandHandler(new DataBaseContext()).Handle( new UpdateFailSpyAccountInformationCommand { AccountId = account.Id, AuthorizationDataIsFailed = true }); } else { new UpdateFailAccountInformationCommandHandler(new DataBaseContext()).Handle( new UpdateFailAccountInformationCommand { AccountId = account.Id, AuthorizationDataIsFailed = true }); } backgroundJob.RemoveAllBackgroundJobs(new RemoveAccountJobsModel { AccountId = account.Id, IsForSpy = forSpy, Login = account.Login }); return(false); } if (cookieResponse.ConfirmationError) { if (forSpy) { new UpdateFailSpyAccountInformationCommandHandler(new DataBaseContext()).Handle( new UpdateFailSpyAccountInformationCommand { AccountId = account.Id, ConformationIsFailed = true }); } else { new UpdateFailAccountInformationCommandHandler(new DataBaseContext()).Handle( new UpdateFailAccountInformationCommand { AccountId = account.Id, ConformationIsFailed = true }); } backgroundJob.RemoveAllBackgroundJobs(new RemoveAccountJobsModel { AccountId = account.Id, IsForSpy = forSpy, Login = account.Login }); return(false); } var newCookie = cookieResponse.CookiesString; if (newCookie == null) { return(false); } if (forSpy) { new UpdateCookiesForSpyHandler(new DataBaseContext()).Handle(new UpdateCookiesForSpyCommand { AccountId = account.Id, NewCookieString = newCookie }); } else { new UpdateCookiesHandler(new DataBaseContext()).Handle(new UpdateCookiesCommand() { AccountId = account.Id, NewCookieString = newCookie }); } new UpdateFailSpyAccountInformationCommandHandler(new DataBaseContext()).Handle( new UpdateFailSpyAccountInformationCommand { AccountId = account.Id, ProxyDataIsFailed = false, AuthorizationDataIsFailed = false, ConformationIsFailed = false }); return(true); }