Skip to content

Commit eed26ce

Browse files
committed
Merge branch 'master' into dev
2 parents 329b14c + 8fe3991 commit eed26ce

593 files changed

Lines changed: 75858 additions & 1727 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@
6161
#*.PDF diff=astextplain
6262
#*.rtf diff=astextplain
6363
#*.RTF diff=astextplain
64+
65+
66+
67+
*.js linguist-language=C#
68+
*.css linguist-language=C#
69+
*.html linguist-language=C#

License

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 雨~
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

NETCore.DapperKit.sln

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26430.13
4+
VisualStudioVersion = 15.0.26430.14
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{424ABC0A-A295-498F-BC1D-BBF3EDA7ACC7}"
77
EndProject
@@ -17,6 +17,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NETCore.DapperKit.Tests", "
1717
EndProject
1818
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{813A8C5B-8457-469F-BC69-94198C570898}"
1919
ProjectSection(SolutionItems) = preProject
20+
.gitattributes = .gitattributes
2021
README.md = README.md
2122
EndProjectSection
2223
EndProject

README.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,80 @@
11
# NETCore.DapperKit
2-
Dapper extensions
2+
3+
## Easy use [Dapper](https://github.com/StackExchange/Dapper) like ef with DapperKit.
4+
5+
6+
---
7+
8+
# Install with nuget
9+
10+
- To install NETCore.DapperKit, run the following command in the [Package Manager](https://docs.microsoft.com/zh-cn/nuget/tools/package-manager-console) Console
11+
12+
```
13+
Install-Package NETCore.DapperKit -Version 2.0.0
14+
```
15+
16+
# Add Dapperkit service in starup.cs
17+
18+
- Using DapperKit extensions
19+
20+
```csharp
21+
using NETCore.DapperKit.Extensions;
22+
```
23+
24+
- Add Dapperkit service
25+
26+
```csharp
27+
public void ConfigureServices(IServiceCollection services)
28+
{
29+
// Add framework services.
30+
services.AddMvc();
31+
32+
// Add DapperKit
33+
services.AddDapperKit(optionsBuilder =>
34+
{
35+
optionsBuilder.UseDapper(new DapperKitOptions()
36+
{
37+
ConnectionString = "Data Source=.;User ID=sa;Password='123456';Initial Catalog=DapperDb;MultipleActiveResultSets=True;"
38+
});
39+
});
40+
}
41+
42+
```
43+
44+
# User DapperKit in asp.net core mvc controller
45+
46+
- Init DapperContext
47+
```csharp
48+
public class AccountController : Controller
49+
{
50+
51+
private readonly IDapperContext _DapperContext;
52+
53+
public AccountController(IDapperContext context)
54+
{
55+
_DapperContext = context;
56+
}
57+
...
58+
}
59+
```
60+
61+
- Use Dapper Like EF
62+
63+
```csharp
64+
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
65+
{
66+
...
67+
var users = await _DapperContext.DbSet<SysUser>()
68+
.Select<SysUserRole>((u, r) => new SysUser() { Id = u.Id, IsAdmin = u.IsAdmin, LoginName = u.LoginName, LoginPwd = u.LoginPwd, CreateTime = u.CreateTime, UserName = u.UserName, UserRoleNo = u.UserRoleNo, RoleName = r.Name })
69+
.Join<SysUserRole>((u, r) => u.UserRoleNo == r.No)
70+
.Where(m => m.LoginName == model.Account && m.LoginPwd == model.Password)
71+
.ToListAsync<SysUser>();
72+
...
73+
}
74+
```
75+
76+
# LICENSE
77+
78+
[MIT LICESE](https://github.com/myloveCc/NETCore.DapperKit/blob/master/License)
79+
80+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using NETCore.DapperKit.Web.ViewModels;
7+
using NETCore.DapperKit.Web.Model;
8+
9+
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
10+
11+
namespace NETCore.DapperKit.Web.Controllers
12+
{
13+
public class AccountController : Controller
14+
{
15+
16+
private readonly IDapperContext _DapperContext;
17+
18+
public AccountController(IDapperContext context)
19+
{
20+
_DapperContext = context;
21+
}
22+
23+
// GET: /<controller>/
24+
public IActionResult Index()
25+
{
26+
return View();
27+
}
28+
29+
/// <summary>
30+
/// 登录方法
31+
/// </summary>
32+
/// <param name="model">UserViewModel实体信息</param>
33+
/// <param name="returnUrl">返回Url地址</param>
34+
/// <returns></returns>
35+
[HttpPost]
36+
[ValidateAntiForgeryToken]
37+
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
38+
{
39+
ViewData["ReturnUrl"] = returnUrl;
40+
if (!ModelState.IsValid) return View(model);
41+
42+
try
43+
{
44+
var users = await _DapperContext.DbSet<SysUser>()
45+
.Select<SysUserRole>((u, r) => new SysUser() { Id = u.Id, IsAdmin = u.IsAdmin, LoginName = u.LoginName, LoginPwd = u.LoginPwd, CreateTime = u.CreateTime, UserName = u.UserName, UserRoleNo = u.UserRoleNo, RoleName = r.Name })
46+
.Join<SysUserRole>((u, r) => u.UserRoleNo == r.No)
47+
.Where(m => m.LoginName == model.Account && m.LoginPwd == model.Password)
48+
.ToListAsync<SysUser>();
49+
50+
51+
if (users != null && users.First().LoginName == model.Account)
52+
{
53+
return RedirectToAction("Index", "Home");
54+
}
55+
}
56+
catch (Exception ex)
57+
{
58+
59+
}
60+
61+
return RedirectToAction("Index");
62+
}
63+
64+
}
65+
}

example/NETCore.DapperKit.Web/Controllers/HomeController.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,13 @@ public HomeController(IDapperRepository dapperRepository)
1818

1919
public IActionResult Index()
2020
{
21-
var model = new DapperKitModel()
22-
{
23-
Account = "dswq42",
24-
Password = "123456"
25-
};
26-
27-
var result = _DapperRepository.Insert(model);
28-
2921
return View();
3022
}
3123

3224
public async Task<IActionResult> About()
3325
{
3426
ViewData["Message"] = "Your application description page.";
3527

36-
var result = await _DapperRepository.GetAllAsync<DapperKitModel>();
37-
3828
return View();
3929
}
4030

example/NETCore.DapperKit.Web/Model/DapperKitModel.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using NETCore.DapperKit.Extensions;
6+
7+
namespace NETCore.DapperKit.Web.Model
8+
{
9+
[Table("SysUser")]
10+
public class SysUser
11+
{
12+
/// <summary>
13+
/// primary key
14+
/// </summary>\
15+
[Key]
16+
public int Id { get; set; }
17+
/// <summary>
18+
/// account
19+
/// </summary>
20+
public string LoginName { get; set; }
21+
/// <summary>
22+
/// password
23+
/// </summary>
24+
public string LoginPwd { get; set; }
25+
26+
public string UserName { get; set; }
27+
28+
public string UserRoleNo { get; set; }
29+
30+
public bool IsAdmin { get; set; }
31+
32+
public DateTime CreateTime { get; set; }
33+
34+
[Write(false)]
35+
public string RoleName { get; set; }
36+
}
37+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace NETCore.DapperKit.Web.Model
7+
{
8+
public class SysUserGroup
9+
{
10+
public int UserCount { get; set; }
11+
12+
public string Role { get; set; }
13+
}
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using NETCore.DapperKit.Extensions;
6+
7+
namespace NETCore.DapperKit.Web.Model
8+
{
9+
[Table("SysUserRole")]
10+
public class SysUserRole
11+
{
12+
[Key]
13+
public string No { get; set; }
14+
15+
public string Name { get; set; }
16+
}
17+
}

0 commit comments

Comments
 (0)