Skip to content

Instantly share code, notes, and snippets.

@casper-rasmussen
Last active April 3, 2016 18:07
Show Gist options
  • Save casper-rasmussen/26b45a7329eef50bf8516fe0baa56e66 to your computer and use it in GitHub Desktop.
Save casper-rasmussen/26b45a7329eef50bf8516fe0baa56e66 to your computer and use it in GitHub Desktop.
class FormViewModelBuilder : IFormViewModelBuilder
{
public FormViewModel Build(XForm form, CultureInfo culture)
{
FormViewModel viewModel = new FormViewModel();
viewModel.Form = form;
viewModel.Show = form != null;
if (form != null)
{
RouteValueDictionary values = new RouteValueDictionary(new { controller = "Form", action = "Index", language = culture.Name, area = "MyArea" });
RequestContext context = new RequestContext(new HttpContextWrapper(HttpContext.Current), HttpContext.Current.Request.RequestContext.RouteData);
VirtualPathData url = RouteTable.Routes.GetVirtualPathForArea(context, "Default_MyArea", values);
//Force our area and culture
string actionUrl = url.VirtualPath;
actionUrl = UriSupport.AddQueryString(actionUrl, "XFormId", form.Id.ToString());
actionUrl = UriSupport.AddQueryString(actionUrl, "failedAction", "Failed");
actionUrl = UriSupport.AddQueryString(actionUrl, "successAction", "Success");
viewModel.ActionUrl = actionUrl;
}
return viewModel;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment