├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── TsBlog.sln ├── document └── scripts │ └── mysql │ ├── tsblog_v1.2.sql │ ├── v1.8 │ └── tb_user.sql │ └── v1.9 │ └── tsblog.sql └── src ├── Libraries ├── TsBlog.AutoMapperConfig │ ├── AutoMapperConfiguration.cs │ ├── AutoMapperStartupTask.cs │ ├── MappingExtensions.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── TsBlog.AutoMapperConfig.csproj │ └── packages.config ├── TsBlog.Core │ ├── HtmlHelper.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Security │ │ └── Encryptor.cs │ ├── StringHelper.cs │ └── TsBlog.Core.csproj ├── TsBlog.Domain │ ├── Entities │ │ ├── Post.cs │ │ └── User.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── TsBlog.Domain.csproj │ └── packages.config ├── TsBlog.Repositories │ ├── Config.cs │ ├── DataConverter.cs │ ├── DbFactory.cs │ ├── GenericRepository.cs │ ├── IDependency.cs │ ├── IPagedList.cs │ ├── IPostRepository.cs │ ├── IRepository.cs │ ├── IUserRepository.cs │ ├── MySqlHelper.cs │ ├── PagedList.cs │ ├── PostRepository.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── TsBlog.Repositories.csproj │ ├── UserRepository.cs │ ├── app.config │ ├── lib │ │ ├── MySql.Data.dll │ │ └── MySqlSugar.dll │ └── packages.config ├── TsBlog.Services │ ├── GenericService.cs │ ├── IPostService.cs │ ├── IService.cs │ ├── IUserService.cs │ ├── PostService.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── TsBlog.Services.csproj │ ├── UserService.cs │ └── app.config └── TsBlog.ViewModel │ ├── Post │ └── PostViewModel.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── TsBlog.ViewModel.csproj │ └── User │ ├── LoginViewModel.cs │ ├── RegisterViewModel.cs │ └── UserViewModel.cs └── Presentation └── TsBlog.Frontend ├── App_Start ├── BundleConfig.cs ├── FilterConfig.cs ├── RouteConfig.cs └── WebApiConfig.cs ├── Content ├── PagedList.css ├── Site.css ├── bootstrap-theme.css ├── bootstrap-theme.css.map ├── bootstrap-theme.min.css ├── bootstrap-theme.min.css.map ├── bootstrap.css ├── bootstrap.css.map ├── bootstrap.min.css └── bootstrap.min.css.map ├── Controllers ├── AccountController.cs ├── Api │ └── UserController.cs ├── HomeController.cs └── PostController.cs ├── Extensions └── PostExtension.cs ├── Global.asax ├── Global.asax.cs ├── Properties └── AssemblyInfo.cs ├── Scripts ├── bootstrap.js ├── bootstrap.min.js ├── jquery-3.4.1.intellisense.js ├── jquery-3.4.1.js └── jquery-3.4.1.min.js ├── TsBlog.Frontend.csproj ├── Views ├── Account │ ├── login.cshtml │ └── register.cshtml ├── Home │ ├── Index.cshtml │ └── Post.cshtml ├── Post │ └── Details.cshtml ├── Shared │ ├── Error.cshtml │ ├── _Layout.cshtml │ └── _NavBar.cshtml └── Web.config ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── favicon.ico ├── fonts ├── glyphicons-halflings-regular.eot ├── glyphicons-halflings-regular.svg ├── glyphicons-halflings-regular.ttf ├── glyphicons-halflings-regular.woff └── glyphicons-halflings-regular.woff2 ├── index.html ├── packages.config └── resources └── css └── site.css /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | *.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | 65 | Scripts/* linguist-vendored 66 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc 262 | /TsBlog.Frontend/Properties/PublishProfiles 263 | 264 | /Scripts/ 265 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TsBlog 2 | **TsBlog**是一个基于ASP.NET MVC 5+Repository+Autofac+AutoMapper+SqlSugar的系列教程。旨在帮助.NET开发者快速地提升ASP.NET MVC项目的开发效率和开发技巧。 3 | 4 | 本项目由基础到框架,通过实战项目中的设计,封装以及重构,让.NET开发者们可以直观地感受ASP.NET MVC 5+Repository+Autofac+AutoMapper+SqlSugar的整个开流程和细节。 5 | 6 | 本项目有专门的专题教程,详情请见:[一步一步创建ASP.NET MVC5程序\[Repository+Autofac+Automapper+SqlSugar\]][1] 7 | 8 | 如果你在学习或者查看源码时遇到什么问题,或有意见/建议,欢迎加入我们的QQ交流群:483350228 9 | 10 | [1]: https://codedefault.com/t/EdVp8xCk 11 | -------------------------------------------------------------------------------- /TsBlog.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2010 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2.Persentation", "2.Persentation", "{FA8E85B0-9A67-4C64-B336-7DAD8D6833D0}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1.Libraries", "1.Libraries", "{EC3F3ECF-1C39-46B1-9379-13CE519A2BE9}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TsBlog.Domain", "src\Libraries\TsBlog.Domain\TsBlog.Domain.csproj", "{E415AB82-2704-4984-9576-A9BC8F3DED30}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TsBlog.Repositories", "src\Libraries\TsBlog.Repositories\TsBlog.Repositories.csproj", "{0B3D004F-250E-439F-B0AB-9268C33D3DEB}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TsBlog.Frontend", "src\Presentation\TsBlog.Frontend\TsBlog.Frontend.csproj", "{5CC238A7-ED1E-475D-B8F0-43E94CF5A24E}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TsBlog.Services", "src\Libraries\TsBlog.Services\TsBlog.Services.csproj", "{6BCFD47C-B93A-4E6C-8E27-3EF8CCB49D74}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TsBlog.AutoMapperConfig", "src\Libraries\TsBlog.AutoMapperConfig\TsBlog.AutoMapperConfig.csproj", "{2866A0EC-8F66-4CB5-BC70-568EC3397EFB}" 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TsBlog.ViewModel", "src\Libraries\TsBlog.ViewModel\TsBlog.ViewModel.csproj", "{459E7C49-DE30-4FFD-8912-FF9ED8069DEB}" 21 | EndProject 22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TsBlog.Core", "src\Libraries\TsBlog.Core\TsBlog.Core.csproj", "{0A171809-BF68-4AD5-A3D2-D4638149E95C}" 23 | EndProject 24 | Global 25 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 26 | Debug|Any CPU = Debug|Any CPU 27 | Release|Any CPU = Release|Any CPU 28 | EndGlobalSection 29 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 30 | {E415AB82-2704-4984-9576-A9BC8F3DED30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {E415AB82-2704-4984-9576-A9BC8F3DED30}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {E415AB82-2704-4984-9576-A9BC8F3DED30}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {E415AB82-2704-4984-9576-A9BC8F3DED30}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {0B3D004F-250E-439F-B0AB-9268C33D3DEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {0B3D004F-250E-439F-B0AB-9268C33D3DEB}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {0B3D004F-250E-439F-B0AB-9268C33D3DEB}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {0B3D004F-250E-439F-B0AB-9268C33D3DEB}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {5CC238A7-ED1E-475D-B8F0-43E94CF5A24E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {5CC238A7-ED1E-475D-B8F0-43E94CF5A24E}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {5CC238A7-ED1E-475D-B8F0-43E94CF5A24E}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {5CC238A7-ED1E-475D-B8F0-43E94CF5A24E}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {6BCFD47C-B93A-4E6C-8E27-3EF8CCB49D74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {6BCFD47C-B93A-4E6C-8E27-3EF8CCB49D74}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {6BCFD47C-B93A-4E6C-8E27-3EF8CCB49D74}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {6BCFD47C-B93A-4E6C-8E27-3EF8CCB49D74}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {2866A0EC-8F66-4CB5-BC70-568EC3397EFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {2866A0EC-8F66-4CB5-BC70-568EC3397EFB}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {2866A0EC-8F66-4CB5-BC70-568EC3397EFB}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {2866A0EC-8F66-4CB5-BC70-568EC3397EFB}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {459E7C49-DE30-4FFD-8912-FF9ED8069DEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {459E7C49-DE30-4FFD-8912-FF9ED8069DEB}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {459E7C49-DE30-4FFD-8912-FF9ED8069DEB}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {459E7C49-DE30-4FFD-8912-FF9ED8069DEB}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {0A171809-BF68-4AD5-A3D2-D4638149E95C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {0A171809-BF68-4AD5-A3D2-D4638149E95C}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {0A171809-BF68-4AD5-A3D2-D4638149E95C}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {0A171809-BF68-4AD5-A3D2-D4638149E95C}.Release|Any CPU.Build.0 = Release|Any CPU 58 | EndGlobalSection 59 | GlobalSection(SolutionProperties) = preSolution 60 | HideSolutionNode = FALSE 61 | EndGlobalSection 62 | GlobalSection(NestedProjects) = preSolution 63 | {E415AB82-2704-4984-9576-A9BC8F3DED30} = {EC3F3ECF-1C39-46B1-9379-13CE519A2BE9} 64 | {0B3D004F-250E-439F-B0AB-9268C33D3DEB} = {EC3F3ECF-1C39-46B1-9379-13CE519A2BE9} 65 | {5CC238A7-ED1E-475D-B8F0-43E94CF5A24E} = {FA8E85B0-9A67-4C64-B336-7DAD8D6833D0} 66 | {6BCFD47C-B93A-4E6C-8E27-3EF8CCB49D74} = {EC3F3ECF-1C39-46B1-9379-13CE519A2BE9} 67 | {2866A0EC-8F66-4CB5-BC70-568EC3397EFB} = {EC3F3ECF-1C39-46B1-9379-13CE519A2BE9} 68 | {459E7C49-DE30-4FFD-8912-FF9ED8069DEB} = {EC3F3ECF-1C39-46B1-9379-13CE519A2BE9} 69 | {0A171809-BF68-4AD5-A3D2-D4638149E95C} = {EC3F3ECF-1C39-46B1-9379-13CE519A2BE9} 70 | EndGlobalSection 71 | GlobalSection(ExtensibilityGlobals) = postSolution 72 | SolutionGuid = {C238B374-A804-4D90-9C62-E56EC977BA8B} 73 | EndGlobalSection 74 | EndGlobal 75 | -------------------------------------------------------------------------------- /document/scripts/mysql/tsblog_v1.2.sql: -------------------------------------------------------------------------------- 1 | /* 2 | SQLyog Enterprise v12.4.1 (64 bit) 3 | MySQL - 5.7.17-log : Database - tsblog 4 | ********************************************************************* 5 | */ 6 | 7 | /*!40101 SET NAMES utf8 */; 8 | 9 | /*!40101 SET SQL_MODE=''*/; 10 | 11 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 12 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 13 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 14 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 15 | CREATE DATABASE /*!32312 IF NOT EXISTS*/`tsblog` /*!40100 DEFAULT CHARACTER SET utf8 */; 16 | 17 | USE `tsblog`; 18 | 19 | /*Table structure for table `tb_post` */ 20 | 21 | DROP TABLE IF EXISTS `tb_post`; 22 | 23 | CREATE TABLE `tb_post` ( 24 | `Id` int(12) NOT NULL AUTO_INCREMENT, 25 | `Title` varchar(255) DEFAULT '' COMMENT '标题', 26 | `Content` text COMMENT '内容', 27 | `AuthorId` int(6) DEFAULT '0' COMMENT '作者ID', 28 | `AuthorName` varchar(50) DEFAULT '' COMMENT '作者姓名', 29 | `CreatedAt` datetime DEFAULT NULL COMMENT '创建时间', 30 | `PublishedAt` datetime DEFAULT NULL COMMENT '发布时间', 31 | `IsDeleted` bit(1) DEFAULT b'0' COMMENT '是否标识已删除[0:否,1:是],默认值:0', 32 | `AllowShow` bit(1) DEFAULT b'1' COMMENT '是否允许展示[0:否,1:是],默认值:1', 33 | `ViewCount` int(10) DEFAULT '0' COMMENT '浏览量', 34 | PRIMARY KEY (`Id`) 35 | ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; 36 | 37 | /*Data for the table `tb_post` */ 38 | 39 | insert into `tb_post`(`Id`,`Title`,`Content`,`AuthorId`,`AuthorName`,`CreatedAt`,`PublishedAt`,`IsDeleted`,`AllowShow`,`ViewCount`) values 40 | (1,'Title','Clean content',0,'',NULL,NULL,'\0','',0); 41 | 42 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 43 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 44 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 45 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 46 | -------------------------------------------------------------------------------- /document/scripts/mysql/v1.8/tb_user.sql: -------------------------------------------------------------------------------- 1 | SET FOREIGN_KEY_CHECKS = 0; 2 | 3 | -- ---------------------------- 4 | -- Table structure for ts_user 5 | -- ---------------------------- 6 | DROP TABLE IF EXISTS `tb_user`; 7 | CREATE TABLE `tb_user` ( 8 | `Id` int(10) NOT NULL AUTO_INCREMENT, 9 | `LoginName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '登录名', 10 | `Password` varchar(150) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '密码', 11 | `DisplayName` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '显示名称', 12 | `RealName` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '真实姓名', 13 | `EmailAddress` varchar(120) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '电子邮箱', 14 | `Avatar` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '用户头像', 15 | `Status` int(2) NOT NULL DEFAULT 1 COMMENT '用户的状态,0:禁用,1:正常', 16 | `Telephone` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '手机号码', 17 | `Qq` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '', 18 | `WebsiteUrl` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '', 19 | `CreatedOn` datetime(0) NULL DEFAULT NULL COMMENT '用户创建时间', 20 | `CreatedIp` varchar(24) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '创建用户时的IP地址', 21 | `LoginCount` int(8) NULL DEFAULT 0 COMMENT '登录次数累加器', 22 | `LatestLoginDate` datetime(0) NULL DEFAULT NULL COMMENT '最近一次登录时间', 23 | `LatestLoginIp` varchar(24) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '最近一次登录时的IP地址', 24 | `ModifiedOn` datetime(0) NULL DEFAULT NULL COMMENT '最近修改时间', 25 | `Type` int(2) NULL DEFAULT 0 COMMENT '用户类型[-1:超级管理员,0:一般用户]', 26 | PRIMARY KEY (`Id`) USING BTREE, 27 | UNIQUE INDEX `IX_LoginName`(`LoginName`) USING BTREE, 28 | UNIQUE INDEX `IX_EmailAddress`(`EmailAddress`) USING BTREE, 29 | INDEX `IX_CreatedOn`(`CreatedOn`) USING BTREE 30 | ) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; 31 | 32 | SET FOREIGN_KEY_CHECKS = 1; 33 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.AutoMapperConfig/AutoMapperConfiguration.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using TsBlog.Domain.Entities; 3 | using TsBlog.ViewModel.Post; 4 | using TsBlog.ViewModel.User; 5 | 6 | namespace TsBlog.AutoMapperConfig 7 | { 8 | /// 9 | /// AutoMapper的全局实体映射配置静态类 10 | /// 11 | public static class AutoMapperConfiguration 12 | { 13 | public static void Init() 14 | { 15 | MapperConfiguration = new MapperConfiguration(cfg => 16 | { 17 | 18 | #region Post 19 | //将领域实体映射到视图实体 20 | cfg.CreateMap() 21 | .ForMember(d => d.IsDeleted, d => d.MapFrom(s => s.IsDeleted ? "是" : "否")) //将布尔类型映射成字符串类型的是/否 22 | ; 23 | //将视图实体映射到领域实体 24 | cfg.CreateMap(); 25 | #endregion 26 | 27 | #region User 28 | 29 | cfg.CreateMap(); 30 | cfg.CreateMap(); 31 | #endregion 32 | }); 33 | 34 | Mapper = MapperConfiguration.CreateMapper(); 35 | } 36 | 37 | public static IMapper Mapper { get; private set; } 38 | 39 | public static MapperConfiguration MapperConfiguration { get; private set; } 40 | } 41 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.AutoMapperConfig/AutoMapperStartupTask.cs: -------------------------------------------------------------------------------- 1 | namespace TsBlog.AutoMapperConfig 2 | { 3 | /// 4 | /// AutoMapper初始化类 5 | /// 6 | public class AutoMapperStartupTask 7 | { 8 | public void Execute() 9 | { 10 | AutoMapperConfiguration.Init(); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.AutoMapperConfig/MappingExtensions.cs: -------------------------------------------------------------------------------- 1 | using TsBlog.Domain.Entities; 2 | using TsBlog.ViewModel.Post; 3 | using TsBlog.ViewModel.User; 4 | 5 | namespace TsBlog.AutoMapperConfig 6 | { 7 | /// 8 | /// 数据库表-实体映射静态扩展类 9 | /// 10 | public static class MappingExtensions 11 | { 12 | public static TDestination MapTo(this TSource source) 13 | { 14 | return AutoMapperConfiguration.Mapper.Map(source); 15 | } 16 | 17 | public static TDestination MapTo(this TSource source, TDestination destination) 18 | { 19 | return AutoMapperConfiguration.Mapper.Map(source, destination); 20 | } 21 | 22 | #region Post 23 | public static PostViewModel ToModel(this Post entity) 24 | { 25 | return entity.MapTo(); 26 | } 27 | 28 | public static Post ToEntity(this PostViewModel model) 29 | { 30 | return model.MapTo(); 31 | } 32 | 33 | #endregion 34 | 35 | #region User 36 | public static UserViewModel ToModel(this User entity) 37 | { 38 | return entity.MapTo(); 39 | } 40 | 41 | public static User ToEntity(this UserViewModel model) 42 | { 43 | return model.MapTo(); 44 | } 45 | 46 | #endregion 47 | 48 | } 49 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.AutoMapperConfig/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TsBlog.AutoMapperConfig")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TsBlog.AutoMapperConfig")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("2866a0ec-8f66-4cb5-bc70-568ec3397efb")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.AutoMapperConfig/TsBlog.AutoMapperConfig.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {2866A0EC-8F66-4CB5-BC70-568EC3397EFB} 8 | Library 9 | Properties 10 | TsBlog.AutoMapperConfig 11 | TsBlog.AutoMapperConfig 12 | v4.6.2 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\..\..\packages\AutoMapper.8.0.0\lib\net461\AutoMapper.dll 35 | 36 | 37 | 38 | 39 | 40 | ..\..\..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | {e415ab82-2704-4984-9576-a9bc8f3ded30} 58 | TsBlog.Domain 59 | 60 | 61 | {459E7C49-DE30-4FFD-8912-FF9ED8069DEB} 62 | TsBlog.ViewModel 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.AutoMapperConfig/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Core/HtmlHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace TsBlog.Core 4 | { 5 | public static class HtmlHelper 6 | { 7 | #region 去掉HTML中的所有标签,只留下纯文本 8 | /// 9 | /// 去掉HTML中的所有标签,只留下纯文本 10 | /// 11 | /// 12 | /// 13 | public static string CleanHtml(this string strHtml) 14 | { 15 | if (string.IsNullOrEmpty(strHtml)) return strHtml; 16 | //删除脚本 17 | strHtml = Regex.Replace(strHtml, "(\\)|(\\)", "", RegexOptions.IgnoreCase | RegexOptions.Singleline); 18 | //删除标签 19 | var r = new Regex(@"<\/?[^>]*>", RegexOptions.IgnoreCase); 20 | Match m; 21 | for (m = r.Match(strHtml); m.Success; m = m.NextMatch()) 22 | { 23 | strHtml = strHtml.Replace(m.Groups[0].ToString(), ""); 24 | } 25 | return strHtml.Trim(); 26 | } 27 | 28 | #endregion 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TsBlog.Core")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TsBlog.Core")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0a171809-bf68-4ad5-a3d2-d4638149e95c")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Core/Security/Encryptor.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Cryptography; 2 | using System.Text; 3 | 4 | namespace TsBlog.Core.Security 5 | { 6 | /// 7 | /// 加密静态类 8 | /// 9 | public static class Encryptor 10 | { 11 | //MD5加密一个字符串 12 | public static string Md5Hash(string text) 13 | { 14 | MD5 md5 = new MD5CryptoServiceProvider(); 15 | md5.ComputeHash(Encoding.ASCII.GetBytes(text)); 16 | 17 | var result = md5.Hash; 18 | 19 | var strBuilder = new StringBuilder(); 20 | foreach (var t in result) 21 | { 22 | strBuilder.Append(t.ToString("x2")); 23 | } 24 | 25 | return strBuilder.ToString(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Core/StringHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TsBlog.Core 4 | { 5 | public static class StringHelper 6 | { 7 | #region 8 | /// 9 | /// 截取指定长度的字符串 10 | /// 11 | /// 原始字符串 12 | /// 要保留的字符串长度 13 | /// 14 | public static string CutStrLength(this string str, int strLength) 15 | { 16 | var strNew = str; 17 | if (string.IsNullOrEmpty(strNew)) return strNew; 18 | var strOriginalLength = strNew.Length; 19 | if (strOriginalLength > strLength) 20 | { 21 | strNew = strNew.Substring(0, strLength) + "..."; 22 | } 23 | return strNew; 24 | } 25 | 26 | #endregion 27 | 28 | #region 29 | /// 30 | /// 截取指定长度的字符串 31 | /// 32 | /// 原始字符串 33 | /// 要保留的字符串长度 34 | /// 是或以省略号(...)结束 35 | /// 36 | public static string CutStrLength(string str, int strLength, bool endWithEllipsis) 37 | { 38 | string strNew = str; 39 | if (!strNew.Equals("")) 40 | { 41 | int strOriginalLength = strNew.Length; 42 | if (strOriginalLength > strLength) 43 | { 44 | strNew = strNew.Substring(0, strLength); 45 | if (endWithEllipsis) 46 | { 47 | strNew += "..."; 48 | } 49 | } 50 | } 51 | return strNew; 52 | } 53 | 54 | #endregion 55 | 56 | #region 截断字符串(可保留完整单词) 57 | /// 58 | /// 截断字符串(可保留完整单词) 59 | /// 60 | /// 需处理的字符串 61 | /// 字符数 62 | /// 截断选项 63 | /// 64 | public static string TruncateString(this string valueToTruncate, int maxLength, TruncateOptions options) 65 | { 66 | if (valueToTruncate == null) 67 | { 68 | return ""; 69 | } 70 | 71 | if (valueToTruncate.Length <= maxLength) 72 | { 73 | return valueToTruncate; 74 | } 75 | 76 | var includeEllipsis = (options & TruncateOptions.IncludeEllipsis) == 77 | TruncateOptions.IncludeEllipsis; 78 | var finishWord = (options & TruncateOptions.FinishWord) == 79 | TruncateOptions.FinishWord; 80 | var allowLastWordOverflow = 81 | (options & TruncateOptions.AllowLastWordToGoOverMaxLength) == 82 | TruncateOptions.AllowLastWordToGoOverMaxLength; 83 | 84 | var retValue = valueToTruncate; 85 | 86 | if (includeEllipsis) 87 | { 88 | maxLength -= 1; 89 | } 90 | 91 | var lastSpaceIndex = retValue.LastIndexOf(" ", 92 | maxLength, StringComparison.CurrentCultureIgnoreCase); 93 | 94 | if (!finishWord) 95 | { 96 | retValue = retValue.Remove(maxLength); 97 | } 98 | else if (allowLastWordOverflow) 99 | { 100 | var spaceIndex = retValue.IndexOf(" ", 101 | maxLength, StringComparison.CurrentCultureIgnoreCase); 102 | if (spaceIndex != -1) 103 | { 104 | retValue = retValue.Remove(spaceIndex); 105 | } 106 | } 107 | else if (lastSpaceIndex > -1) 108 | { 109 | retValue = retValue.Remove(lastSpaceIndex); 110 | } 111 | 112 | if (includeEllipsis && retValue.Length < valueToTruncate.Length) 113 | { 114 | retValue += "..."; 115 | } 116 | return retValue; 117 | } 118 | 119 | #endregion 120 | } 121 | 122 | #region 截断字符串用的枚举 123 | /// 124 | /// 截断字符串用的枚举 125 | /// 126 | [Flags] 127 | public enum TruncateOptions 128 | { 129 | /// 130 | /// 不作任何处理 131 | /// 132 | None = 0x0, 133 | /// 134 | /// 保留完整单词 135 | /// 136 | FinishWord = 0x1, 137 | /// 138 | /// 允许最后一个单词超过最大长度限制 139 | /// 140 | AllowLastWordToGoOverMaxLength = 0x2, 141 | /// 142 | /// 字符串最后跟省略号 143 | /// 144 | IncludeEllipsis = 0x4 145 | } 146 | #endregion 147 | } 148 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Core/TsBlog.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0A171809-BF68-4AD5-A3D2-D4638149E95C} 8 | Library 9 | Properties 10 | TsBlog.Core 11 | TsBlog.Core 12 | v4.6.2 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Domain/Entities/Post.cs: -------------------------------------------------------------------------------- 1 | using SqlSugar; 2 | using System; 3 | 4 | namespace TsBlog.Domain.Entities 5 | { 6 | /// 7 | /// 博文实体类 8 | /// 9 | [SugarTable("tb_post")] 10 | public class Post 11 | { 12 | /// 13 | /// ID 14 | /// 15 | [SugarColumn(IsIdentity = true, IsPrimaryKey = true)] 16 | public int Id { get; set; } 17 | /// 18 | /// 标题 19 | /// 20 | public string Title { get; set; } 21 | /// 22 | /// 内容 23 | /// 24 | public string Content { get; set; } 25 | /// 26 | /// 作者ID 27 | /// 28 | public string AuthorId { get; set; } 29 | /// 30 | /// 作者姓名 31 | /// 32 | public string AuthorName { get; set; } 33 | /// 34 | /// 创建时间 35 | /// 36 | public DateTime CreatedAt { get; set; } 37 | /// 38 | /// 发布时间 39 | /// 40 | public DateTime PublishedAt { get; set; } 41 | /// 42 | /// 是否标识已删除 43 | /// 44 | public bool IsDeleted { get; set; } 45 | /// 46 | /// 是否允许展示 47 | /// 48 | public bool AllowShow { get; set; } 49 | /// 50 | /// 浏览量 51 | /// 52 | public int ViewCount { get; set; } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Domain/Entities/User.cs: -------------------------------------------------------------------------------- 1 | using SqlSugar; 2 | using System; 3 | 4 | namespace TsBlog.Domain.Entities 5 | { 6 | [SugarTable("tb_user")] 7 | public class User 8 | { 9 | [SugarColumn(IsIdentity = true, IsPrimaryKey = true)] 10 | public int Id { get; set; } 11 | public string LoginName { get; set; } 12 | public string Password { get; set; } 13 | public string RealName { get; set; } 14 | public string EmailAddress { get; set; } 15 | public string Avatar { get; set; } 16 | public int Status { get; set; } 17 | public string Telephone { get; set; } 18 | public string Qq { get; set; } 19 | public string WebsiteUrl { get; set; } 20 | public DateTime CreatedOn { get; set; } 21 | public string CreatedIp { get; set; } 22 | public int LoginCount { get; set; } 23 | public DateTime? LatestLoginDate { get; set; } 24 | public string LatestLoginIp { get; set; } 25 | public DateTime? ModifiedOn { get; set; } 26 | public int Type { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Domain/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TsBlog.Domain")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TsBlog.Domain")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e415ab82-2704-4984-9576-a9bc8f3ded30")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Domain/TsBlog.Domain.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {E415AB82-2704-4984-9576-A9BC8F3DED30} 8 | Library 9 | Properties 10 | TsBlog.Domain 11 | TsBlog.Domain 12 | v4.6.2 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\..\..\packages\sqlSugar.4.6.0.6\lib\SqlSugar.dll 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Domain/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/Config.cs: -------------------------------------------------------------------------------- 1 | using System.Configuration; 2 | 3 | namespace TsBlog.Repositories 4 | { 5 | /// 6 | /// 静态配置类 7 | /// 8 | public static class Config 9 | { 10 | /// 11 | /// 数据库连接字符串(私有字段) 12 | /// 13 | private static readonly string _connectionString =ConfigurationManager.ConnectionStrings["TsBlogMySQLDb"].ConnectionString; 14 | /// 15 | /// 数据库连接字符串(公有属性) 16 | /// 17 | public static string ConnectionString 18 | { 19 | get { return _connectionString; } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/DataConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data; 4 | using System.Linq; 5 | using System.Reflection; 6 | 7 | namespace TsBlog.Repositories 8 | { 9 | public static class DataConverter 10 | { 11 | public static List ToList(this DataTable table) where T : class, new() 12 | { 13 | var obj = new T(); 14 | var tType = obj.GetType(); 15 | var list = new List(); 16 | //Define what attributes to be read from the class 17 | const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; 18 | 19 | //Read Attribute Names and Types 20 | var objFieldNames = typeof(T).GetProperties(flags) 21 | .Select(item => new 22 | { 23 | item.Name, 24 | Type = Nullable.GetUnderlyingType(item.PropertyType) ?? item.PropertyType 25 | }).ToList(); 26 | 27 | //Read Datatable column names and types 28 | var dtlFieldNames = table.Columns.Cast() 29 | .Select(item => new 30 | { 31 | Name = item.ColumnName, 32 | Type = item.DataType 33 | }).ToList(); 34 | 35 | foreach (var row in table.Rows.Cast()) 36 | { 37 | foreach (var prop in objFieldNames) 38 | { 39 | if (!dtlFieldNames.Any(x => x.Name.Equals(prop.Name, StringComparison.CurrentCultureIgnoreCase))) 40 | { 41 | continue; 42 | } 43 | var propertyInfo = tType.GetProperty(prop.Name); 44 | var rowValue = row[prop.Name]; 45 | if (propertyInfo == null) continue; 46 | var t = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType; 47 | 48 | var safeValue = (rowValue == null || DBNull.Value.Equals(rowValue)) ? null : Convert.ChangeType(rowValue, t); 49 | propertyInfo.SetValue(obj, safeValue, null); 50 | } 51 | list.Add(obj); 52 | } 53 | return list; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/DbFactory.cs: -------------------------------------------------------------------------------- 1 | using SqlSugar; 2 | 3 | namespace TsBlog.Repositories 4 | { 5 | /// 6 | /// 数据库工厂 7 | /// 8 | public class DbFactory 9 | { 10 | /// 11 | /// SqlSugarClient属性 12 | /// 13 | /// 14 | public static SqlSugarClient GetSqlSugarClient() 15 | { 16 | var db = new SqlSugarClient(new ConnectionConfig() 17 | { 18 | ConnectionString = Config.ConnectionString, //必填 19 | DbType = DbType.MySql, //必填 20 | IsAutoCloseConnection = true, //默认false 21 | InitKeyType = InitKeyType.Attribute 22 | }); //默认SystemTable 23 | return db; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/GenericRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | 5 | namespace TsBlog.Repositories 6 | { 7 | public abstract class GenericRepository : IDependency, IRepository where T : class, new() 8 | { 9 | #region Implementation of IRepository 10 | 11 | /// 12 | /// 根据主值查询单条数据 13 | /// 14 | /// 主键值 15 | /// 泛型实体 16 | public T FindById(object pkValue) 17 | { 18 | using (var db = DbFactory.GetSqlSugarClient()) 19 | { 20 | var entity = db.Queryable().InSingle(pkValue); 21 | return entity; 22 | } 23 | } 24 | 25 | /// 26 | /// 查询所有数据(无分页,请慎用) 27 | /// 28 | /// 29 | public IEnumerable FindAll() 30 | { 31 | using (var db = DbFactory.GetSqlSugarClient()) 32 | { 33 | var list = db.Queryable().ToList(); 34 | return list; 35 | } 36 | } 37 | 38 | /// 39 | /// 根据条件查询数据 40 | /// 41 | /// 条件表达式树 42 | /// 排序 43 | /// 泛型实体集合 44 | public IEnumerable FindListByClause(Expression> predicate, string orderBy = "") 45 | { 46 | using (var db = DbFactory.GetSqlSugarClient()) 47 | { 48 | var query = db.Queryable().Where(predicate); 49 | if (!string.IsNullOrEmpty(orderBy)) 50 | { 51 | query = query.OrderBy(orderBy); 52 | } 53 | var entities = query.ToList(); 54 | return entities; 55 | } 56 | } 57 | 58 | /// 59 | /// 根据条件查询数据 60 | /// 61 | /// 条件表达式树 62 | /// 63 | public T FindByClause(Expression> predicate) 64 | { 65 | using (var db = DbFactory.GetSqlSugarClient()) 66 | { 67 | var entity = db.Queryable().First(predicate); 68 | return entity; 69 | } 70 | } 71 | 72 | /// 73 | /// 写入实体数据 74 | /// 75 | /// 实体类 76 | /// 77 | public long Insert(T entity) 78 | { 79 | using (var db = DbFactory.GetSqlSugarClient()) 80 | { 81 | //返回插入数据的标识字段值 82 | var i = db.Insertable(entity).ExecuteReturnBigIdentity(); 83 | return i; 84 | } 85 | } 86 | 87 | /// 88 | /// 更新实体数据 89 | /// 90 | /// 91 | /// 92 | public bool Update(T entity) 93 | { 94 | using (var db = DbFactory.GetSqlSugarClient()) 95 | { 96 | //这种方式会以主键为条件 97 | var i = db.Updateable(entity).ExecuteCommand(); 98 | return i > 0; 99 | } 100 | } 101 | 102 | /// 103 | /// 删除数据 104 | /// 105 | /// 实体类 106 | /// 107 | public bool Delete(T entity) 108 | { 109 | using (var db = DbFactory.GetSqlSugarClient()) 110 | { 111 | var i = db.Deleteable(entity).ExecuteCommand(); 112 | return i > 0; 113 | } 114 | } 115 | 116 | /// 117 | /// 删除数据 118 | /// 119 | /// 过滤条件 120 | /// 121 | public bool Delete(Expression> @where) 122 | { 123 | using (var db = DbFactory.GetSqlSugarClient()) 124 | { 125 | var i = db.Deleteable(@where).ExecuteCommand(); 126 | return i > 0; 127 | } 128 | } 129 | 130 | /// 131 | /// 删除指定ID的数据 132 | /// 133 | /// 134 | /// 135 | public bool DeleteById(object id) 136 | { 137 | using (var db = DbFactory.GetSqlSugarClient()) 138 | { 139 | var i = db.Deleteable(id).ExecuteCommand(); 140 | return i > 0; 141 | } 142 | } 143 | 144 | /// 145 | /// 删除指定ID集合的数据(批量删除) 146 | /// 147 | /// 148 | /// 149 | public bool DeleteByIds(object[] ids) 150 | { 151 | using (var db = DbFactory.GetSqlSugarClient()) 152 | { 153 | var i = db.Deleteable().In(ids).ExecuteCommand(); 154 | return i > 0; 155 | } 156 | } 157 | 158 | /// 159 | /// 根据条件查询分页数据 160 | /// 161 | /// 162 | /// 163 | /// 当前页面索引 164 | /// 分布大小 165 | /// 166 | public IPagedList FindPagedList(Expression> predicate, string orderBy = "", int pageIndex = 1, int pageSize = 20) 167 | { 168 | using (var db = DbFactory.GetSqlSugarClient()) 169 | { 170 | var totalCount = 0; 171 | var page = db.Queryable().OrderBy(orderBy).ToPageList(pageIndex, pageSize, ref totalCount); 172 | var list = new PagedList(page, pageIndex, pageSize, totalCount); 173 | return list; 174 | } 175 | } 176 | #endregion 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/IDependency.cs: -------------------------------------------------------------------------------- 1 | namespace TsBlog.Repositories 2 | { 3 | /// 4 | /// 依赖注入的接口约束 5 | /// 6 | public interface IDependency 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/IPagedList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TsBlog.Repositories 4 | { 5 | public interface IPagedList : IList 6 | { 7 | int PageIndex { get; } 8 | int PageSize { get; } 9 | int TotalCount { get; } 10 | int TotalPages { get; } 11 | bool HasPreviousPage { get; } 12 | bool HasNextPage { get; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/IPostRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using TsBlog.Domain.Entities; 3 | 4 | namespace TsBlog.Repositories 5 | { 6 | public interface IPostRepository : IRepository 7 | { 8 | /// 9 | /// 查询首页文章列表 10 | /// 11 | /// 要查询的记录数 12 | /// 13 | IEnumerable FindHomePagePosts(int limit = 20); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/IRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | 5 | namespace TsBlog.Repositories 6 | { 7 | /// 8 | /// 仓储通用接口类 9 | /// 10 | /// 泛型实体类 11 | public interface IRepository where T : class, new() 12 | { 13 | /// 14 | /// 根据主值查询单条数据 15 | /// 16 | /// 主键值 17 | /// 泛型实体 18 | T FindById(object pkValue); 19 | 20 | /// 21 | /// 查询所有数据(无分页,请慎用) 22 | /// 23 | /// 24 | IEnumerable FindAll(); 25 | /// 26 | /// 根据条件查询数据 27 | /// 28 | /// 条件表达式树 29 | /// 排序 30 | /// 泛型实体集合 31 | IEnumerable FindListByClause(Expression> predicate, string orderBy = ""); 32 | 33 | /// 34 | /// 根据条件查询数据 35 | /// 36 | /// 条件表达式树 37 | /// 38 | T FindByClause(Expression> predicate); 39 | 40 | /// 41 | /// 写入实体数据 42 | /// 43 | /// 实体类 44 | /// 45 | long Insert(T entity); 46 | 47 | /// 48 | /// 更新实体数据 49 | /// 50 | /// 51 | /// 52 | bool Update(T entity); 53 | 54 | /// 55 | /// 删除数据 56 | /// 57 | /// 实体类 58 | /// 59 | bool Delete(T entity); 60 | /// 61 | /// 删除数据 62 | /// 63 | /// 过滤条件 64 | /// 65 | bool Delete(Expression> @where); 66 | 67 | /// 68 | /// 删除指定ID的数据 69 | /// 70 | /// 71 | /// 72 | bool DeleteById(object id); 73 | 74 | /// 75 | /// 删除指定ID集合的数据(批量删除) 76 | /// 77 | /// 78 | /// 79 | bool DeleteByIds(object[] ids); 80 | 81 | /// 82 | /// 根据条件查询分页数据 83 | /// 84 | /// 85 | /// 86 | /// 当前页面索引 87 | /// 分布大小 88 | /// 89 | IPagedList FindPagedList(Expression> predicate, string orderBy = "", int pageIndex = 1, int pageSize = 20); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/IUserRepository.cs: -------------------------------------------------------------------------------- 1 | using TsBlog.Domain.Entities; 2 | 3 | namespace TsBlog.Repositories 4 | { 5 | public interface IUserRepository : IRepository 6 | { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/PagedList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace TsBlog.Repositories 6 | { 7 | /// 8 | /// 分页组件实体类 9 | /// 10 | /// 泛型实体 11 | 12 | [Serializable] 13 | public class PagedList : List, IPagedList 14 | { 15 | /// 16 | /// 构造函数 17 | /// 18 | /// 数据源 19 | /// 分页索引 20 | /// 分页大小 21 | public PagedList(IQueryable source, int pageIndex, int pageSize) 22 | { 23 | var total = source.Count(); 24 | TotalCount = total; 25 | TotalPages = total / pageSize; 26 | 27 | if (total % pageSize > 0) 28 | TotalPages++; 29 | 30 | PageSize = pageSize; 31 | PageIndex = pageIndex; 32 | 33 | AddRange(source.Skip(pageIndex * pageSize).Take(pageSize).ToList()); 34 | } 35 | 36 | /// 37 | /// 构造函数 38 | /// 39 | /// 数据源 40 | /// 分页索引 41 | /// 分页大小 42 | public PagedList(IList source, int pageIndex, int pageSize) 43 | { 44 | TotalCount = source.Count(); 45 | TotalPages = TotalCount / pageSize; 46 | 47 | if (TotalCount % pageSize > 0) 48 | TotalPages++; 49 | 50 | PageSize = pageSize; 51 | PageIndex = pageIndex; 52 | AddRange(source.Skip(pageIndex * pageSize).Take(pageSize).ToList()); 53 | } 54 | 55 | /// 56 | /// 构造函数 57 | /// 58 | /// 数据源 59 | /// 分页索引 60 | /// 分页大小 61 | /// 总记录数 62 | public PagedList(IEnumerable source, int pageIndex, int pageSize, int totalCount) 63 | { 64 | TotalCount = totalCount; 65 | TotalPages = TotalCount / pageSize; 66 | 67 | if (TotalCount % pageSize > 0) 68 | TotalPages++; 69 | 70 | PageSize = pageSize; 71 | PageIndex = pageIndex; 72 | AddRange(source); 73 | } 74 | 75 | /// 76 | /// 分页索引 77 | /// 78 | public int PageIndex { get; } 79 | /// 80 | /// 分页大小 81 | /// 82 | public int PageSize { get; private set; } 83 | /// 84 | /// 总记录数 85 | /// 86 | public int TotalCount { get; } 87 | /// 88 | /// 总页数 89 | /// 90 | public int TotalPages { get; } 91 | 92 | /// 93 | /// 是否有上一页 94 | /// 95 | public bool HasPreviousPage 96 | { 97 | get { return (PageIndex > 0); } 98 | } 99 | /// 100 | /// 是否有下一页 101 | /// 102 | public bool HasNextPage 103 | { 104 | get { return (PageIndex + 1 < TotalPages); } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/PostRepository.cs: -------------------------------------------------------------------------------- 1 | using SqlSugar; 2 | using System.Collections.Generic; 3 | using TsBlog.Domain.Entities; 4 | 5 | namespace TsBlog.Repositories 6 | { 7 | /// 8 | /// POST表的数据库操作类 9 | /// 10 | public class PostRepository : GenericRepository, IPostRepository 11 | { 12 | #region Implementation of IPostRepository 13 | 14 | /// 15 | /// 查询首页文章列表 16 | /// 17 | /// 要查询的记录数 18 | /// 19 | public IEnumerable FindHomePagePosts(int limit = 20) 20 | { 21 | using (var db = DbFactory.GetSqlSugarClient()) 22 | { 23 | var list = db.Queryable().OrderBy(x => x.Id, OrderByType.Desc).Take(limit).ToList(); 24 | return list; 25 | } 26 | } 27 | } 28 | #endregion 29 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TsBlog.Repositories")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TsBlog.Repositories")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0b3d004f-250e-439f-b0ab-9268c33d3deb")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/TsBlog.Repositories.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0B3D004F-250E-439F-B0AB-9268C33D3DEB} 8 | Library 9 | Properties 10 | TsBlog.Repositories 11 | TsBlog.Repositories 12 | v4.6.2 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\..\..\packages\Google.Protobuf.3.5.1\lib\net45\Google.Protobuf.dll 35 | 36 | 37 | ..\..\..\packages\MySql.Data.8.0.13\lib\net452\MySql.Data.dll 38 | 39 | 40 | ..\..\..\packages\mySqlSugar.3.5.3.4\lib\net40\MySqlSugar.dll 41 | 42 | 43 | ..\..\..\packages\sqlSugar.4.9.7.3\lib\SqlSugar.dll 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | {e415ab82-2704-4984-9576-a9bc8f3ded30} 85 | TsBlog.Domain 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/UserRepository.cs: -------------------------------------------------------------------------------- 1 | using TsBlog.Domain.Entities; 2 | 3 | namespace TsBlog.Repositories 4 | { 5 | public class UserRepository : GenericRepository, IUserRepository 6 | { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/lib/MySql.Data.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lampo1024/TsBlog/93bfe0416dfa2d3032f5c7c3362408a283d05ae7/src/Libraries/TsBlog.Repositories/lib/MySql.Data.dll -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/lib/MySqlSugar.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lampo1024/TsBlog/93bfe0416dfa2d3032f5c7c3362408a283d05ae7/src/Libraries/TsBlog.Repositories/lib/MySqlSugar.dll -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Repositories/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Services/GenericService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using TsBlog.Repositories; 5 | 6 | namespace TsBlog.Services 7 | { 8 | public abstract class GenericService : IService, IDependency where T : class, new() 9 | { 10 | private readonly IRepository _repository; 11 | 12 | protected GenericService(IRepository repository) 13 | { 14 | _repository = repository; 15 | } 16 | 17 | /// 18 | /// 根据主值查询单条数据 19 | /// 20 | /// 主键值 21 | /// 泛型实体 22 | public T FindById(object pkValue) 23 | { 24 | return _repository.FindById(pkValue); 25 | } 26 | 27 | /// 28 | /// 查询所有数据(无分页,请慎用) 29 | /// 30 | /// 31 | public IEnumerable FindAll() 32 | { 33 | return _repository.FindAll(); 34 | } 35 | 36 | /// 37 | /// 根据条件查询数据 38 | /// 39 | /// 条件表达式树 40 | /// 排序 41 | /// 泛型实体集合 42 | public IEnumerable FindListByClause(Expression> predicate, string orderBy = "") 43 | { 44 | return _repository.FindListByClause(predicate, orderBy); 45 | } 46 | 47 | /// 48 | /// 根据条件查询数据 49 | /// 50 | /// 条件表达式树 51 | /// 52 | public T FindByClause(Expression> predicate) 53 | { 54 | return _repository.FindByClause(predicate); 55 | } 56 | 57 | /// 58 | /// 写入实体数据 59 | /// 60 | /// 实体类 61 | /// 62 | public long Insert(T entity) 63 | { 64 | return _repository.Insert(entity); 65 | } 66 | 67 | /// 68 | /// 更新实体数据 69 | /// 70 | /// 71 | /// 72 | public bool Update(T entity) 73 | { 74 | return _repository.Update(entity); 75 | } 76 | 77 | /// 78 | /// 删除数据 79 | /// 80 | /// 实体类 81 | /// 82 | public bool Delete(T entity) 83 | { 84 | return _repository.Delete(entity); 85 | } 86 | 87 | /// 88 | /// 删除数据 89 | /// 90 | /// 过滤条件 91 | /// 92 | public bool Delete(Expression> @where) 93 | { 94 | return _repository.Delete(@where); 95 | } 96 | 97 | /// 98 | /// 删除指定ID的数据 99 | /// 100 | /// 101 | /// 102 | public bool DeleteById(object id) 103 | { 104 | return _repository.DeleteById(id); 105 | } 106 | 107 | /// 108 | /// 删除指定ID集合的数据(批量删除) 109 | /// 110 | /// 111 | /// 112 | public bool DeleteByIds(object[] ids) 113 | { 114 | return _repository.DeleteByIds(ids); 115 | } 116 | 117 | /// 118 | /// 根据条件查询分页数据 119 | /// 120 | /// 121 | /// 122 | /// 当前页面索引 123 | /// 分布大小 124 | /// 125 | public IPagedList FindPagedList(Expression> predicate, string orderBy = "", int pageIndex = 1, int pageSize = 20) 126 | { 127 | return _repository.FindPagedList(predicate, orderBy, pageIndex, pageSize); 128 | } 129 | } 130 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Services/IPostService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using TsBlog.Domain.Entities; 3 | 4 | namespace TsBlog.Services 5 | { 6 | public interface IPostService : IService 7 | { 8 | /// 9 | /// 查询首页文章列表 10 | /// 11 | /// 要查询的记录数 12 | /// 13 | IEnumerable FindHomePagePosts(int limit = 20); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Services/IService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using TsBlog.Repositories; 5 | 6 | namespace TsBlog.Services 7 | { 8 | /// 9 | /// 服务接口 10 | /// 11 | /// 12 | public interface IService 13 | { 14 | /// 15 | /// 根据主值查询单条数据 16 | /// 17 | /// 主键值 18 | /// 泛型实体 19 | T FindById(object pkValue); 20 | 21 | /// 22 | /// 查询所有数据(无分页,请慎用) 23 | /// 24 | /// 25 | IEnumerable FindAll(); 26 | 27 | /// 28 | /// 根据条件查询数据 29 | /// 30 | /// 条件表达式树 31 | /// 排序 32 | /// 泛型实体集合 33 | IEnumerable FindListByClause(Expression> predicate, string orderBy = ""); 34 | 35 | /// 36 | /// 根据条件查询数据 37 | /// 38 | /// 条件表达式树 39 | /// 40 | T FindByClause(Expression> predicate); 41 | 42 | /// 43 | /// 写入实体数据 44 | /// 45 | /// 实体类 46 | /// 47 | long Insert(T entity); 48 | 49 | /// 50 | /// 更新实体数据 51 | /// 52 | /// 53 | /// 54 | bool Update(T entity); 55 | 56 | /// 57 | /// 删除数据 58 | /// 59 | /// 实体类 60 | /// 61 | bool Delete(T entity); 62 | 63 | /// 64 | /// 删除数据 65 | /// 66 | /// 过滤条件 67 | /// 68 | bool Delete(Expression> @where); 69 | 70 | /// 71 | /// 删除指定ID的数据 72 | /// 73 | /// 74 | /// 75 | bool DeleteById(object id); 76 | 77 | /// 78 | /// 删除指定ID集合的数据(批量删除) 79 | /// 80 | /// 81 | /// 82 | bool DeleteByIds(object[] ids); 83 | 84 | /// 85 | /// 根据条件查询分页数据 86 | /// 87 | /// 88 | /// 89 | /// 当前页面索引 90 | /// 分布大小 91 | /// 92 | IPagedList FindPagedList(Expression> predicate, string orderBy = "", int pageIndex = 1, int pageSize = 20); 93 | } 94 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Services/IUserService.cs: -------------------------------------------------------------------------------- 1 | using TsBlog.Domain.Entities; 2 | 3 | namespace TsBlog.Services 4 | { 5 | public interface IUserService : IService 6 | { 7 | User FindByLoginName(string loginName); 8 | } 9 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Services/PostService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using TsBlog.Domain.Entities; 3 | using TsBlog.Repositories; 4 | 5 | namespace TsBlog.Services 6 | { 7 | public class PostService : GenericService, IPostService 8 | { 9 | private readonly IPostRepository _repository; 10 | public PostService(IPostRepository repository) : base(repository) 11 | { 12 | _repository = repository; 13 | } 14 | 15 | 16 | #region Implementation of IPostService 17 | 18 | /// 19 | /// 查询首页文章列表 20 | /// 21 | /// 要查询的记录数 22 | /// 23 | public IEnumerable FindHomePagePosts(int limit = 20) 24 | { 25 | return _repository.FindHomePagePosts(limit); 26 | } 27 | 28 | #endregion 29 | } 30 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Services/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TsBlog.Services")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TsBlog.Services")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("6bcfd47c-b93a-4e6c-8e27-3ef8ccb49d74")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Services/TsBlog.Services.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {6BCFD47C-B93A-4E6C-8E27-3EF8CCB49D74} 8 | Library 9 | Properties 10 | TsBlog.Services 11 | TsBlog.Services 12 | v4.6.2 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | {E415AB82-2704-4984-9576-A9BC8F3DED30} 54 | TsBlog.Domain 55 | 56 | 57 | {0B3D004F-250E-439F-B0AB-9268C33D3DEB} 58 | TsBlog.Repositories 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Services/UserService.cs: -------------------------------------------------------------------------------- 1 | using TsBlog.Domain.Entities; 2 | using TsBlog.Repositories; 3 | 4 | namespace TsBlog.Services 5 | { 6 | public class UserService : GenericService, IUserService 7 | { 8 | private readonly IUserRepository _repository; 9 | public UserService(IUserRepository repository) : base(repository) 10 | { 11 | _repository = repository; 12 | } 13 | 14 | public User FindByLoginName(string loginName) 15 | { 16 | return _repository.FindByClause(x => x.LoginName == loginName); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.Services/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.ViewModel/Post/PostViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace TsBlog.ViewModel.Post 2 | { 3 | /// 4 | /// 博文视图实体类 5 | /// 6 | public class PostViewModel 7 | { 8 | /// 9 | /// ID 10 | /// 11 | public int Id { get; set; } 12 | /// 13 | /// 标题 14 | /// 15 | public string Title { get; set; } 16 | /// 17 | /// 内容 18 | /// 19 | public string Content { get; set; } 20 | /// 21 | /// 作者ID 22 | /// 23 | public string AuthorId { get; set; } 24 | /// 25 | /// 作者姓名 26 | /// 27 | public string AuthorName { get; set; } 28 | /// 29 | /// 创建时间 30 | /// 31 | public string CreatedAt { get; set; } 32 | /// 33 | /// 发布时间 34 | /// 35 | public string PublishedAt { get; set; } 36 | /// 37 | /// 是否标识已删除 38 | /// 39 | public string IsDeleted { get; set; } 40 | /// 41 | /// 是否允许展示 42 | /// 43 | public bool AllowShow { get; set; } 44 | /// 45 | /// 浏览量 46 | /// 47 | public int ViewCount { get; set; } 48 | 49 | /// 50 | /// 摘要 51 | /// 52 | public string Summary { get; set; } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.ViewModel/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TsBlog.ViewModel")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TsBlog.ViewModel")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("459e7c49-de30-4ffd-8912-ff9ed8069deb")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.ViewModel/TsBlog.ViewModel.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {459E7C49-DE30-4FFD-8912-FF9ED8069DEB} 8 | Library 9 | Properties 10 | TsBlog.ViewModel 11 | TsBlog.ViewModel 12 | v4.6.2 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/Libraries/TsBlog.ViewModel/User/LoginViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace TsBlog.ViewModel.User 4 | { 5 | /// 6 | /// 用户登录视图实体 7 | /// 8 | public class LoginViewModel 9 | { 10 | [Required(ErrorMessage = "请输入用户")] 11 | [Display(Name = "用户名")] 12 | public string UserName { get; set; } 13 | [Required(ErrorMessage = "请输入密码")] 14 | [Display(Name = "密码")] 15 | [DataType(DataType.Password)] 16 | public string Password { get; set; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.ViewModel/User/RegisterViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace TsBlog.ViewModel.User 4 | { 5 | /// 6 | /// 用户注册视图实体 7 | /// 8 | public class RegisterViewModel 9 | { 10 | [Required(ErrorMessage = "请输入用户名")] 11 | [Display(Name = "用户名")] 12 | public string UserName { get; set; } 13 | [Required(ErrorMessage = "请输入密码")] 14 | [Display(Name = "密码")] 15 | [DataType(DataType.Password), MaxLength(20, ErrorMessage = "密码最大长度为20个字符"), MinLength(6, ErrorMessage = "密码最小长度为6个字符")] 16 | public string Password { get; set; } 17 | 18 | [Required(ErrorMessage = "请输入确认密码")] 19 | [Display(Name = "确认密码")] 20 | [DataType(DataType.Password), Compare("Password", ErrorMessage = "两次密码不一致")] 21 | public string ConfirmPassword { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /src/Libraries/TsBlog.ViewModel/User/UserViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TsBlog.ViewModel.User 4 | { 5 | /// 6 | /// 与领域用户实体对应的用户视图实体 7 | /// 8 | public class UserViewModel 9 | { 10 | public int Id { get; set; } 11 | public string LoginName { get; set; } 12 | public string Password { get; set; } 13 | public string RealName { get; set; } 14 | public string EmailAddress { get; set; } 15 | public string Avatar { get; set; } 16 | public int Status { get; set; } 17 | public string Telephone { get; set; } 18 | public string Qq { get; set; } 19 | public string WebsiteUrl { get; set; } 20 | public DateTime CreatedOn { get; set; } 21 | public string CreatedIp { get; set; } 22 | public int LoginCount { get; set; } 23 | public DateTime? LatestLoginDate { get; set; } 24 | public string LatestLoginIp { get; set; } 25 | public DateTime? ModifiedOn { get; set; } 26 | public int Type { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/App_Start/BundleConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Optimization; 3 | 4 | namespace TsBlog.Frontend 5 | { 6 | public class BundleConfig 7 | { 8 | // For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862 9 | public static void RegisterBundles(BundleCollection bundles) 10 | { 11 | bundles.Add(new ScriptBundle("~/bundles/jquery").Include( 12 | "~/Scripts/jquery-{version}.js")); 13 | 14 | bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( 15 | "~/Scripts/jquery.validate*")); 16 | 17 | // Use the development version of Modernizr to develop with and learn from. Then, when you're 18 | // ready for production, use the build tool at https://modernizr.com to pick only the tests you need. 19 | bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( 20 | "~/Scripts/modernizr-*")); 21 | 22 | bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( 23 | "~/Scripts/bootstrap.js", 24 | "~/Scripts/respond.js")); 25 | 26 | bundles.Add(new StyleBundle("~/Content/css").Include( 27 | "~/Content/bootstrap.css", 28 | "~/Content/site.css")); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Mvc; 3 | 4 | namespace TsBlog.Frontend 5 | { 6 | public class FilterConfig 7 | { 8 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 9 | { 10 | filters.Add(new HandleErrorAttribute()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace TsBlog.Frontend 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Net.Http.Headers; 3 | using System.Web.Http; 4 | 5 | namespace TsBlog.Frontend 6 | { 7 | public static class WebApiConfig 8 | { 9 | public static void Register(HttpConfiguration config) 10 | { 11 | config.MapHttpAttributeRoutes(); 12 | //config.Formatters.JsonFormatter.SupportedMediaTypes 13 | // .Add(new MediaTypeHeaderValue("text/html")); 14 | 15 | config.Routes.MapHttpRoute( 16 | name: "DefaultApi", 17 | routeTemplate: "api/{controller}/{acton}/{id}", 18 | defaults: new { id = RouteParameter.Optional } 19 | ); 20 | 21 | var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml"); 22 | config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Content/PagedList.css: -------------------------------------------------------------------------------- 1 | .pagination { 2 | display: inline-block; 3 | padding-left: 0; 4 | margin: 20px 0; 5 | border-radius: 4px; 6 | } 7 | 8 | .pagination > li { 9 | display: inline; 10 | } 11 | 12 | .pagination > li > a, 13 | .pagination > li > span { 14 | position: relative; 15 | float: left; 16 | padding: 6px 12px; 17 | margin-left: -1px; 18 | line-height: 1.428571429; 19 | text-decoration: none; 20 | background-color: #ffffff; 21 | border: 1px solid #dddddd; 22 | } 23 | 24 | .pagination > li:first-child > a, 25 | .pagination > li:first-child > span { 26 | margin-left: 0; 27 | border-bottom-left-radius: 4px; 28 | border-top-left-radius: 4px; 29 | } 30 | 31 | .pagination > li:last-child > a, 32 | .pagination > li:last-child > span { 33 | border-top-right-radius: 4px; 34 | border-bottom-right-radius: 4px; 35 | } 36 | 37 | .pagination > li > a:hover, 38 | .pagination > li > span:hover, 39 | .pagination > li > a:focus, 40 | .pagination > li > span:focus { 41 | background-color: #eeeeee; 42 | } 43 | 44 | .pagination > .active > a, 45 | .pagination > .active > span, 46 | .pagination > .active > a:hover, 47 | .pagination > .active > span:hover, 48 | .pagination > .active > a:focus, 49 | .pagination > .active > span:focus { 50 | z-index: 2; 51 | color: #ffffff; 52 | cursor: default; 53 | background-color: #428bca; 54 | border-color: #428bca; 55 | } 56 | 57 | .pagination > .disabled > span, 58 | .pagination > .disabled > a, 59 | .pagination > .disabled > a:hover, 60 | .pagination > .disabled > a:focus { 61 | color: #999999; 62 | cursor: not-allowed; 63 | background-color: #ffffff; 64 | border-color: #dddddd; 65 | } 66 | 67 | .pagination-lg > li > a, 68 | .pagination-lg > li > span { 69 | padding: 10px 16px; 70 | font-size: 18px; 71 | } 72 | 73 | .pagination-lg > li:first-child > a, 74 | .pagination-lg > li:first-child > span { 75 | border-bottom-left-radius: 6px; 76 | border-top-left-radius: 6px; 77 | } 78 | 79 | .pagination-lg > li:last-child > a, 80 | .pagination-lg > li:last-child > span { 81 | border-top-right-radius: 6px; 82 | border-bottom-right-radius: 6px; 83 | } 84 | 85 | .pagination-sm > li > a, 86 | .pagination-sm > li > span { 87 | padding: 5px 10px; 88 | font-size: 12px; 89 | } 90 | 91 | .pagination-sm > li:first-child > a, 92 | .pagination-sm > li:first-child > span { 93 | border-bottom-left-radius: 3px; 94 | border-top-left-radius: 3px; 95 | } 96 | 97 | .pagination-sm > li:last-child > a, 98 | .pagination-sm > li:last-child > span { 99 | border-top-right-radius: 3px; 100 | border-bottom-right-radius: 3px; 101 | } 102 | 103 | .pager { 104 | padding-left: 0; 105 | margin: 20px 0; 106 | text-align: center; 107 | list-style: none; 108 | } 109 | 110 | .pager:before, 111 | .pager:after { 112 | display: table; 113 | content: " "; 114 | } 115 | 116 | .pager:after { 117 | clear: both; 118 | } 119 | 120 | .pager:before, 121 | .pager:after { 122 | display: table; 123 | content: " "; 124 | } 125 | 126 | .pager:after { 127 | clear: both; 128 | } 129 | 130 | .pager li { 131 | display: inline; 132 | } 133 | 134 | .pager li > a, 135 | .pager li > span { 136 | display: inline-block; 137 | padding: 5px 14px; 138 | background-color: #ffffff; 139 | border: 1px solid #dddddd; 140 | border-radius: 15px; 141 | } 142 | 143 | .pager li > a:hover, 144 | .pager li > a:focus { 145 | text-decoration: none; 146 | background-color: #eeeeee; 147 | } 148 | 149 | .pager .next > a, 150 | .pager .next > span { 151 | float: right; 152 | } 153 | 154 | .pager .previous > a, 155 | .pager .previous > span { 156 | float: left; 157 | } 158 | 159 | .pager .disabled > a, 160 | .pager .disabled > a:hover, 161 | .pager .disabled > a:focus, 162 | .pager .disabled > span { 163 | color: #999999; 164 | cursor: not-allowed; 165 | background-color: #ffffff; 166 | } -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Content/Site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Set padding to keep content from hitting the edges */ 7 | .body-content { 8 | padding-left: 15px; 9 | padding-right: 15px; 10 | } 11 | 12 | /* Override the default bootstrap behavior where horizontal description lists 13 | will truncate terms that are too long to fit in the left column 14 | */ 15 | .dl-horizontal dt { 16 | white-space: normal; 17 | } 18 | 19 | /* Set width on the form input elements since they're 100% wide by default */ 20 | input, 21 | select, 22 | textarea { 23 | max-width: 280px; 24 | } 25 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Content/bootstrap-theme.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v3.4.1 (https://getbootstrap.com/) 3 | * Copyright 2011-2019 Twitter, Inc. 4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 5 | */.btn-danger,.btn-default,.btn-info,.btn-primary,.btn-success,.btn-warning{text-shadow:0 -1px 0 rgba(0,0,0,.2);-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 1px rgba(0,0,0,.075)}.btn-danger.active,.btn-danger:active,.btn-default.active,.btn-default:active,.btn-info.active,.btn-info:active,.btn-primary.active,.btn-primary:active,.btn-success.active,.btn-success:active,.btn-warning.active,.btn-warning:active{-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,.125);box-shadow:inset 0 3px 5px rgba(0,0,0,.125)}.btn-danger.disabled,.btn-danger[disabled],.btn-default.disabled,.btn-default[disabled],.btn-info.disabled,.btn-info[disabled],.btn-primary.disabled,.btn-primary[disabled],.btn-success.disabled,.btn-success[disabled],.btn-warning.disabled,.btn-warning[disabled],fieldset[disabled] .btn-danger,fieldset[disabled] .btn-default,fieldset[disabled] .btn-info,fieldset[disabled] .btn-primary,fieldset[disabled] .btn-success,fieldset[disabled] .btn-warning{-webkit-box-shadow:none;box-shadow:none}.btn-danger .badge,.btn-default .badge,.btn-info .badge,.btn-primary .badge,.btn-success .badge,.btn-warning .badge{text-shadow:none}.btn.active,.btn:active{background-image:none}.btn-default{background-image:-webkit-linear-gradient(top,#fff 0,#e0e0e0 100%);background-image:-o-linear-gradient(top,#fff 0,#e0e0e0 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#fff),to(#e0e0e0));background-image:linear-gradient(to bottom,#fff 0,#e0e0e0 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe0e0e0', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#dbdbdb;text-shadow:0 1px 0 #fff;border-color:#ccc}.btn-default:focus,.btn-default:hover{background-color:#e0e0e0;background-position:0 -15px}.btn-default.active,.btn-default:active{background-color:#e0e0e0;border-color:#dbdbdb}.btn-default.disabled,.btn-default.disabled.active,.btn-default.disabled.focus,.btn-default.disabled:active,.btn-default.disabled:focus,.btn-default.disabled:hover,.btn-default[disabled],.btn-default[disabled].active,.btn-default[disabled].focus,.btn-default[disabled]:active,.btn-default[disabled]:focus,.btn-default[disabled]:hover,fieldset[disabled] .btn-default,fieldset[disabled] .btn-default.active,fieldset[disabled] .btn-default.focus,fieldset[disabled] .btn-default:active,fieldset[disabled] .btn-default:focus,fieldset[disabled] .btn-default:hover{background-color:#e0e0e0;background-image:none}.btn-primary{background-image:-webkit-linear-gradient(top,#337ab7 0,#265a88 100%);background-image:-o-linear-gradient(top,#337ab7 0,#265a88 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#265a88));background-image:linear-gradient(to bottom,#337ab7 0,#265a88 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff265a88', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#245580}.btn-primary:focus,.btn-primary:hover{background-color:#265a88;background-position:0 -15px}.btn-primary.active,.btn-primary:active{background-color:#265a88;border-color:#245580}.btn-primary.disabled,.btn-primary.disabled.active,.btn-primary.disabled.focus,.btn-primary.disabled:active,.btn-primary.disabled:focus,.btn-primary.disabled:hover,.btn-primary[disabled],.btn-primary[disabled].active,.btn-primary[disabled].focus,.btn-primary[disabled]:active,.btn-primary[disabled]:focus,.btn-primary[disabled]:hover,fieldset[disabled] .btn-primary,fieldset[disabled] .btn-primary.active,fieldset[disabled] .btn-primary.focus,fieldset[disabled] .btn-primary:active,fieldset[disabled] .btn-primary:focus,fieldset[disabled] .btn-primary:hover{background-color:#265a88;background-image:none}.btn-success{background-image:-webkit-linear-gradient(top,#5cb85c 0,#419641 100%);background-image:-o-linear-gradient(top,#5cb85c 0,#419641 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#5cb85c),to(#419641));background-image:linear-gradient(to bottom,#5cb85c 0,#419641 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5cb85c', endColorstr='#ff419641', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#3e8f3e}.btn-success:focus,.btn-success:hover{background-color:#419641;background-position:0 -15px}.btn-success.active,.btn-success:active{background-color:#419641;border-color:#3e8f3e}.btn-success.disabled,.btn-success.disabled.active,.btn-success.disabled.focus,.btn-success.disabled:active,.btn-success.disabled:focus,.btn-success.disabled:hover,.btn-success[disabled],.btn-success[disabled].active,.btn-success[disabled].focus,.btn-success[disabled]:active,.btn-success[disabled]:focus,.btn-success[disabled]:hover,fieldset[disabled] .btn-success,fieldset[disabled] .btn-success.active,fieldset[disabled] .btn-success.focus,fieldset[disabled] .btn-success:active,fieldset[disabled] .btn-success:focus,fieldset[disabled] .btn-success:hover{background-color:#419641;background-image:none}.btn-info{background-image:-webkit-linear-gradient(top,#5bc0de 0,#2aabd2 100%);background-image:-o-linear-gradient(top,#5bc0de 0,#2aabd2 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#5bc0de),to(#2aabd2));background-image:linear-gradient(to bottom,#5bc0de 0,#2aabd2 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de', endColorstr='#ff2aabd2', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#28a4c9}.btn-info:focus,.btn-info:hover{background-color:#2aabd2;background-position:0 -15px}.btn-info.active,.btn-info:active{background-color:#2aabd2;border-color:#28a4c9}.btn-info.disabled,.btn-info.disabled.active,.btn-info.disabled.focus,.btn-info.disabled:active,.btn-info.disabled:focus,.btn-info.disabled:hover,.btn-info[disabled],.btn-info[disabled].active,.btn-info[disabled].focus,.btn-info[disabled]:active,.btn-info[disabled]:focus,.btn-info[disabled]:hover,fieldset[disabled] .btn-info,fieldset[disabled] .btn-info.active,fieldset[disabled] .btn-info.focus,fieldset[disabled] .btn-info:active,fieldset[disabled] .btn-info:focus,fieldset[disabled] .btn-info:hover{background-color:#2aabd2;background-image:none}.btn-warning{background-image:-webkit-linear-gradient(top,#f0ad4e 0,#eb9316 100%);background-image:-o-linear-gradient(top,#f0ad4e 0,#eb9316 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f0ad4e),to(#eb9316));background-image:linear-gradient(to bottom,#f0ad4e 0,#eb9316 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff0ad4e', endColorstr='#ffeb9316', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#e38d13}.btn-warning:focus,.btn-warning:hover{background-color:#eb9316;background-position:0 -15px}.btn-warning.active,.btn-warning:active{background-color:#eb9316;border-color:#e38d13}.btn-warning.disabled,.btn-warning.disabled.active,.btn-warning.disabled.focus,.btn-warning.disabled:active,.btn-warning.disabled:focus,.btn-warning.disabled:hover,.btn-warning[disabled],.btn-warning[disabled].active,.btn-warning[disabled].focus,.btn-warning[disabled]:active,.btn-warning[disabled]:focus,.btn-warning[disabled]:hover,fieldset[disabled] .btn-warning,fieldset[disabled] .btn-warning.active,fieldset[disabled] .btn-warning.focus,fieldset[disabled] .btn-warning:active,fieldset[disabled] .btn-warning:focus,fieldset[disabled] .btn-warning:hover{background-color:#eb9316;background-image:none}.btn-danger{background-image:-webkit-linear-gradient(top,#d9534f 0,#c12e2a 100%);background-image:-o-linear-gradient(top,#d9534f 0,#c12e2a 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#d9534f),to(#c12e2a));background-image:linear-gradient(to bottom,#d9534f 0,#c12e2a 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9534f', endColorstr='#ffc12e2a', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#b92c28}.btn-danger:focus,.btn-danger:hover{background-color:#c12e2a;background-position:0 -15px}.btn-danger.active,.btn-danger:active{background-color:#c12e2a;border-color:#b92c28}.btn-danger.disabled,.btn-danger.disabled.active,.btn-danger.disabled.focus,.btn-danger.disabled:active,.btn-danger.disabled:focus,.btn-danger.disabled:hover,.btn-danger[disabled],.btn-danger[disabled].active,.btn-danger[disabled].focus,.btn-danger[disabled]:active,.btn-danger[disabled]:focus,.btn-danger[disabled]:hover,fieldset[disabled] .btn-danger,fieldset[disabled] .btn-danger.active,fieldset[disabled] .btn-danger.focus,fieldset[disabled] .btn-danger:active,fieldset[disabled] .btn-danger:focus,fieldset[disabled] .btn-danger:hover{background-color:#c12e2a;background-image:none}.img-thumbnail,.thumbnail{-webkit-box-shadow:0 1px 2px rgba(0,0,0,.075);box-shadow:0 1px 2px rgba(0,0,0,.075)}.dropdown-menu>li>a:focus,.dropdown-menu>li>a:hover{background-image:-webkit-linear-gradient(top,#f5f5f5 0,#e8e8e8 100%);background-image:-o-linear-gradient(top,#f5f5f5 0,#e8e8e8 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f5f5f5),to(#e8e8e8));background-image:linear-gradient(to bottom,#f5f5f5 0,#e8e8e8 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#ffe8e8e8', GradientType=0);background-repeat:repeat-x;background-color:#e8e8e8}.dropdown-menu>.active>a,.dropdown-menu>.active>a:focus,.dropdown-menu>.active>a:hover{background-image:-webkit-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-o-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#2e6da4));background-image:linear-gradient(to bottom,#337ab7 0,#2e6da4 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff2e6da4', GradientType=0);background-repeat:repeat-x;background-color:#2e6da4}.navbar-default{background-image:-webkit-linear-gradient(top,#fff 0,#f8f8f8 100%);background-image:-o-linear-gradient(top,#fff 0,#f8f8f8 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#fff),to(#f8f8f8));background-image:linear-gradient(to bottom,#fff 0,#f8f8f8 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#fff8f8f8', GradientType=0);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);border-radius:4px;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 5px rgba(0,0,0,.075);box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 5px rgba(0,0,0,.075)}.navbar-default .navbar-nav>.active>a,.navbar-default .navbar-nav>.open>a{background-image:-webkit-linear-gradient(top,#dbdbdb 0,#e2e2e2 100%);background-image:-o-linear-gradient(top,#dbdbdb 0,#e2e2e2 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#dbdbdb),to(#e2e2e2));background-image:linear-gradient(to bottom,#dbdbdb 0,#e2e2e2 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdbdbdb', endColorstr='#ffe2e2e2', GradientType=0);background-repeat:repeat-x;-webkit-box-shadow:inset 0 3px 9px rgba(0,0,0,.075);box-shadow:inset 0 3px 9px rgba(0,0,0,.075)}.navbar-brand,.navbar-nav>li>a{text-shadow:0 1px 0 rgba(255,255,255,.25)}.navbar-inverse{background-image:-webkit-linear-gradient(top,#3c3c3c 0,#222 100%);background-image:-o-linear-gradient(top,#3c3c3c 0,#222 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#3c3c3c),to(#222));background-image:linear-gradient(to bottom,#3c3c3c 0,#222 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff3c3c3c', endColorstr='#ff222222', GradientType=0);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);border-radius:4px}.navbar-inverse .navbar-nav>.active>a,.navbar-inverse .navbar-nav>.open>a{background-image:-webkit-linear-gradient(top,#080808 0,#0f0f0f 100%);background-image:-o-linear-gradient(top,#080808 0,#0f0f0f 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#080808),to(#0f0f0f));background-image:linear-gradient(to bottom,#080808 0,#0f0f0f 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff080808', endColorstr='#ff0f0f0f', GradientType=0);background-repeat:repeat-x;-webkit-box-shadow:inset 0 3px 9px rgba(0,0,0,.25);box-shadow:inset 0 3px 9px rgba(0,0,0,.25)}.navbar-inverse .navbar-brand,.navbar-inverse .navbar-nav>li>a{text-shadow:0 -1px 0 rgba(0,0,0,.25)}.navbar-fixed-bottom,.navbar-fixed-top,.navbar-static-top{border-radius:0}@media (max-width:767px){.navbar .navbar-nav .open .dropdown-menu>.active>a,.navbar .navbar-nav .open .dropdown-menu>.active>a:focus,.navbar .navbar-nav .open .dropdown-menu>.active>a:hover{color:#fff;background-image:-webkit-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-o-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#2e6da4));background-image:linear-gradient(to bottom,#337ab7 0,#2e6da4 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff2e6da4', GradientType=0);background-repeat:repeat-x}}.alert{text-shadow:0 1px 0 rgba(255,255,255,.2);-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.25),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 1px 0 rgba(255,255,255,.25),0 1px 2px rgba(0,0,0,.05)}.alert-success{background-image:-webkit-linear-gradient(top,#dff0d8 0,#c8e5bc 100%);background-image:-o-linear-gradient(top,#dff0d8 0,#c8e5bc 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#dff0d8),to(#c8e5bc));background-image:linear-gradient(to bottom,#dff0d8 0,#c8e5bc 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdff0d8', endColorstr='#ffc8e5bc', GradientType=0);background-repeat:repeat-x;border-color:#b2dba1}.alert-info{background-image:-webkit-linear-gradient(top,#d9edf7 0,#b9def0 100%);background-image:-o-linear-gradient(top,#d9edf7 0,#b9def0 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#d9edf7),to(#b9def0));background-image:linear-gradient(to bottom,#d9edf7 0,#b9def0 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9edf7', endColorstr='#ffb9def0', GradientType=0);background-repeat:repeat-x;border-color:#9acfea}.alert-warning{background-image:-webkit-linear-gradient(top,#fcf8e3 0,#f8efc0 100%);background-image:-o-linear-gradient(top,#fcf8e3 0,#f8efc0 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#fcf8e3),to(#f8efc0));background-image:linear-gradient(to bottom,#fcf8e3 0,#f8efc0 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffcf8e3', endColorstr='#fff8efc0', GradientType=0);background-repeat:repeat-x;border-color:#f5e79e}.alert-danger{background-image:-webkit-linear-gradient(top,#f2dede 0,#e7c3c3 100%);background-image:-o-linear-gradient(top,#f2dede 0,#e7c3c3 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f2dede),to(#e7c3c3));background-image:linear-gradient(to bottom,#f2dede 0,#e7c3c3 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2dede', endColorstr='#ffe7c3c3', GradientType=0);background-repeat:repeat-x;border-color:#dca7a7}.progress{background-image:-webkit-linear-gradient(top,#ebebeb 0,#f5f5f5 100%);background-image:-o-linear-gradient(top,#ebebeb 0,#f5f5f5 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#ebebeb),to(#f5f5f5));background-image:linear-gradient(to bottom,#ebebeb 0,#f5f5f5 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffebebeb', endColorstr='#fff5f5f5', GradientType=0);background-repeat:repeat-x}.progress-bar{background-image:-webkit-linear-gradient(top,#337ab7 0,#286090 100%);background-image:-o-linear-gradient(top,#337ab7 0,#286090 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#286090));background-image:linear-gradient(to bottom,#337ab7 0,#286090 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff286090', GradientType=0);background-repeat:repeat-x}.progress-bar-success{background-image:-webkit-linear-gradient(top,#5cb85c 0,#449d44 100%);background-image:-o-linear-gradient(top,#5cb85c 0,#449d44 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#5cb85c),to(#449d44));background-image:linear-gradient(to bottom,#5cb85c 0,#449d44 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5cb85c', endColorstr='#ff449d44', GradientType=0);background-repeat:repeat-x}.progress-bar-info{background-image:-webkit-linear-gradient(top,#5bc0de 0,#31b0d5 100%);background-image:-o-linear-gradient(top,#5bc0de 0,#31b0d5 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#5bc0de),to(#31b0d5));background-image:linear-gradient(to bottom,#5bc0de 0,#31b0d5 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de', endColorstr='#ff31b0d5', GradientType=0);background-repeat:repeat-x}.progress-bar-warning{background-image:-webkit-linear-gradient(top,#f0ad4e 0,#ec971f 100%);background-image:-o-linear-gradient(top,#f0ad4e 0,#ec971f 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f0ad4e),to(#ec971f));background-image:linear-gradient(to bottom,#f0ad4e 0,#ec971f 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff0ad4e', endColorstr='#ffec971f', GradientType=0);background-repeat:repeat-x}.progress-bar-danger{background-image:-webkit-linear-gradient(top,#d9534f 0,#c9302c 100%);background-image:-o-linear-gradient(top,#d9534f 0,#c9302c 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#d9534f),to(#c9302c));background-image:linear-gradient(to bottom,#d9534f 0,#c9302c 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9534f', endColorstr='#ffc9302c', GradientType=0);background-repeat:repeat-x}.progress-bar-striped{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent)}.list-group{border-radius:4px;-webkit-box-shadow:0 1px 2px rgba(0,0,0,.075);box-shadow:0 1px 2px rgba(0,0,0,.075)}.list-group-item.active,.list-group-item.active:focus,.list-group-item.active:hover{text-shadow:0 -1px 0 #286090;background-image:-webkit-linear-gradient(top,#337ab7 0,#2b669a 100%);background-image:-o-linear-gradient(top,#337ab7 0,#2b669a 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#2b669a));background-image:linear-gradient(to bottom,#337ab7 0,#2b669a 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff2b669a', GradientType=0);background-repeat:repeat-x;border-color:#2b669a}.list-group-item.active .badge,.list-group-item.active:focus .badge,.list-group-item.active:hover .badge{text-shadow:none}.panel{-webkit-box-shadow:0 1px 2px rgba(0,0,0,.05);box-shadow:0 1px 2px rgba(0,0,0,.05)}.panel-default>.panel-heading{background-image:-webkit-linear-gradient(top,#f5f5f5 0,#e8e8e8 100%);background-image:-o-linear-gradient(top,#f5f5f5 0,#e8e8e8 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f5f5f5),to(#e8e8e8));background-image:linear-gradient(to bottom,#f5f5f5 0,#e8e8e8 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#ffe8e8e8', GradientType=0);background-repeat:repeat-x}.panel-primary>.panel-heading{background-image:-webkit-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-o-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#2e6da4));background-image:linear-gradient(to bottom,#337ab7 0,#2e6da4 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff2e6da4', GradientType=0);background-repeat:repeat-x}.panel-success>.panel-heading{background-image:-webkit-linear-gradient(top,#dff0d8 0,#d0e9c6 100%);background-image:-o-linear-gradient(top,#dff0d8 0,#d0e9c6 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#dff0d8),to(#d0e9c6));background-image:linear-gradient(to bottom,#dff0d8 0,#d0e9c6 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdff0d8', endColorstr='#ffd0e9c6', GradientType=0);background-repeat:repeat-x}.panel-info>.panel-heading{background-image:-webkit-linear-gradient(top,#d9edf7 0,#c4e3f3 100%);background-image:-o-linear-gradient(top,#d9edf7 0,#c4e3f3 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#d9edf7),to(#c4e3f3));background-image:linear-gradient(to bottom,#d9edf7 0,#c4e3f3 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9edf7', endColorstr='#ffc4e3f3', GradientType=0);background-repeat:repeat-x}.panel-warning>.panel-heading{background-image:-webkit-linear-gradient(top,#fcf8e3 0,#faf2cc 100%);background-image:-o-linear-gradient(top,#fcf8e3 0,#faf2cc 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#fcf8e3),to(#faf2cc));background-image:linear-gradient(to bottom,#fcf8e3 0,#faf2cc 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffcf8e3', endColorstr='#fffaf2cc', GradientType=0);background-repeat:repeat-x}.panel-danger>.panel-heading{background-image:-webkit-linear-gradient(top,#f2dede 0,#ebcccc 100%);background-image:-o-linear-gradient(top,#f2dede 0,#ebcccc 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f2dede),to(#ebcccc));background-image:linear-gradient(to bottom,#f2dede 0,#ebcccc 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2dede', endColorstr='#ffebcccc', GradientType=0);background-repeat:repeat-x}.well{background-image:-webkit-linear-gradient(top,#e8e8e8 0,#f5f5f5 100%);background-image:-o-linear-gradient(top,#e8e8e8 0,#f5f5f5 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#e8e8e8),to(#f5f5f5));background-image:linear-gradient(to bottom,#e8e8e8 0,#f5f5f5 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffe8e8e8', endColorstr='#fff5f5f5', GradientType=0);background-repeat:repeat-x;border-color:#dcdcdc;-webkit-box-shadow:inset 0 1px 3px rgba(0,0,0,.05),0 1px 0 rgba(255,255,255,.1);box-shadow:inset 0 1px 3px rgba(0,0,0,.05),0 1px 0 rgba(255,255,255,.1)} 6 | /*# sourceMappingURL=bootstrap-theme.min.css.map */ -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Controllers/AccountController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Web.Mvc; 3 | using TsBlog.Core.Security; 4 | using TsBlog.Domain.Entities; 5 | using TsBlog.Services; 6 | using TsBlog.ViewModel.User; 7 | 8 | namespace TsBlog.Frontend.Controllers 9 | { 10 | /// 11 | /// 用户中心控制器 12 | /// 13 | public class AccountController : Controller 14 | { 15 | /// 16 | /// 用户服务接口 17 | /// 18 | private readonly IUserService _userService; 19 | 20 | public AccountController(IUserService userService) 21 | { 22 | _userService = userService; 23 | } 24 | 25 | /// 26 | /// 登录页面 27 | /// 28 | /// 29 | public ActionResult Login() 30 | { 31 | return View(); 32 | } 33 | 34 | /// 35 | /// 提交登录请求 36 | /// 37 | /// 38 | /// 39 | [HttpPost, ValidateAntiForgeryToken, AllowAnonymous] 40 | public ActionResult Login(LoginViewModel model) 41 | { 42 | //如果视图模型中的属性没有验证通过,则返回到登录页面,要求用户重新填写 43 | if (!ModelState.IsValid) 44 | { 45 | return View(model); 46 | } 47 | 48 | //根据用户登录名查询指定用户实体 49 | var user = _userService.FindByLoginName(model.UserName.Trim()); 50 | 51 | //如果用户不存在,则携带错误消息并返回登录页面 52 | if (user == null) 53 | { 54 | ModelState.AddModelError("error_message", "用户不存在"); 55 | return View(model); 56 | } 57 | 58 | //如果密码不匹配,则携带错误消息并返回登录页面 59 | if (user.Password != Encryptor.Md5Hash(model.Password.Trim())) 60 | { 61 | ModelState.AddModelError("error_message", "密码错误,请重新登录"); 62 | return View(model); 63 | } 64 | 65 | //将用户实体保存到Session中 66 | Session["user_account"] = user; 67 | //跳转到首页 68 | return RedirectToAction("index", "home"); 69 | } 70 | 71 | /// 72 | /// 注册页面 73 | /// 74 | /// 75 | public ActionResult Register() 76 | { 77 | return View(); 78 | } 79 | 80 | /// 81 | /// 提交注册请求 82 | /// 83 | /// 84 | /// 85 | [HttpPost, ValidateAntiForgeryToken, AllowAnonymous] 86 | public ActionResult Register(RegisterViewModel model) 87 | { 88 | //如果视图模型中的属性没有验证通过,则返回到注册页面,要求用户重新填写 89 | if (!ModelState.IsValid) 90 | { 91 | return View(model); 92 | } 93 | 94 | //创建一个用户实体 95 | var user = new User 96 | { 97 | LoginName = model.UserName, 98 | Password = Encryptor.Md5Hash(model.Password.Trim()), 99 | CreatedOn = DateTime.Now 100 | //由于是示例教程,所以其他字段不作填充了 101 | }; 102 | //将用户实体对象写入数据库中 103 | var ret = _userService.Insert(user); 104 | 105 | if (ret <= 0) 106 | { 107 | //如果注册失败,则携带错误消息并返回注册页面 108 | ModelState.AddModelError("error_message", "注册失败"); 109 | return View(model); 110 | 111 | } 112 | //如果注册成功,则跳转到登录页面 113 | return RedirectToAction("login"); 114 | } 115 | 116 | public ActionResult Logout() 117 | { 118 | Session.Clear(); 119 | Session.Abandon(); 120 | return RedirectToAction("index", "home"); 121 | } 122 | } 123 | } -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Controllers/Api/UserController.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | using TsBlog.Services; 3 | 4 | namespace TsBlog.Frontend.Controllers.Api 5 | { 6 | public class UserController : ApiController 7 | { 8 | private readonly IUserService _userService; 9 | 10 | public UserController(IUserService userService) 11 | { 12 | _userService = userService; 13 | } 14 | 15 | [HttpGet] 16 | public IHttpActionResult GetUserList() 17 | { 18 | var users = _userService.FindAll(); 19 | return Ok(users); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using PagedList; 2 | using System.Linq; 3 | using System.Web.Mvc; 4 | using TsBlog.AutoMapperConfig; 5 | using TsBlog.Frontend.Extensions; 6 | using TsBlog.Services; 7 | using TsBlog.ViewModel.Post; 8 | 9 | namespace TsBlog.Frontend.Controllers 10 | { 11 | public class HomeController : Controller 12 | { 13 | /// 14 | /// 文章服务接口 15 | /// 16 | private readonly IPostService _postService; 17 | public HomeController(IPostService postService) 18 | { 19 | _postService = postService; 20 | } 21 | /// 22 | /// 首页 23 | /// 24 | /// 25 | public ActionResult Index(int? page) 26 | { 27 | //var list = _postService.FindHomePagePosts(); 28 | //读取分页数据,返回IPagedList 29 | page = page ?? 1; 30 | var list = _postService.FindPagedList(x => !x.IsDeleted && x.AllowShow, pageIndex: (int)page, pageSize: 10); 31 | var model = list.Select(x => x.ToModel().FormatPostViewModel()); 32 | ViewBag.Pagination = new StaticPagedList(model, list.PageIndex, list.PageSize, list.TotalCount); 33 | return View(model); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Controllers/PostController.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | using TsBlog.AutoMapperConfig; 3 | using TsBlog.Services; 4 | 5 | namespace TsBlog.Frontend.Controllers 6 | { 7 | public class PostController : Controller 8 | { 9 | /// 10 | /// 文章服务接口 11 | /// 12 | private readonly IPostService _postService; 13 | 14 | public PostController(IPostService postService) 15 | { 16 | _postService = postService; 17 | } 18 | 19 | /// 20 | /// 文章详情 21 | /// 22 | /// 文章ID 23 | /// 24 | public ActionResult Details(int id) 25 | { 26 | var post = _postService.FindById(id); 27 | var model = post.ToModel(); 28 | return View(model); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Extensions/PostExtension.cs: -------------------------------------------------------------------------------- 1 | using TsBlog.Core; 2 | using TsBlog.ViewModel.Post; 3 | 4 | namespace TsBlog.Frontend.Extensions 5 | { 6 | public static class PostExtension 7 | { 8 | /// 9 | /// 格式化文章的视图实体 10 | /// 11 | /// 文章视图实体类 12 | /// 13 | public static PostViewModel FormatPostViewModel(this PostViewModel model) 14 | { 15 | if (model == null) 16 | { 17 | return null; 18 | } 19 | 20 | model.Summary = model.Content 21 | .CleanHtml() //去掉所有HTML标签 22 | .TruncateString(200, TruncateOptions.FinishWord | TruncateOptions.AllowLastWordToGoOverMaxLength); //截断指定长度作为文章摘要 23 | return model; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="TsBlog.Frontend.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Features.ResolveAnything; 3 | using Autofac.Integration.Mvc; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Web.Compilation; 7 | using System.Web.Http; 8 | using System.Web.Mvc; 9 | using System.Web.Routing; 10 | using Autofac.Integration.WebApi; 11 | using TsBlog.AutoMapperConfig; 12 | using TsBlog.Repositories; 13 | 14 | namespace TsBlog.Frontend 15 | { 16 | public class MvcApplication : System.Web.HttpApplication 17 | { 18 | protected void Application_Start() 19 | { 20 | AreaRegistration.RegisterAllAreas(); 21 | GlobalConfiguration.Configure(WebApiConfig.Register); 22 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 23 | RouteConfig.RegisterRoutes(RouteTable.Routes); 24 | 25 | //BundleConfig.RegisterBundles(BundleTable.Bundles); 26 | 27 | AutofacRegister(); 28 | 29 | AutoMapperRegister(); 30 | } 31 | 32 | private void AutofacRegister() 33 | { 34 | var builder = new ContainerBuilder(); 35 | var config = GlobalConfiguration.Configuration; 36 | 37 | builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); 38 | 39 | //注册MvcApplication程序集中所有的控制器 40 | builder.RegisterControllers(typeof(MvcApplication).Assembly); 41 | 42 | //注册仓储层服务 43 | //builder.RegisterType().As(); 44 | //注册基于接口约束的实体 45 | //var assembly = AppDomain.CurrentDomain.GetAssemblies(); 46 | 47 | var assemblies = BuildManager.GetReferencedAssemblies().Cast() 48 | .Where( 49 | assembly => 50 | assembly.GetTypes().FirstOrDefault(type => type.GetInterfaces().Contains(typeof(IDependency))) != 51 | null 52 | ); 53 | 54 | builder.RegisterAssemblyTypes(assemblies.ToArray()) 55 | .AsImplementedInterfaces() 56 | .InstancePerDependency(); 57 | 58 | //注册过滤器 59 | builder.RegisterFilterProvider(); 60 | builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource()); 61 | 62 | 63 | 64 | // OPTIONAL: Register the Autofac filter provider. 65 | builder.RegisterWebApiFilterProvider(config); 66 | 67 | // OPTIONAL: Register the Autofac model binder provider. 68 | builder.RegisterWebApiModelBinderProvider(); 69 | 70 | // Set the dependency resolver to be Autofac. 71 | var container = builder.Build(); 72 | config.DependencyResolver = new AutofacWebApiDependencyResolver(container); 73 | 74 | //设置依赖注入解析器 75 | DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); 76 | 77 | } 78 | 79 | /// 80 | /// AutoMapper的配置初始化 81 | /// 82 | private void AutoMapperRegister() 83 | { 84 | new AutoMapperStartupTask().Execute(); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TsBlog.Frontend")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TsBlog.Frontend")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e8f91a1d-b81d-4eb7-84b8-7280aa29d05e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/TsBlog.Frontend.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | 9 | 10 | 2.0 11 | {5CC238A7-ED1E-475D-B8F0-43E94CF5A24E} 12 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 13 | Library 14 | Properties 15 | TsBlog.Frontend 16 | TsBlog.Frontend 17 | v4.6.2 18 | false 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 3.5 29 | 30 | 31 | true 32 | full 33 | false 34 | bin\ 35 | DEBUG;TRACE 36 | prompt 37 | 4 38 | 39 | 40 | true 41 | pdbonly 42 | true 43 | bin\ 44 | TRACE 45 | prompt 46 | 4 47 | 48 | 49 | 50 | ..\..\..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll 51 | 52 | 53 | ..\..\..\packages\Autofac.4.9.3\lib\net45\Autofac.dll 54 | 55 | 56 | ..\..\..\packages\Autofac.Mvc5.4.0.2\lib\net45\Autofac.Integration.Mvc.dll 57 | 58 | 59 | ..\..\..\packages\Autofac.WebApi2.4.2.1\lib\net45\Autofac.Integration.WebApi.dll 60 | 61 | 62 | 63 | ..\..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll 64 | 65 | 66 | ..\..\..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll 67 | 68 | 69 | ..\..\..\packages\PagedList.1.17.0.0\lib\net40\PagedList.dll 70 | 71 | 72 | ..\..\..\packages\PagedList.Mvc.4.5.0.0\lib\net40\PagedList.Mvc.dll 73 | 74 | 75 | 76 | 77 | 78 | 79 | ..\..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll 80 | 81 | 82 | 83 | 84 | ..\..\..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll 85 | 86 | 87 | ..\..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll 88 | 89 | 90 | ..\..\..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll 91 | 92 | 93 | ..\..\..\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll 94 | 95 | 96 | ..\..\..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll 97 | 98 | 99 | ..\..\..\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll 100 | 101 | 102 | 103 | ..\..\..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll 104 | 105 | 106 | ..\..\..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll 107 | 108 | 109 | ..\..\..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll 110 | 111 | 112 | ..\..\..\packages\WebGrease.1.6.0\lib\WebGrease.dll 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | Global.asax 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | Web.config 160 | 161 | 162 | Web.config 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | {2866A0EC-8F66-4CB5-BC70-568EC3397EFB} 186 | TsBlog.AutoMapperConfig 187 | 188 | 189 | {0a171809-bf68-4ad5-a3d2-d4638149e95c} 190 | TsBlog.Core 191 | 192 | 193 | {E415AB82-2704-4984-9576-A9BC8F3DED30} 194 | TsBlog.Domain 195 | 196 | 197 | {0B3D004F-250E-439F-B0AB-9268C33D3DEB} 198 | TsBlog.Repositories 199 | 200 | 201 | {6bcfd47c-b93a-4e6c-8e27-3ef8ccb49d74} 202 | TsBlog.Services 203 | 204 | 205 | {459E7C49-DE30-4FFD-8912-FF9ED8069DEB} 206 | TsBlog.ViewModel 207 | 208 | 209 | 210 | 211 | 212 | 213 | 10.0 214 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | True 228 | True 229 | 54739 230 | / 231 | http://localhost:54739/ 232 | False 233 | False 234 | 235 | 236 | False 237 | 238 | 239 | 240 | 241 | 247 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Views/Account/login.cshtml: -------------------------------------------------------------------------------- 1 | @model TsBlog.ViewModel.User.LoginViewModel 2 | @{ 3 | Layout = null; 4 | } 5 | 6 | 7 | 8 | 9 | 用户登录 10 | 32 | 33 | 34 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Views/Account/register.cshtml: -------------------------------------------------------------------------------- 1 | @model TsBlog.ViewModel.User.RegisterViewModel 2 | @{ 3 | Layout = null; 4 | } 5 | 6 | 7 | 8 | 9 | 用户注册 10 | 31 | 32 | 33 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @using PagedList 2 | @using PagedList.Mvc 3 | @model IEnumerable 4 | @{ 5 | Layout = "~/Views/Shared/_Layout.cshtml"; 6 | ViewBag.Title = "ASP.NET MVC 5 系列文章教程--首页"; 7 | } 8 |
9 |

小伙伴,你好

10 |

欢迎来到 Rector 的ASP.NET MVC 5 系列文章教程。在这里,Rector将和你一起一步一步创建一个集成Repository+Autofac+Automapper+SqlSugar的WEB应用程序。

11 |

你准备好了吗?

12 |

......

13 |

让我们开始ASP.NET MVC 5 应用程序的探索之旅吧!!!

14 |
15 | 文章列表(@(Model.Count())篇) 16 |
    17 | @foreach (var p in Model) 18 | { 19 |
  • 20 |

    @p.Title

    21 |

    @p.Summary ... 阅读全文

    22 |
  • 23 | } 24 |
25 | @Html.PagedListPager((IPagedList)ViewBag.Pagination, page => Url.Action("index", new { page }), new PagedListRenderOptions 26 | { 27 | LinkToFirstPageFormat = "首页", 28 | LinkToPreviousPageFormat = "上一页", 29 | LinkToNextPageFormat = "下一页", 30 | LinkToLastPageFormat = "末页", 31 | DisplayLinkToFirstPage = PagedListDisplayMode.IfNeeded, 32 | DisplayLinkToLastPage = PagedListDisplayMode.Never, 33 | DisplayEllipsesWhenNotShowingAllPageNumbers = true, 34 | MaximumPageNumbersToDisplay = 5 35 | }) -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Views/Home/Post.cshtml: -------------------------------------------------------------------------------- 1 | @model TsBlog.ViewModel.Post.PostViewModel 2 | @{ 3 | Layout = "~/Views/Shared/_Layout.cshtml"; 4 | ViewBag.Title = Model.Title; 5 | } 6 |
7 |

Post id:@Model.Id

8 |

Post Title:@Model.Title

9 |

Post PublishedAt:@Model.PublishedAt

10 |

Post IsDeleted:@Model.IsDeleted

11 |
-------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Views/Post/Details.cshtml: -------------------------------------------------------------------------------- 1 | @model TsBlog.ViewModel.Post.PostViewModel 2 | @{ 3 | Layout = null; 4 | } 5 | 6 | 7 | 8 | 9 | 10 | @(Model.Title) | TSBLOG 11 | 12 | 13 | 14 | 15 | 56 |
57 |

@Model.Title

58 |
59 | @Html.Raw(Model.Content) 60 |
61 |
62 |
63 |
64 | 版权所有 © @(DateTime.Now.Year) 65 |
66 |
67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Error 6 | 7 | 8 |
9 |

Error.

10 |

An error occurred while processing your request.

11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | @ViewBag.Title - TSBLOG 7 | 8 | 9 | 10 | 11 | @Html.Partial("_NavBar") 12 |
13 | @RenderBody() 14 |
15 |
16 |
17 | 版权所有 © @(DateTime.Now.Year) 18 |
19 |
20 | 21 | 22 | @RenderSection("scripts", required: false) 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Views/Shared/_NavBar.cshtml: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Views/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Web.Debug.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Web.Release.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lampo1024/TsBlog/93bfe0416dfa2d3032f5c7c3362408a283d05ae7/src/Presentation/TsBlog.Frontend/favicon.ico -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lampo1024/TsBlog/93bfe0416dfa2d3032f5c7c3362408a283d05ae7/src/Presentation/TsBlog.Frontend/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lampo1024/TsBlog/93bfe0416dfa2d3032f5c7c3362408a283d05ae7/src/Presentation/TsBlog.Frontend/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lampo1024/TsBlog/93bfe0416dfa2d3032f5c7c3362408a283d05ae7/src/Presentation/TsBlog.Frontend/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lampo1024/TsBlog/93bfe0416dfa2d3032f5c7c3362408a283d05ae7/src/Presentation/TsBlog.Frontend/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Hello world. 9 | 10 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/Presentation/TsBlog.Frontend/resources/css/site.css: -------------------------------------------------------------------------------- 1 | html, body, div, span, applet, object, iframe, 2 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 3 | a, abbr, acronym, address, big, cite, code, 4 | del, dfn, em, font, img, ins, kbd, q, s, samp, 5 | small, strike, strong, sub, sup, tt, var, 6 | b, u, i, center, 7 | dl, dt, dd, ol, ul, li, 8 | fieldset, form, label, legend, 9 | table, caption, tbody, tfoot, thead, tr, th, td { border: 0; margin: 0; padding: 0; } 10 | 11 | body { color: #333; font-size: 14px; font-family: -apple-system,'helvetica neue', helvetica,"Helvetica Neue",Helvetica,Arial,"PingFang SC","Hiragino Sans GB","WenQuanYi Micro Hei","Microsoft Yahei",sans-serif; line-height: 22px; width: 100%; height: 100%; } 12 | h1, h2, h3, h4, h5, h6 { clear: both; font-weight: normal; } 13 | ol, ul { list-style: none; } 14 | blockquote { quotes: none; border-left: 5px solid #eee; font-size: 14px; margin: 10px 0; padding: 10px 20px; } 15 | blockquote:before, blockquote:after { content: ''; content: none; } 16 | 17 | a { color: #4484ce; } 18 | 19 | /*bootstrap override*/ 20 | .btn { border-radius: 2px !important; } 21 | .btn-primary { background-color: #4484CE !important; } 22 | .btn-primary:hover { background-color: #3A77BE !important; } 23 | 24 | .navbar-nav a { color: #333 !important; } 25 | .navbar-nav > .active > a, .navbar-nav > .active > a:focus, .navbar-nav > .active > a:hover, .navbar-nav a:hover { border-radius: 2px; background-color: #e7e7e7 !important; } 26 | /*site begin*/ 27 | .ts-navbar .navbar-nav { height: 50px; vertical-align: middle; line-height: 50px; } 28 | .ts-navbar .navbar-nav li { vertical-align: middle; line-height: 50px; float: none; display: inline-block; } 29 | .ts-navbar .dropdown li { display: block; } 30 | .ts-navbar .navbar-nav li a { padding: 8px 15px; } 31 | .navbar-brand { height: auto; } 32 | a.nav-btn-login { color: #fff !important; } 33 | a.nav-btn-login:hover { background-color: #3A77BE !important; color: #fff !important; } 34 | .navbar-profile { margin-right: 0; } 35 | /*home begin*/ 36 | .jumbotron h1 { margin-bottom: 15px; } 37 | .jumbotron p { line-height: 28px; } 38 | .post-title { display: block; font-size: 16px; font-weight: 600; border-bottom: 2px solid #e7e7e7; padding-bottom: 8px; } 39 | .post-item-box { margin-bottom: 15px; } 40 | .post-item-box li { margin-top: 15px; margin-bottom: 15px; padding-top: 10px; padding-bottom: 10px; } 41 | .post-item-box li h2 { font-size: 16px; font-weight: 500; margin-bottom: 10px; } 42 | .post-item-summary { color: #555; } 43 | .footer-box { padding: 15px; margin-top: 15px; border-top: 1px solid #e7e7e7; } 44 | 45 | 46 | /*post details*/ 47 | 48 | .article-content { padding-top: 15px; padding-bottom: 15px; } 49 | .article-content p { margin-top: 20px; margin-bottom: 20px; } 50 | .article-fixed p { margin-top: 0; margin-bottom: 5px; } 51 | .article-content h1, .article-content h2, .article-content h3, .article-content h4, .article-content h5, .article-content h6 { margin: 15px 0 10px; } 52 | .article-content h1, .article-content h2 { border-bottom: 1px solid #eee; padding-bottom: 10px; } 53 | .article-content h2 { font-size: 1.75em; line-height: 1.2 } 54 | .article-content h3 { font-size: 1.5em; line-height: 1.2 } 55 | .article-content blockquote { background: #f6f6f6 none repeat scroll 0 0; border-left: 2px solid #009a61; color: #555; font-size: 1em; } 56 | .cloud-tags .cloud-tag-item { border: 1px solid #efefef; background-color: #f7f7f7; padding: 5px 10px; } 57 | .cloud-tags .cloud-tag-item, .side-bar-article-list, .article-content { word-break: break-all; word-wrap: break-word; white-space: normal; } 58 | .article-content pre { background-attachment: scroll; background-clip: border-box; background-color: #f6f6f6; border: medium none; line-height: 1.45; max-height: 35em; overflow: auto; padding: 1em; position: relative; margin-bottom: 15px; margin-top: 15px; } 59 | .article-content ul li { padding-left: 15px; list-style: inside; } 60 | .article-content ul li { padding-left: 15px; list-style: inside; } 61 | .article-content ul, .article-content ol { margin-left: 3em; padding-left: 0; } 62 | .article-content ul li, .article-content ol li { margin: .3em 0; } 63 | --------------------------------------------------------------------------------