public ActionResult Retrieve(string url) { JsonViewData viewData = Validate <JsonViewData>( new Validation(() => string.IsNullOrEmpty(url), "Url nie mo¿e byæ pusty."), new Validation(() => !url.IsWebUrl(), "Niepoprawny format Url.") ); if (viewData == null) { try { IStory story = _storyRepository.FindByUrl(url); if (story != null) { string existingUrl = Url.RouteUrl("Detail", new { name = story.UniqueName }); viewData = new JsonContentViewData { alreadyExists = true, existingUrl = existingUrl }; } else { StoryContent content = _contentService.Get(url); viewData = (content == StoryContent.Empty) ? new JsonViewData { errorMessage = "Podany Url nie istnieje." } : new JsonContentViewData { isSuccessful = true, title = content.Title.HtmlDecode(), description = content.Description.HtmlDecode() }; } } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("pobierania strony.") }; } } return(Json(viewData)); }
public ActionResult Retrieve(string url) { JsonViewData viewData = Validate <JsonViewData>( new Validation(() => string.IsNullOrEmpty(url), "Url cannot be blank."), new Validation(() => !url.IsWebUrl(), "Invalid Url format.") ); if (viewData == null) { try { IStory story = _storyRepository.FindByUrl(url); if (story != null) { string existingUrl = Url.RouteUrl("Detail", new { name = story.UniqueName }); viewData = new JsonContentViewData { alreadyExists = true, existingUrl = existingUrl }; } else { StoryContent content = _contentService.Get(url); viewData = (content == StoryContent.Empty) ? new JsonViewData { errorMessage = "Specified url does not exist." } : new JsonContentViewData { isSuccessful = true, title = content.Title.HtmlDecode(), description = content.Description.HtmlDecode() }; } } catch (Exception e) { Log.Exception(e); viewData = new JsonViewData { errorMessage = FormatStrings.UnknownError.FormatWith("retrieving url") }; } } return(Json(viewData, JsonRequestBehavior.AllowGet)); }