Created
November 4, 2010 01:17
-
-
Save RexMorgan/661992 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
public interface IPartialActionExtension<T> | |
where T : class | |
{ | |
T Modify(T model); | |
} |
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
public interface IPartialActionExtensionGraph<T> : IPartialActionExtension<T> | |
where T : class | |
{ | |
} |
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
<%@ Page Language="C#" CodeBehind="MasterLoginLogout.aspx.cs" Inherits="Project.Web.Shared.Partials.Views.MasterLoginLogout" %> | |
<%@ Import Namespace="Project.Web.Models.Users" %> | |
<% if (Model.IsAuthenticated) {%> | |
<a href="<%=Urls.UrlFor(new UserLogoutGetModel())%>">Logout</a> | |
<% } else { %> | |
<a href="<%= Urls.UrlFor(new UserLoginGetModel()) %>">Login</a> | |
<%} %> |
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
public class MasterLoginLogout : FubuPage<MasterLoginLogoutModel> | |
{ | |
} |
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
[PartialModel] | |
public class MasterLoginLogoutModel | |
{ | |
public bool IsAuthenticated { 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
public class MasterLoginLogoutPartialActionExtension : IPartialActionExtension<MasterLoginLogoutModel> | |
{ | |
private readonly IAuthenticationManager _authenticationManager; | |
public MasterLoginLogoutPartialActionExtension(IAuthenticationManager authenticationManager) | |
{ | |
_authenticationManager = authenticationManager; | |
} | |
public MasterLoginLogoutModel Modify(MasterLoginLogoutModel model) | |
{ | |
model.IsAuthenticated = _authenticationManager.LoggedIn; | |
return model; | |
} | |
} |
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
public class PartialAction<T> | |
where T : class | |
{ | |
private readonly IPartialActionExtensionGraph<T> _graph; | |
public PartialAction(IPartialActionExtensionGraph<T> graph) | |
{ | |
_graph = graph; | |
} | |
public T Execute(T input) | |
{ | |
return _graph.Modify(input); | |
} | |
} |
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
public class PartialActionExtensionGraph<T> : IPartialActionExtensionGraph<T> | |
where T : class | |
{ | |
private readonly IContainer _container; | |
public PartialActionExtensionGraph(IContainer container) | |
{ | |
_container = container; | |
} | |
public T Modify(T model) | |
{ | |
_container.GetAllInstances<IPartialActionExtension<T>>() | |
.Each(extension => model = extension.Modify(model)); | |
return model; | |
} | |
} |
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
public class PartialActionsSource: IActionSource | |
{ | |
public IEnumerable<ActionCall> FindActions(TypePool types) | |
{ | |
return types | |
.TypesMatching(t => t.HasAttribute<PartialModelAttribute>()) | |
.Select(m => | |
{ | |
var actionType = typeof(PartialAction<>).MakeGenericType(m); | |
return new ActionCall(actionType, actionType.GetExecuteMethod()); | |
}); | |
} | |
} |
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
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="Project.Web.Shared.Master.Site" %> | |
<%@ Import Namespace="FubuCore" %> | |
<%@ Import Namespace="Project.Web.Shared.Partials.Models" %> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>Project Master Page</title> | |
</head> | |
<body> | |
<% this.Partial<MasterLoginLogoutModel>(); %> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment