Exemplo n.º 1
0
        public SpyAccountModel GetSpyAccountById(long?spyAccountId)
        {
            var spyAccount = new GetSpyAccountByIdQueryHandler(new DataBaseContext()).Handle(new GetSpyAccountByIdQuery
            {
                UserId = spyAccountId
            });

            if (spyAccount == null)
            {
                return(null);
            }

            return(spyAccount);
        }
Exemplo n.º 2
0
        public void RemoveSpyAccount(long spyAccountId)
        {
            var spyAccount = new GetSpyAccountByIdQueryHandler(new DataBaseContext()).Handle(new GetSpyAccountByIdQuery
            {
                UserId = spyAccountId
            });

            new DeleteSpyAccounCommandHandler(new DataBaseContext()).Handle(new DeleteSpyAccounCommand
            {
                AccountId = spyAccountId
            });

            var model = new RemoveAccountJobsModel
            {
                Login     = spyAccount.Login,
                AccountId = null
            };

            _jobService.RemoveAccountJobs(model);
        }
Exemplo n.º 3
0
        public CookiesViewModel GetSpyAccountCookies(long accountId)
        {
            var spyAccount = new GetSpyAccountByIdQueryHandler(new DataBaseContext()).Handle(new GetSpyAccountByIdQuery
            {
                UserId = accountId
            });

            if (spyAccount.Cookie == null)
            {
                return(new CookiesViewModel
                {
                    AccountId = accountId,
                    Value = "Cookie is not created"
                });
            }
            return(new CookiesViewModel
            {
                AccountId = accountId,
                Value = spyAccount.Cookie.CookieString,
                CreateDateTime = spyAccount.Cookie.CreateDateTime
            });
        }
Exemplo n.º 4
0
        public void AddOrUpdateSpyAccount(SpyAccountViewModel model, IBackgroundJobService backgroundJobService)
        {
            var accountId = new AddOrUpdateSpyAccountCommandHandler(new DataBaseContext()).Handle(new AddOrUpdateSpyAccountCommand
            {
                Id            = model.Id,
                Name          = model.Name,
                PageUrl       = model.PageUrl,
                FacebookId    = model.FacebookId,
                Password      = model.Password,
                Login         = model.Login,
                Proxy         = model.Proxy,
                ProxyLogin    = model.ProxyLogin,
                ProxyPassword = model.ProxyPassword
            });

            new CookieService().RefreshCookies(new AccountViewModel
            {
                Id            = accountId,
                Login         = model.Login,
                Password      = model.Password,
                Proxy         = model.Proxy,
                ProxyLogin    = model.ProxyLogin,
                ProxyPassword = model.ProxyPassword,
            },
                                               true,
                                               backgroundJobService);

            var account = new GetSpyAccountByIdQueryHandler(new DataBaseContext()).Handle(new GetSpyAccountByIdQuery
            {
                UserId = accountId
            });

            if (model.PageUrl == null || model.FacebookId == 0)
            {
                var accountFacebookId = _proxyManager.GetAccountFacebookId(account.Cookie.CookieString);
                var homePageUrl       = _accountManager.CreateHomePageUrl(accountFacebookId);

                new AddOrUpdateSpyAccountCommandHandler(new DataBaseContext()).Handle(new AddOrUpdateSpyAccountCommand
                {
                    Id            = account.Id,
                    Name          = model.Name,
                    PageUrl       = homePageUrl,
                    FacebookId    = accountFacebookId,
                    Password      = model.Password,
                    Login         = model.Login,
                    Proxy         = model.Proxy,
                    ProxyLogin    = model.ProxyLogin,
                    ProxyPassword = model.ProxyPassword
                });

                account = new GetSpyAccountByIdQueryHandler(new DataBaseContext()).Handle(new GetSpyAccountByIdQuery
                {
                    UserId = accountId
                });
            }

            var jobModel = new AddOrUpdateAccountModel
            {
                Account = new AccountViewModel
                {
                    Id            = accountId,
                    Name          = model.Name,
                    PageUrl       = model.PageUrl,
                    FacebookId    = account.FacebookId,
                    Password      = model.Password,
                    Login         = model.Login,
                    Proxy         = model.Proxy,
                    ProxyLogin    = model.ProxyLogin,
                    ProxyPassword = model.ProxyPassword,
                    Cookie        = account.Cookie.CookieString
                }
            };

            _jobService.AddOrUpdateSpyAccountJobs(jobModel);
        }