This gist represents a collection of code snippets to be used during the Hands-on workshop: Modernize your Web Forms app using DotVVM. Original repo: https://github.com/riganti/dotvvm-samples-wingtip-toys
Last active
September 28, 2021 11:43
-
-
Save tomasherceg/be18a56ddd1d4974bbb09d0b92bb3710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install-Package Microsoft.Owin.Host.SystemWeb | |
Install-Package DotVVM.Owin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DotVVM.Framework.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
namespace WingtipToys.DotvvmSite | |
{ | |
public class DotvvmStartup : IDotvvmStartup, IDotvvmServiceConfigurator | |
{ | |
public void Configure(DotvvmConfiguration config, string applicationPath) | |
{ | |
ConfigureRoutes(config, applicationPath); | |
ConfigureResources(config, applicationPath); | |
ConfigureControls(config, applicationPath); | |
} | |
private void ConfigureRoutes(DotvvmConfiguration config, string applicationPath) | |
{ | |
// configure your DotVVM routes here | |
} | |
private void ConfigureResources(DotvvmConfiguration config, string applicationPath) | |
{ | |
} | |
private void ConfigureControls(DotvvmConfiguration config, string applicationPath) | |
{ | |
} | |
public void ConfigureServices(IDotvvmServiceCollection options) | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DotVVM.Framework.Configuration; | |
using Microsoft.Owin; | |
using Owin; | |
using System.Web.Hosting; | |
using WingtipToys.DotvvmSite; | |
[assembly: OwinStartupAttribute(typeof(WingtipToys.Startup))] | |
namespace WingtipToys | |
{ | |
public partial class Startup { | |
public void Configuration(IAppBuilder app) { | |
ConfigureAuth(app); | |
app.UseDotVVM<DotvvmStartup>(HostingEnvironment.ApplicationPhysicalPath, | |
useErrorPages: HostingEnvironment.IsDevelopmentEnvironment, | |
debug: HostingEnvironment.IsDevelopmentEnvironment); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@viewModel WingtipToys.DotvvmSite.ViewModels.SiteViewModel, WingtipToys | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title><%: Page.Title %> - Wingtip Toys</title> | |
<asp:PlaceHolder> | |
<%: Scripts.Render("~/bundles/modernizr") %> | |
</asp:PlaceHolder> | |
<webopt:bundlereference path="~/Content/css" /> | |
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> | |
</head> | |
<body> | |
<form> | |
<asp:ScriptManager> | |
<Scripts> | |
<%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%> | |
<%--Framework Scripts--%> | |
<asp:ScriptReference Name="MsAjaxBundle" /> | |
<asp:ScriptReference Name="jquery" /> | |
<asp:ScriptReference Name="bootstrap" /> | |
<asp:ScriptReference Name="respond" /> | |
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" /> | |
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" /> | |
<asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" /> | |
<asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" /> | |
<asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" /> | |
<asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" /> | |
<asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" /> | |
<asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" /> | |
<asp:ScriptReference Name="WebFormsBundle" /> | |
<%--Site Scripts--%> | |
</Scripts> | |
</asp:ScriptManager> | |
<div class="navbar navbar-inverse navbar-fixed-top"> | |
<div class="container"> | |
<div class="navbar-header"> | |
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
</button> | |
<a class="navbar-brand" href="~/">Wingtip Toys</a> | |
</div> | |
<div class="navbar-collapse collapse"> | |
<ul class="nav navbar-nav"> | |
<li> | |
<a id="adminLink" visible="false" | |
href="~/Admin/AdminPage">Admin</a> | |
</li> | |
<li><a href="~/">Home</a></li> | |
<li><a href="~/About">About</a></li> | |
<li><a href="~/Contact">Contact</a></li> | |
<li><a href="~/ProductList">Products</a></li> | |
<li><a href="~/ShoppingCart" ID="cartCount"> </a></li> | |
</ul> | |
<asp:LoginView ViewStateMode="Disabled"> | |
<AnonymousTemplate> | |
<ul class="nav navbar-nav navbar-right"> | |
<li><a href="~/Account/Register">Register</a></li> | |
<li><a href="~/Account/Login">Log in</a></li> | |
</ul> | |
</AnonymousTemplate> | |
<LoggedInTemplate> | |
<ul class="nav navbar-nav navbar-right"> | |
<li><a href="~/Account/Manage" title="Manage your account">Hello, <%: Context.User.Identity.GetUserName() %> !</a></li> | |
<li> | |
<asp:LoginStatus LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" OnLoggingOut="Unnamed_LoggingOut" /> | |
</li> | |
</ul> | |
</LoggedInTemplate> | |
</asp:LoginView> | |
</div> | |
</div> | |
</div> | |
<div id="TitleContent" style="text-align: center"> | |
<a href="~/"> | |
<img ID="Image1" ImageUrl="~/Images/logo.jpg" BorderStyle="None" /> | |
</a> | |
<br /> | |
</div> | |
<div id="CategoryMenu" style="text-align: center"> | |
<asp:ListView ID="categoryList" | |
ItemType="WingtipToys.Models.Category" | |
SelectMethod="GetCategories"> | |
<ItemTemplate> | |
<b style="font-size: large; font-style: normal"> | |
<a href="<%#: GetRouteUrl(" ProductsByCategoryRoute", new {categoryName=Item.CategoryName}) %> | |
"> | |
<%#: Item.CategoryName %> | |
</a> | |
</b> | |
</ItemTemplate> | |
<ItemSeparatorTemplate> | </ItemSeparatorTemplate> | |
</asp:ListView> | |
</div> | |
<div class="container body-content"> | |
<dot:ContentPlaceHolder ID="MainContent"> | |
</dot:ContentPlaceHolder> | |
<hr /> | |
<footer> | |
<p>© <%: DateTime.Now.Year %> - Wingtip Toys</p> | |
</footer> | |
</div> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" type="text/css" href="~/Content/css" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@viewModel WingtipToys.DotvvmSite.ViewModels.SiteViewModel, WingtipToys | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title><%: Page.Title %> - Wingtip Toys</title> | |
<link rel="stylesheet" type="text/css" href="~/Content/css" /> | |
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> | |
</head> | |
<body> | |
<div class="navbar navbar-inverse navbar-fixed-top"> | |
<div class="container"> | |
<div class="navbar-header"> | |
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
</button> | |
<a class="navbar-brand" href="~/">Wingtip Toys</a> | |
</div> | |
<div class="navbar-collapse collapse"> | |
<ul class="nav navbar-nav"> | |
<li> | |
<a id="adminLink" visible="false" | |
href="~/Admin/AdminPage">Admin</a> | |
</li> | |
<li><a href="~/">Home</a></li> | |
<li><a href="~/About">About</a></li> | |
<li><a href="~/Contact">Contact</a></li> | |
<li><a href="~/ProductList">Products</a></li> | |
<li><a href="~/ShoppingCart" ID="cartCount"> </a></li> | |
</ul> | |
<asp:LoginView ViewStateMode="Disabled"> | |
<AnonymousTemplate> | |
<ul class="nav navbar-nav navbar-right"> | |
<li><a href="~/Account/Register">Register</a></li> | |
<li><a href="~/Account/Login">Log in</a></li> | |
</ul> | |
</AnonymousTemplate> | |
<LoggedInTemplate> | |
<ul class="nav navbar-nav navbar-right"> | |
<li><a href="~/Account/Manage" title="Manage your account">Hello, <%: Context.User.Identity.GetUserName() %> !</a></li> | |
<li> | |
<asp:LoginStatus LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" OnLoggingOut="Unnamed_LoggingOut" /> | |
</li> | |
</ul> | |
</LoggedInTemplate> | |
</asp:LoginView> | |
</div> | |
</div> | |
</div> | |
<div id="TitleContent" style="text-align: center"> | |
<a href="~/"> | |
<img ID="Image1" ImageUrl="~/Images/logo.jpg" BorderStyle="None" /> | |
</a> | |
<br /> | |
</div> | |
<div id="CategoryMenu" style="text-align: center"> | |
<asp:ListView ID="categoryList" | |
ItemType="WingtipToys.Models.Category" | |
SelectMethod="GetCategories"> | |
<ItemTemplate> | |
<b style="font-size: large; font-style: normal"> | |
<a href="<%#: GetRouteUrl(" ProductsByCategoryRoute", new {categoryName=Item.CategoryName}) %> | |
"> | |
<%#: Item.CategoryName %> | |
</a> | |
</b> | |
</ItemTemplate> | |
<ItemSeparatorTemplate> | </ItemSeparatorTemplate> | |
</asp:ListView> | |
</div> | |
<div class="container body-content"> | |
<dot:ContentPlaceHolder ID="MainContent"> | |
</dot:ContentPlaceHolder> | |
<hr /> | |
<footer> | |
<p>© <%: DateTime.Now.Year %> - Wingtip Toys</p> | |
</footer> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dot:RoleView Roles="Administrator"> | |
<a href="~/Admin/AdminPage">Admin</a> | |
</dot:RoleView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dot:AuthenticatedView> | |
<NotAuthenticatedTemplate> | |
<ul class="nav navbar-nav navbar-right"> | |
<li><a href="~/Account/Register">Register</a></li> | |
<li><a href="~/Account/Login">Log in</a></li> | |
</ul> | |
</NotAuthenticatedTemplate> | |
<AuthenticatedTemplate> | |
<ul class="nav navbar-nav navbar-right"> | |
<li><a href="~/Account/Manage" title="Manage your account">Hello, {{resource: Context.HttpContext.User.Identity.Name}} !</a></li> | |
<li> | |
<dot:LinkButton Text="Log off" Click="{command: LogOut()}" /> | |
</li> | |
</ul> | |
</AuthenticatedTemplate> | |
</dot:AuthenticatedView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dot:Repeater DataSource="{value: Categories}"> | |
<ItemTemplate> | |
<b style="font-size: large; font-style: normal"> | |
<a href="{value: "category/" + CategoryName}"> | |
{{value: CategoryName}} | |
</a> | |
</b> | |
</ItemTemplate> | |
<SeparatorTemplate> | </SeparatorTemplate> | |
</dot:Repeater> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<title>{{resource: PageTitle}} - Wingtip Toys</title> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<li><a href="~/ShoppingCart" ID="cartCount">Cart ({{value: CartCount}})</a></li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@viewModel WingtipToys.DotvvmSite.ViewModels.SiteViewModel, WingtipToys | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>{{resource: PageTitle}} - Wingtip Toys</title> | |
<link rel="stylesheet" type="text/css" href="~/Content/css" /> | |
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> | |
</head> | |
<body> | |
<div class="navbar navbar-inverse navbar-fixed-top"> | |
<div class="container"> | |
<div class="navbar-header"> | |
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
</button> | |
<a class="navbar-brand" href="~/">Wingtip Toys</a> | |
</div> | |
<div class="navbar-collapse collapse"> | |
<ul class="nav navbar-nav"> | |
<li> | |
<dot:RoleView Roles="Administrator"> | |
<a href="~/Admin/AdminPage">Admin</a> | |
</dot:RoleView> | |
</li> | |
<li><a href="~/">Home</a></li> | |
<li><a href="~/About">About</a></li> | |
<li><a href="~/Contact">Contact</a></li> | |
<li><a href="~/ProductList">Products</a></li> | |
<li><a href="~/ShoppingCart" ID="cartCount">Cart ({{value: CartCount}})</a></li> | |
</ul> | |
<dot:AuthenticatedView> | |
<NotAuthenticatedTemplate> | |
<ul class="nav navbar-nav navbar-right"> | |
<li><a href="~/Account/Register">Register</a></li> | |
<li><a href="~/Account/Login">Log in</a></li> | |
</ul> | |
</NotAuthenticatedTemplate> | |
<AuthenticatedTemplate> | |
<ul class="nav navbar-nav navbar-right"> | |
<li><a href="~/Account/Manage" title="Manage your account">Hello, {{resource: Context.HttpContext.User.Identity.Name}} !</a></li> | |
<li> | |
<dot:LinkButton Text="Log off" Click="{command: LogOut()}" /> | |
</li> | |
</ul> | |
</AuthenticatedTemplate> | |
</dot:AuthenticatedView> | |
</div> | |
</div> | |
</div> | |
<div id="TitleContent" style="text-align: center"> | |
<a href="~/"> | |
<img ID="Image1" src="~/Images/logo.jpg" BorderStyle="None" /> | |
</a> | |
<br /> | |
</div> | |
<div id="CategoryMenu" style="text-align: center"> | |
<dot:Repeater DataSource="{value: Categories}"> | |
<ItemTemplate> | |
<b style="font-size: large; font-style: normal"> | |
<a href="{value: "category/" + CategoryName}"> | |
{{value: CategoryName}} | |
</a> | |
</b> | |
</ItemTemplate> | |
<SeparatorTemplate> | </SeparatorTemplate> | |
</dot:Repeater> | |
</div> | |
<div class="container body-content"> | |
<dot:ContentPlaceHolder ID="MainContent"> | |
</dot:ContentPlaceHolder> | |
<hr /> | |
<footer> | |
<p>© {{resource: DateTime.Now.Year}} - Wingtip Toys</p> | |
</footer> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using DotVVM.Framework.Hosting; | |
using DotVVM.Framework.ViewModel; | |
using WingtipToys.Logic; | |
using WingtipToys.Models; | |
namespace WingtipToys.DotvvmSite.ViewModels | |
{ | |
public abstract class SiteViewModel : DotvvmViewModelBase | |
{ | |
public int CartCount { get; set; } | |
public abstract string PageTitle { get; } | |
[Bind(Direction.ServerToClientFirstRequest)] | |
public List<CategoryDto> Categories { get; set; } | |
public void LogOut() | |
{ | |
Context.GetAuthentication().SignOut(); | |
Context.RedirectToLocalUrl("~/"); | |
} | |
public override Task PreRender() | |
{ | |
if (!Context.IsPostBack) | |
{ | |
using (var usersShoppingCart = new ShoppingCartActions()) | |
{ | |
CartCount = usersShoppingCart.GetCount(); | |
} | |
Categories = GetCategories(); | |
} | |
return base.PreRender(); | |
} | |
private List<CategoryDto> GetCategories() | |
{ | |
var _db = new WingtipToys.Models.ProductContext(); | |
IQueryable<Category> query = _db.Categories; | |
return query | |
.Select(q => new CategoryDto() | |
{ | |
CategoryName = q.CategoryName | |
}) | |
.ToList(); | |
} | |
public class CategoryDto | |
{ | |
public string CategoryName { get; set; } | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using DotVVM.Framework.ViewModel; | |
namespace WingtipToys.DotvvmSite.ViewModels | |
{ | |
public class TestViewModel : SiteViewModel | |
{ | |
public override string PageTitle => "Test"; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// paste into ConfigureRoutes method | |
config.RouteTable.Add("Test", "test", "DotvvmSite/Views/Test.dothtml"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Owin; | |
using Microsoft.Owin.Extensions; | |
using Owin; | |
using System.Web; | |
using System.Web.Hosting; | |
using System.Web.SessionState; | |
using WingtipToys.DotvvmSite; | |
[assembly: OwinStartupAttribute(typeof(WingtipToys.Startup))] | |
namespace WingtipToys | |
{ | |
public partial class Startup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
app.Use((context, next) => | |
{ | |
var httpContext = context.Get<HttpContextBase>(typeof(HttpContextBase).FullName); | |
httpContext.SetSessionStateBehavior(SessionStateBehavior.Required); | |
return next(); | |
}); | |
app.UseStageMarker(PipelineStage.MapHandler); | |
ConfigureAuth(app); | |
app.UseDotVVM<DotvvmStartup>(HostingEnvironment.ApplicationPhysicalPath, | |
useErrorPages: HostingEnvironment.IsDevelopmentEnvironment, debug: HostingEnvironment.IsDevelopmentEnvironment); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment