Exemplo n.º 1
0
        public async Task <ActionResult> GetHostHistory(string url)
        {
            if (_homeControllerService == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError,
                                                "homeControllerService is null"));
            }

            try
            {
                string hostUrl = Helper.GetHost(url);

                if (hostUrl != null)
                {
                    HistoryViewModel history = await _homeControllerService.GetHostHistory(hostUrl);

                    return(Json(history, JsonRequestBehavior.AllowGet));
                }

                return(Json(HistoryViewModel.HistoryError(url, "History is empty"),
                            JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Exemplo n.º 2
0
        public async Task <HistoryViewModel> GetHostHistory(string hostUrl)
        {
            if (string.IsNullOrWhiteSpace(hostUrl))
            {
                return(HistoryViewModel.HistoryError(hostUrl, "Please enter url"));
            }

            var gruped = (await _repository.GetHostHistory(hostUrl)).GroupBy(x => x.Page.Url).ToList();

            if (!gruped.Any())
            {
                return(HistoryViewModel.HistoryError(hostUrl, "History is empty"));
            }

            var history = new HistoryViewModel
            {
                HostUrl   = hostUrl,
                Success   = true,
                HostPages = new List <PageModel>()
            };

            foreach (IGrouping <string, HostHistory> page in gruped)
            {
                var newPage = new PageModel
                {
                    Url         = page.Key,
                    HostHistory = page.OrderByDescending(x => x.Date).Select(x => new HistoryModel
                    {
                        Date         = x.Date.ToString("MM/dd/yyyy HH:mm:ss"),
                        ResponseTime = x.ResponseTime
                    }).ToList()
                };

                history.HostPages.Add(newPage);
            }

            return(history);
        }