/// <summary> /// Enrich the SearchQuery View Model with request querystring parameters and populate the results using a configured Search Provider. /// </summary> protected override ViewModel EnrichModel(ViewModel model) { using (new Tracer(model)) { base.EnrichModel(model); SearchQuery searchQuery = model as SearchQuery; if (searchQuery == null || !searchQuery.GetType().IsGenericType) { throw new DxaSearchException(String.Format("Unexpected View Model: '{0}'. Expecting type SearchQuery<T>.", model)); } NameValueCollection queryString = Request.QueryString; // Map standard query string parameters searchQuery.QueryText = queryString["q"]; searchQuery.Start = queryString.AllKeys.Contains("start") ? Convert.ToInt32(queryString["start"]) : 1; // To allow the Search Provider to use additional query string parameters: searchQuery.QueryStringParameters = queryString; Type searchItemType = searchQuery.GetType().GetGenericArguments()[0]; SearchProvider.ExecuteQuery(searchQuery, searchItemType, WebRequestContext.Localization); return searchQuery; } }
protected override ViewModel EnrichModel(ViewModel sourceModel) { DynamicList model = base.EnrichModel(sourceModel) as DynamicList; if (model == null || model.QueryResults.Any()) { return model; } //we need to run a query to populate the list if (model.Id == Request.Params["id"]) { //we only take the start from the query string if there is also an id parameter matching the model entity id //this means that we are sure that the paging is coming from the right entity (if there is more than one paged list on the page) model.Start = GetRequestParameter<int>("start"); } ContentProvider.PopulateDynamicList(model, WebRequestContext.Localization); return model; }
/// <summary> /// Decorates the HTML markup rendered by an Entity or Region View. /// </summary> /// <param name="htmlToDecorate">The HTML to decorate.</param> /// <param name="viewModel">The <see cref="ViewModel"/> associated with the HTML fragment.</param> /// <returns>The decorated HTML.</returns> public string DecorateMarkup(string htmlToDecorate, ViewModel viewModel) { SmartTargetExperiment experiment = viewModel as SmartTargetExperiment; if (experiment == null) { // Not a ST Experiment; nothing to do. return htmlToDecorate; } using (new Tracer(htmlToDecorate, viewModel)) { if (_analyticsManager == null) { // NOTE: might overwrite in a race condition, but that's not a problem. _analyticsManager = new AnalyticsManager(); } AnalyticsMetaData analyticsMetaData = new AnalyticsMetaData(); return _analyticsManager.AddTrackingToLinks(htmlToDecorate, experiment.ExperimentDimensions, analyticsMetaData); } }
protected override ViewModel EnrichModel(ViewModel model) { using (new Tracer(model)) { LoginForm loginForm = base.EnrichModel(model) as LoginForm; if (loginForm != null && MapRequestFormData(loginForm) && ModelState.IsValid) { // This is login form submission and basic field validation is fine. // Authenticate the user using the AudienceManager Membership Provider. if (Membership.ValidateUser(loginForm.UserName, loginForm.Password)) { FormsAuthentication.SetAuthCookie(loginForm.UserName, loginForm.RememberMe); return new RedirectModel(WebRequestContext.Localization.GetBaseUrl()); } ModelState.AddModelError("UserName", loginForm.AuthenticationErrorMessage); } return model; } }
/// <summary> /// Resolves CM-managed validation messages. /// </summary> /// <param name="inputMessage">The input validation message which may have the special syntax <c>@Model.{$ModelPropertyName}</c>.</param> /// <param name="model">The View Model used to resolve the value of such Model property expression.</param> /// <returns>The resolved validation message or the input message in case resolving fails.</returns> private static string ResolveValidationMessage(string inputMessage, ViewModel model) { const string modelPrefix = "@Model."; if (!inputMessage.StartsWith(modelPrefix)) { return inputMessage; } string modelPropertyName = inputMessage.Substring(modelPrefix.Length); PropertyInfo validationMessageProperty = model.GetType().GetProperty(modelPropertyName); string validationMessagePropertyValue = null; if (validationMessageProperty != null) { validationMessagePropertyValue = validationMessageProperty.GetValue(model) as string; } if (string.IsNullOrEmpty(validationMessagePropertyValue)) { Log.Warn("No validation message could be resolved for expression '{0}'", inputMessage); return inputMessage; } return validationMessagePropertyValue; }