OpenAuth.Net/CodeSmith/CSharp/Web/Application.cst

85 lines
2.8 KiB
Plaintext
Raw Normal View History

2017-11-29 18:26:36 +08:00
<%--
Name: Database Table Properties
Author: yubaolee
Description: Create a list of properties from a database table
--%>
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="应用层" %>
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
using System;
using System.Collections.Generic;
using System.Linq;
2017-12-15 00:03:06 +08:00
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.App.SSO;
using OpenAuth.Repository.Domain;
2017-11-29 18:26:36 +08:00
namespace OpenAuth.App
{
2017-12-15 00:03:06 +08:00
public class <%=ModuleName%>App : BaseApp<<%=ModuleName%>>
2017-11-29 18:26:36 +08:00
{
2017-12-15 00:03:06 +08:00
public RevelanceManagerApp ReleManagerApp { get; set; }
2017-11-29 18:26:36 +08:00
/// <summary>
2017-12-15 00:03:06 +08:00
/// 加载列表
2017-11-29 18:26:36 +08:00
/// </summary>
2017-12-15 00:03:06 +08:00
public TableData Load(Query<%=ModuleName%>ListReq request)
2017-11-29 18:26:36 +08:00
{
2017-12-15 00:03:06 +08:00
var loginUser = AuthUtil.GetCurrentUser();
string cascadeId = ".0.";
if (!string.IsNullOrEmpty(request.orgId))
2017-11-29 18:26:36 +08:00
{
2017-12-15 00:03:06 +08:00
var org = loginUser.Orgs.SingleOrDefault(u => u.Id == request.orgId);
cascadeId = org.CascadeId;
2017-11-29 18:26:36 +08:00
}
2017-12-15 00:03:06 +08:00
var ids = loginUser.Orgs.Where(u => u.CascadeId.Contains(cascadeId)).Select(u => u.Id).ToArray();
var roleIds = ReleManagerApp.Get(Define.ROLEORG, false, ids);
var roles = UnitWork.Find<<%=ModuleName%>>(u => roleIds.Contains(u.Id))
.OrderBy(u => u.Name)
.Skip((request.page - 1) * request.limit)
.Take(request.limit);
var records = Repository.GetCount(u => roleIds.Contains(u.Id));
var roleViews = new List<<%=ModuleName%>View>();
foreach (var role in roles)
2017-11-29 18:26:36 +08:00
{
2017-12-15 00:03:06 +08:00
RoleView uv = role;
var orgs = LoadByRole(role.Id);
uv.Organizations = string.Join(",", orgs.Select(u => u.Name).ToList());
uv.OrganizationIds = string.Join(",", orgs.Select(u => u.Id).ToList());
roleViews.Add(uv);
2017-11-29 18:26:36 +08:00
}
2017-12-15 00:03:06 +08:00
return new TableData
2017-11-29 18:26:36 +08:00
{
2017-12-15 00:03:06 +08:00
count = records,
data = roleViews,
2017-11-29 18:26:36 +08:00
};
}
2017-12-15 00:03:06 +08:00
public void Add(<%=ModuleName%> obj)
2017-11-29 18:26:36 +08:00
{
2017-12-15 00:03:06 +08:00
Repository.Add(obj);
2017-11-29 18:26:36 +08:00
}
2017-12-15 00:03:06 +08:00
public void Update(<%=ModuleName%> obj)
2017-11-29 18:26:36 +08:00
{
2017-12-15 00:03:06 +08:00
UnitWork.Update<User>(u => u.Id == obj.Id, u => new User
2017-11-29 18:26:36 +08:00
{
2017-12-15 00:03:06 +08:00
Name = role.Name,
Status = role.Status
});
2017-11-29 18:26:36 +08:00
}
}
2015-11-22 23:54:21 +08:00
}