Skip to content

Commit

Permalink
应用层
Browse files Browse the repository at this point in the history
  • Loading branch information
wenha committed Apr 11, 2019
1 parent 458028d commit ce51691
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 10 deletions.
27 changes: 27 additions & 0 deletions APP.Application/APP.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,20 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.0\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Identity.Core.2.2.2\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.EntityFramework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Identity.EntityFramework.2.2.2\lib\net45\Microsoft.AspNet.Identity.EntityFramework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -41,7 +54,21 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationBase.cs" />
<Compile Include="IApplication.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Users\IUserApplication.cs" />
<Compile Include="Users\UserApplication.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\APP.Core\APP.Core.csproj">
<Project>{AE6A5AC1-2B1D-4B66-BA6C-D5A308639CBE}</Project>
<Name>APP.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
17 changes: 17 additions & 0 deletions APP.Application/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v13.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
12 changes: 12 additions & 0 deletions APP.Application/ApplicationBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace APP.Application
{
public class ApplicationBase
{
}
}
12 changes: 12 additions & 0 deletions APP.Application/IApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace APP.Application
{
public interface IApplication
{
}
}
15 changes: 15 additions & 0 deletions APP.Application/Users/IUserApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using APP.Core.Users;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace APP.Application.Users
{
public interface IUserApplication : IApplication
{
IQueryable<User> GetUsers(Expression<Func<User, bool>> predicate);
}
}
26 changes: 26 additions & 0 deletions APP.Application/Users/UserApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using APP.Core;
using APP.Core.Users;

namespace APP.Application.Users
{
public class UserApplication : ApplicationBase, IUserApplication
{
private readonly IRepository<User, int> UserRepository;

public UserApplication(IRepository<User, int> userRepository)
{
UserRepository = userRepository;
}

public IQueryable<User> GetUsers(Expression<Func<User, bool>> predicate)
{
return UserRepository.GetAll(predicate);
}
}
}
6 changes: 6 additions & 0 deletions APP.Application/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.0" targetFramework="net461" />
<package id="Microsoft.AspNet.Identity.Core" version="2.2.2" targetFramework="net461" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="2.2.2" targetFramework="net461" />
</packages>
1 change: 1 addition & 0 deletions APP.Model/APP.Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Users\LoginUser.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
19 changes: 19 additions & 0 deletions APP.Model/Users/LoginUser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace APP.Model.Users
{
public class LoginUser
{
public int UserId { get; set; }

public string UserName { get; set; }

public string RealName { get; set; }

public int RoleId { get; set; }
}
}
21 changes: 21 additions & 0 deletions APP.Web/APP.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<Reference Include="Microsoft.AspNet.Identity.EntityFramework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -126,6 +128,7 @@
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Controllers\BaseController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
Expand Down Expand Up @@ -186,6 +189,24 @@
<Content Include="Scripts\jquery-3.3.1.slim.min.map" />
<Content Include="Scripts\jquery-3.3.1.min.map" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\APP.Application\APP.Application.csproj">
<Project>{990395BF-B290-46C5-8DD6-C9A41F6C786C}</Project>
<Name>APP.Application</Name>
</ProjectReference>
<ProjectReference Include="..\APP.Core\APP.Core.csproj">
<Project>{AE6A5AC1-2B1D-4B66-BA6C-D5A308639CBE}</Project>
<Name>APP.Core</Name>
</ProjectReference>
<ProjectReference Include="..\APP.EntityFramework\APP.EntityFramework.csproj">
<Project>{8C03D133-C87C-413A-8471-89E22875761C}</Project>
<Name>APP.EntityFramework</Name>
</ProjectReference>
<ProjectReference Include="..\APP.Model\APP.Model.csproj">
<Project>{0A7D2C56-6CCF-4A62-ADA5-43031EEC71E5}</Project>
<Name>APP.Model</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down
63 changes: 63 additions & 0 deletions APP.Web/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using APP.EntityFramework.Context;
using APP.Model.Users;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace APP.Web.Controllers
{
public class BaseController : Controller
{
private LoginUser _loginUser;
private APPContext _dbContext;

public LoginUser LoginUser
{
get
{
if(_loginUser != null)
{
return _loginUser;
}
return _loginUser;
}
}

private APPContext DBContext
{
get
{
if(_dbContext != null)
{
return _dbContext;
}
_dbContext = DependencyResolver.Current.GetService<APPContext>();
return _dbContext;
}
}

protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
try
{
if (!DBContext.IsDisposed)
{
using (DBContext)
{
if (DBContext.ChangeTracker.HasChanges())
{
DBContext.SaveChanges();
}
}
}
}
catch(Exception ex)
{
throw;
}
base.OnActionExecuted(filterContext); base.OnActionExecuted(filterContext);
}
}
}
21 changes: 11 additions & 10 deletions APP.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
using System;
using APP.Application.Users;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace APP.Web.Controllers
{
public class HomeController : Controller
public class HomeController : BaseController
{
public ActionResult Index()
private readonly IUserApplication UserApplication;

public HomeController(IUserApplication userApplication)
{
return View();
UserApplication = userApplication;
}

public ActionResult About()
public ActionResult Index()
{
ViewBag.Message = "Your application description page.";

return View();
}

public ActionResult Contact()
public ActionResult GetAll()
{
ViewBag.Message = "Your contact page.";
var data = UserApplication.GetUsers(u => u.RealName == "张三");

return View();
return Json(data);
}
}
}

0 comments on commit ce51691

Please sign in to comment.