Пример #1
0
        public ActionResult Measure(SitePostModel site)
        {
            if (site.Url != null)
            {
                var siteModel = _mapper.Map <SiteModel>(site);
                var measures  = new List <TestingPageModel>();

                var checkSite = _siteService.GetSiteByUrl(site.Url);

                if (checkSite == null)
                {
                    siteModel.Sitemap = _siteService.GetSitemap(site.Url);
                    measures          = _siteService.MeasureSpeedResponse(siteModel.Sitemap);

                    if (measures == null)
                    {
                        return(View("SiteMapNotFound"));
                    }

                    siteModel.Pages = measures;
                    siteModel.Pages = _siteService.GetMinMax(siteModel.Pages);
                    _siteService.Add(siteModel);
                }

                else
                {
                    measures        = _siteService.MeasureSpeedResponse(checkSite.Sitemap);
                    checkSite.Pages = _siteService.GetListSpeeds(measures, checkSite.Pages);
                    checkSite.Pages = _siteService.GetMinMax(checkSite.Pages);
                    _siteService.UpdateSite(checkSite.Pages, checkSite.Id);
                }

                var getSiteResult = _siteService.GetSiteByUrl(site.Url);
                var result        = _mapper.Map <SiteViewModel>(getSiteResult);

                result.Pages = result.Pages.OrderBy(m => m.CurrentResponseTime).ToList();

                foreach (var item in getSiteResult.Pages)
                {
                    result.XPagesUrl.Add(item.PageUrl);
                    result.YPageSpeed.Add(item.CurrentResponseTime);
                }

                result.Sites = GetSelectList();

                return(View(result));
            }

            return(View("Index"));
        }
Пример #2
0
 public async Task <SiteResultModel> Post([FromBody] SitePostModel model)
 => _mapper.Map <SiteResultModel>(
     await _mediator.Send(new CreateSiteCommand(
                              _mapper.Map <Site>(model))));