-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
230 additions
and
10 deletions.
There are no files selected for viewing
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
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
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> |
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
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 | ||
{ | ||
} | ||
} |
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
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 | ||
{ | ||
} | ||
} |
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
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); | ||
} | ||
} |
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
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); | ||
} | ||
} | ||
} |
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
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> |
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
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
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; } | ||
} | ||
} |
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
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
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); | ||
} | ||
} | ||
} |
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
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); | ||
} | ||
} | ||
} |