├── .gitattributes
├── .gitignore
├── CommentingSystem.sln
├── README.md
└── src
└── CommentingSystem.Web
├── CommentingSystem.Web.csproj
├── Configurations
├── ControllersWithViewsConfig.cs
└── DbContextConfig.cs
├── Controllers
└── HomeController.cs
├── DTOs
└── CreateCommentDto.cs
├── Data
└── CommentingSystemDbContext.cs
├── Domain
└── Comment.cs
├── Migrations
├── 20220415125505_Initial.Designer.cs
├── 20220415125505_Initial.cs
└── CommentingSystemDbContextModelSnapshot.cs
├── Program.cs
├── Properties
└── launchSettings.json
├── Views
├── Home
│ ├── Index.cshtml
│ ├── _CommentsPartialView.cshtml
│ ├── _CreateComment.cshtml
│ ├── _CreateReplyModal.cshtml
│ └── _DeleteCommentModal.cshtml
├── Shared
│ └── _Layout.cshtml
├── _ViewImports.cshtml
└── _ViewStart.cshtml
├── appsettings.Development.json
├── appsettings.json
└── wwwroot
└── img
└── Capture.png
/.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 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | [Aa][Rr][Mm]/
24 | [Aa][Rr][Mm]64/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 |
30 | # Visual Studio 2015/2017 cache/options directory
31 | .vs/
32 | # Uncomment if you have tasks that create the project's static files in wwwroot
33 | #wwwroot/
34 |
35 | # Visual Studio 2017 auto generated files
36 | Generated\ Files/
37 |
38 | # MSTest test Results
39 | [Tt]est[Rr]esult*/
40 | [Bb]uild[Ll]og.*
41 |
42 | # NUNIT
43 | *.VisualState.xml
44 | TestResult.xml
45 |
46 | # Build Results of an ATL Project
47 | [Dd]ebugPS/
48 | [Rr]eleasePS/
49 | dlldata.c
50 |
51 | # Benchmark Results
52 | BenchmarkDotNet.Artifacts/
53 |
54 | # .NET Core
55 | project.lock.json
56 | project.fragment.lock.json
57 | artifacts/
58 |
59 | # StyleCop
60 | StyleCopReport.xml
61 |
62 | # Files built by Visual Studio
63 | *_i.c
64 | *_p.c
65 | *_h.h
66 | *.ilk
67 | *.meta
68 | *.obj
69 | *.iobj
70 | *.pch
71 | *.pdb
72 | *.ipdb
73 | *.pgc
74 | *.pgd
75 | *.rsp
76 | *.sbr
77 | *.tlb
78 | *.tli
79 | *.tlh
80 | *.tmp
81 | *.tmp_proj
82 | *_wpftmp.csproj
83 | *.log
84 | *.vspscc
85 | *.vssscc
86 | .builds
87 | *.pidb
88 | *.svclog
89 | *.scc
90 |
91 | # Chutzpah Test files
92 | _Chutzpah*
93 |
94 | # Visual C++ cache files
95 | ipch/
96 | *.aps
97 | *.ncb
98 | *.opendb
99 | *.opensdf
100 | *.sdf
101 | *.cachefile
102 | *.VC.db
103 | *.VC.VC.opendb
104 |
105 | # Visual Studio profiler
106 | *.psess
107 | *.vsp
108 | *.vspx
109 | *.sap
110 |
111 | # Visual Studio Trace Files
112 | *.e2e
113 |
114 | # TFS 2012 Local Workspace
115 | $tf/
116 |
117 | # Guidance Automation Toolkit
118 | *.gpState
119 |
120 | # ReSharper is a .NET coding add-in
121 | _ReSharper*/
122 | *.[Rr]e[Ss]harper
123 | *.DotSettings.user
124 |
125 | # JustCode is a .NET coding add-in
126 | .JustCode
127 |
128 | # TeamCity is a build add-in
129 | _TeamCity*
130 |
131 | # DotCover is a Code Coverage Tool
132 | *.dotCover
133 |
134 | # AxoCover is a Code Coverage Tool
135 | .axoCover/*
136 | !.axoCover/settings.json
137 |
138 | # Visual Studio code coverage results
139 | *.coverage
140 | *.coveragexml
141 |
142 | # NCrunch
143 | _NCrunch_*
144 | .*crunch*.local.xml
145 | nCrunchTemp_*
146 |
147 | # MightyMoose
148 | *.mm.*
149 | AutoTest.Net/
150 |
151 | # Web workbench (sass)
152 | .sass-cache/
153 |
154 | # Installshield output folder
155 | [Ee]xpress/
156 |
157 | # DocProject is a documentation generator add-in
158 | DocProject/buildhelp/
159 | DocProject/Help/*.HxT
160 | DocProject/Help/*.HxC
161 | DocProject/Help/*.hhc
162 | DocProject/Help/*.hhk
163 | DocProject/Help/*.hhp
164 | DocProject/Help/Html2
165 | DocProject/Help/html
166 |
167 | # Click-Once directory
168 | publish/
169 |
170 | # Publish Web Output
171 | *.[Pp]ublish.xml
172 | *.azurePubxml
173 | # Note: Comment the next line if you want to checkin your web deploy settings,
174 | # but database connection strings (with potential passwords) will be unencrypted
175 | *.pubxml
176 | *.publishproj
177 |
178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
179 | # checkin your Azure Web App publish settings, but sensitive information contained
180 | # in these scripts will be unencrypted
181 | PublishScripts/
182 |
183 | # NuGet Packages
184 | *.nupkg
185 | # The packages folder can be ignored because of Package Restore
186 | **/[Pp]ackages/*
187 | # except build/, which is used as an MSBuild target.
188 | !**/[Pp]ackages/build/
189 | # Uncomment if necessary however generally it will be regenerated when needed
190 | #!**/[Pp]ackages/repositories.config
191 | # NuGet v3's project.json files produces more ignorable files
192 | *.nuget.props
193 | *.nuget.targets
194 |
195 | # Microsoft Azure Build Output
196 | csx/
197 | *.build.csdef
198 |
199 | # Microsoft Azure Emulator
200 | ecf/
201 | rcf/
202 |
203 | # Windows Store app package directories and files
204 | AppPackages/
205 | BundleArtifacts/
206 | Package.StoreAssociation.xml
207 | _pkginfo.txt
208 | *.appx
209 |
210 | # Visual Studio cache files
211 | # files ending in .cache can be ignored
212 | *.[Cc]ache
213 | # but keep track of directories ending in .cache
214 | !?*.[Cc]ache/
215 |
216 | # Others
217 | ClientBin/
218 | ~$*
219 | *~
220 | *.dbmdl
221 | *.dbproj.schemaview
222 | *.jfm
223 | *.pfx
224 | *.publishsettings
225 | orleans.codegen.cs
226 |
227 | # Including strong name files can present a security risk
228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
229 | #*.snk
230 |
231 | # Since there are multiple workflows, uncomment next line to ignore bower_components
232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
233 | #bower_components/
234 |
235 | # RIA/Silverlight projects
236 | Generated_Code/
237 |
238 | # Backup & report files from converting an old project file
239 | # to a newer Visual Studio version. Backup files are not needed,
240 | # because we have git ;-)
241 | _UpgradeReport_Files/
242 | Backup*/
243 | UpgradeLog*.XML
244 | UpgradeLog*.htm
245 | ServiceFabricBackup/
246 | *.rptproj.bak
247 |
248 | # SQL Server files
249 | *.mdf
250 | *.ldf
251 | *.ndf
252 |
253 | # Business Intelligence projects
254 | *.rdl.data
255 | *.bim.layout
256 | *.bim_*.settings
257 | *.rptproj.rsuser
258 | *- Backup*.rdl
259 |
260 | # Microsoft Fakes
261 | FakesAssemblies/
262 |
263 | # GhostDoc plugin setting file
264 | *.GhostDoc.xml
265 |
266 | # Node.js Tools for Visual Studio
267 | .ntvs_analysis.dat
268 | node_modules/
269 |
270 | # Visual Studio 6 build log
271 | *.plg
272 |
273 | # Visual Studio 6 workspace options file
274 | *.opt
275 |
276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
277 | *.vbw
278 |
279 | # Visual Studio LightSwitch build output
280 | **/*.HTMLClient/GeneratedArtifacts
281 | **/*.DesktopClient/GeneratedArtifacts
282 | **/*.DesktopClient/ModelManifest.xml
283 | **/*.Server/GeneratedArtifacts
284 | **/*.Server/ModelManifest.xml
285 | _Pvt_Extensions
286 |
287 | # Paket dependency manager
288 | .paket/paket.exe
289 | paket-files/
290 |
291 | # FAKE - F# Make
292 | .fake/
293 |
294 | # JetBrains Rider
295 | .idea/
296 | *.sln.iml
297 |
298 | # CodeRush personal settings
299 | .cr/personal
300 |
301 | # Python Tools for Visual Studio (PTVS)
302 | __pycache__/
303 | *.pyc
304 |
305 | # Cake - Uncomment if you are using it
306 | # tools/**
307 | # !tools/packages.config
308 |
309 | # Tabs Studio
310 | *.tss
311 |
312 | # Telerik's JustMock configuration file
313 | *.jmconfig
314 |
315 | # BizTalk build output
316 | *.btp.cs
317 | *.btm.cs
318 | *.odx.cs
319 | *.xsd.cs
320 |
321 | # OpenCover UI analysis results
322 | OpenCover/
323 |
324 | # Azure Stream Analytics local run output
325 | ASALocalRun/
326 |
327 | # MSBuild Binary and Structured Log
328 | *.binlog
329 |
330 | # NVidia Nsight GPU debugger configuration file
331 | *.nvuser
332 |
333 | # MFractors (Xamarin productivity tool) working folder
334 | .mfractor/
335 |
336 | # Local History for Visual Studio
337 | .localhistory/
338 |
339 | # BeatPulse healthcheck temp database
340 | healthchecksdb
--------------------------------------------------------------------------------
/CommentingSystem.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.2.32317.152
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommentingSystem.Web", "src\CommentingSystem.Web\CommentingSystem.Web.csproj", "{EA7E408F-8BF0-494D-924F-AB1CB41A3D3C}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5A4D97F7-C20D-4D09-B167-8A62E890EF1C}"
9 | ProjectSection(SolutionItems) = preProject
10 | README.md = README.md
11 | EndProjectSection
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Any CPU = Debug|Any CPU
16 | Release|Any CPU = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {EA7E408F-8BF0-494D-924F-AB1CB41A3D3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {EA7E408F-8BF0-494D-924F-AB1CB41A3D3C}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {EA7E408F-8BF0-494D-924F-AB1CB41A3D3C}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {EA7E408F-8BF0-494D-924F-AB1CB41A3D3C}.Release|Any CPU.Build.0 = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(SolutionProperties) = preSolution
25 | HideSolutionNode = FALSE
26 | EndGlobalSection
27 | GlobalSection(ExtensibilityGlobals) = postSolution
28 | SolutionGuid = {FA19F7F7-C3C7-4FB7-B115-B78470374992}
29 | EndGlobalSection
30 | EndGlobal
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Nested Commenting System
2 |
3 |
4 |
5 |
6 |
7 | *Nested Commenting System With*
8 | * ASP.NET Core 6
9 | * EF Core 6
10 | * Bootstrap 5.1.3
11 | * jQuery 3.6.0
12 |
13 | After download or clone the project you will need to run it with VS 2019 v16.8+, check the connection string and apply migrations using below command:
14 |
15 | ```
16 | Update-Database
17 | ```
18 |
19 | Run the project and enjoy.
20 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/CommentingSystem.Web.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | disable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | all
15 | runtime; build; native; contentfiles; analyzers; buildtransitive
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Configurations/ControllersWithViewsConfig.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Mvc;
2 | using Microsoft.Extensions.DependencyInjection;
3 | using Newtonsoft.Json;
4 |
5 | namespace CommentingSystem.Web.Configurations;
6 |
7 | public static class ControllersWithViewsConfig
8 | {
9 | public static void AddControllersWithViewsConfiguration(this IServiceCollection services)
10 | {
11 | if (services is null)
12 | {
13 | throw new ArgumentNullException(nameof(services));
14 | }
15 |
16 | services.AddControllersWithViews()
17 | .AddNewtonsoftJson(options =>
18 | {
19 | options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
20 | });
21 | }
22 | }
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Configurations/DbContextConfig.cs:
--------------------------------------------------------------------------------
1 | using CommentingSystem.Data;
2 | using Microsoft.EntityFrameworkCore;
3 |
4 | namespace CommentingSystem.Web.Configurations;
5 |
6 | public static class DbContextConfig
7 | {
8 | public static void AddDbContextConfiguration(this IServiceCollection services, IConfiguration configuration)
9 | {
10 | if (services is null)
11 | {
12 | throw new ArgumentNullException(nameof(services));
13 | }
14 |
15 | if (configuration is null)
16 | {
17 | throw new ArgumentNullException(nameof(configuration));
18 | }
19 |
20 | services.AddDbContext(options => options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")));
21 | }
22 | }
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Controllers/HomeController.cs:
--------------------------------------------------------------------------------
1 | using CommentingSystem.Data;
2 | using CommentingSystem.Domain;
3 | using CommentingSystem.DTOs;
4 | using Microsoft.AspNetCore.Mvc;
5 | using Microsoft.EntityFrameworkCore;
6 |
7 | namespace CommentingSystem.Controllers;
8 |
9 | public class HomeController : Controller
10 | {
11 | private readonly CommentingSystemDbContext _db;
12 |
13 | public HomeController(CommentingSystemDbContext db)
14 | {
15 | _db = db;
16 | }
17 |
18 | public async Task Index()
19 | {
20 |
21 | List comments = await _db.Comments
22 | .AsNoTrackingWithIdentityResolution()
23 | .Include(c => c.Children)
24 | .ToListAsync();
25 |
26 | // Structure comments into a tree
27 | List rootComments = comments
28 | .Where(c => c.ParentId == null)
29 | .AsParallel()
30 | .ToList();
31 |
32 | return View(rootComments);
33 | }
34 |
35 | [HttpPost]
36 | public async Task CreateComment(CreateCommentDto commentCDto)
37 | {
38 | if (ModelState.IsValid)
39 | {
40 | var newComment = new Comment
41 | {
42 | ParentId = commentCDto.ReplyToCommentId,
43 | FullName = commentCDto.FullName,
44 | Email = commentCDto.Email,
45 | Content = commentCDto.Content,
46 | DateCreated = DateTimeOffset.Now,
47 | DateModified = DateTimeOffset.Now
48 | };
49 |
50 | await _db.Comments.AddAsync(newComment);
51 | await _db.SaveChangesAsync();
52 | return RedirectToAction(nameof(Index));
53 | }
54 |
55 | // TODO: Throw some error
56 | return RedirectToAction(nameof(Index));
57 | }
58 |
59 | [HttpPost]
60 | public async Task DeleteComment(int commentId)
61 | {
62 | var comments = await _db.Comments
63 | .Include(x => x.Children).ToListAsync();
64 |
65 | var flatten = Flatten(comments.Where(x => x.CommentId == commentId));
66 |
67 | _db.Comments.RemoveRange(flatten);
68 |
69 | await _db.SaveChangesAsync();
70 |
71 | return RedirectToAction(nameof(Index));
72 | }
73 | IEnumerable Flatten(IEnumerable comments) =>
74 | comments.SelectMany(x => Flatten(x.Children)).Concat(comments);
75 | }
76 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/DTOs/CreateCommentDto.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using System.ComponentModel.DataAnnotations;
3 |
4 | namespace CommentingSystem.DTOs;
5 | public record class CreateCommentDto
6 | {
7 | public int? ReplyToCommentId { get; init; }
8 |
9 | [Required, StringLength(1000, MinimumLength = 10)]
10 | public string Content { get; init; }
11 |
12 | [EmailAddress, StringLength(100, MinimumLength = 6), Required]
13 | public string Email { get; init; }
14 |
15 | [Required, StringLength(60, MinimumLength = 3),DisplayName("Full Name")]
16 | public string FullName { get; init; }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Data/CommentingSystemDbContext.cs:
--------------------------------------------------------------------------------
1 | using CommentingSystem.Domain;
2 | using Microsoft.EntityFrameworkCore;
3 |
4 | namespace CommentingSystem.Data;
5 |
6 | public class CommentingSystemDbContext : DbContext
7 | {
8 | public CommentingSystemDbContext(DbContextOptions dbContextOptions) : base(dbContextOptions)
9 | {
10 |
11 | }
12 | protected override void OnModelCreating(ModelBuilder modelBuilder)
13 | {
14 | base.OnModelCreating(modelBuilder);
15 |
16 | modelBuilder.Entity(comment =>
17 | {
18 | comment.HasKey(c => c.CommentId);
19 | comment.HasIndex(c => c.ParentId);
20 |
21 | comment.HasOne(c => c.Parent)
22 | .WithMany(c => c.Children)
23 | .HasForeignKey(c => c.ParentId);
24 |
25 | comment.Property(c => c.FullName).HasMaxLength(60).IsRequired();
26 | comment.Property(c => c.Email).HasMaxLength(100).IsRequired();
27 | comment.Property(c => c.Content).HasMaxLength(1000).IsRequired();
28 | });
29 | }
30 |
31 | public DbSet Comments { get; set; }
32 | }
33 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Domain/Comment.cs:
--------------------------------------------------------------------------------
1 | namespace CommentingSystem.Domain;
2 |
3 | public class Comment
4 | {
5 | public int CommentId { get; set; }
6 | public int? ParentId { get; set; }
7 | public string FullName { get; set; }
8 | public string Email { get; set; }
9 | public string Content { get; set; }
10 | public DateTimeOffset DateCreated { get; set; }
11 | public DateTimeOffset DateModified { get; set; }
12 | public Comment Parent { get; set; }
13 | public ICollection Children { get; set; }
14 | }
15 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Migrations/20220415125505_Initial.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using CommentingSystem.Data;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.EntityFrameworkCore.Infrastructure;
6 | using Microsoft.EntityFrameworkCore.Metadata;
7 | using Microsoft.EntityFrameworkCore.Migrations;
8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
9 |
10 | #nullable disable
11 |
12 | namespace CommentingSystem.Web.Migrations
13 | {
14 | [DbContext(typeof(CommentingSystemDbContext))]
15 | [Migration("20220415125505_Initial")]
16 | partial class Initial
17 | {
18 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
19 | {
20 | #pragma warning disable 612, 618
21 | modelBuilder
22 | .HasAnnotation("ProductVersion", "6.0.4")
23 | .HasAnnotation("Relational:MaxIdentifierLength", 128);
24 |
25 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
26 |
27 | modelBuilder.Entity("CommentingSystem.Domain.Comment", b =>
28 | {
29 | b.Property("CommentId")
30 | .ValueGeneratedOnAdd()
31 | .HasColumnType("int");
32 |
33 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("CommentId"), 1L, 1);
34 |
35 | b.Property("Content")
36 | .IsRequired()
37 | .HasMaxLength(1000)
38 | .HasColumnType("nvarchar(1000)");
39 |
40 | b.Property("DateCreated")
41 | .HasColumnType("datetimeoffset");
42 |
43 | b.Property("DateModified")
44 | .HasColumnType("datetimeoffset");
45 |
46 | b.Property("Email")
47 | .IsRequired()
48 | .HasMaxLength(100)
49 | .HasColumnType("nvarchar(100)");
50 |
51 | b.Property("FullName")
52 | .IsRequired()
53 | .HasMaxLength(60)
54 | .HasColumnType("nvarchar(60)");
55 |
56 | b.Property("ParentId")
57 | .HasColumnType("int");
58 |
59 | b.HasKey("CommentId");
60 |
61 | b.HasIndex("ParentId");
62 |
63 | b.ToTable("Comments");
64 | });
65 |
66 | modelBuilder.Entity("CommentingSystem.Domain.Comment", b =>
67 | {
68 | b.HasOne("CommentingSystem.Domain.Comment", "Parent")
69 | .WithMany("Children")
70 | .HasForeignKey("ParentId");
71 |
72 | b.Navigation("Parent");
73 | });
74 |
75 | modelBuilder.Entity("CommentingSystem.Domain.Comment", b =>
76 | {
77 | b.Navigation("Children");
78 | });
79 | #pragma warning restore 612, 618
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Migrations/20220415125505_Initial.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.EntityFrameworkCore.Migrations;
3 |
4 | #nullable disable
5 |
6 | namespace CommentingSystem.Web.Migrations
7 | {
8 | public partial class Initial : Migration
9 | {
10 | protected override void Up(MigrationBuilder migrationBuilder)
11 | {
12 | migrationBuilder.CreateTable(
13 | name: "Comments",
14 | columns: table => new
15 | {
16 | CommentId = table.Column(type: "int", nullable: false)
17 | .Annotation("SqlServer:Identity", "1, 1"),
18 | ParentId = table.Column(type: "int", nullable: true),
19 | FullName = table.Column(type: "nvarchar(60)", maxLength: 60, nullable: false),
20 | Email = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false),
21 | Content = table.Column(type: "nvarchar(1000)", maxLength: 1000, nullable: false),
22 | DateCreated = table.Column(type: "datetimeoffset", nullable: false),
23 | DateModified = table.Column(type: "datetimeoffset", nullable: false)
24 | },
25 | constraints: table =>
26 | {
27 | table.PrimaryKey("PK_Comments", x => x.CommentId);
28 | table.ForeignKey(
29 | name: "FK_Comments_Comments_ParentId",
30 | column: x => x.ParentId,
31 | principalTable: "Comments",
32 | principalColumn: "CommentId");
33 | });
34 |
35 | migrationBuilder.CreateIndex(
36 | name: "IX_Comments_ParentId",
37 | table: "Comments",
38 | column: "ParentId");
39 | }
40 |
41 | protected override void Down(MigrationBuilder migrationBuilder)
42 | {
43 | migrationBuilder.DropTable(
44 | name: "Comments");
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Migrations/CommentingSystemDbContextModelSnapshot.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using CommentingSystem.Data;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.EntityFrameworkCore.Infrastructure;
6 | using Microsoft.EntityFrameworkCore.Metadata;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | #nullable disable
10 |
11 | namespace CommentingSystem.Web.Migrations
12 | {
13 | [DbContext(typeof(CommentingSystemDbContext))]
14 | partial class CommentingSystemDbContextModelSnapshot : ModelSnapshot
15 | {
16 | protected override void BuildModel(ModelBuilder modelBuilder)
17 | {
18 | #pragma warning disable 612, 618
19 | modelBuilder
20 | .HasAnnotation("ProductVersion", "6.0.4")
21 | .HasAnnotation("Relational:MaxIdentifierLength", 128);
22 |
23 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
24 |
25 | modelBuilder.Entity("CommentingSystem.Domain.Comment", b =>
26 | {
27 | b.Property("CommentId")
28 | .ValueGeneratedOnAdd()
29 | .HasColumnType("int");
30 |
31 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("CommentId"), 1L, 1);
32 |
33 | b.Property("Content")
34 | .IsRequired()
35 | .HasMaxLength(1000)
36 | .HasColumnType("nvarchar(1000)");
37 |
38 | b.Property("DateCreated")
39 | .HasColumnType("datetimeoffset");
40 |
41 | b.Property("DateModified")
42 | .HasColumnType("datetimeoffset");
43 |
44 | b.Property("Email")
45 | .IsRequired()
46 | .HasMaxLength(100)
47 | .HasColumnType("nvarchar(100)");
48 |
49 | b.Property("FullName")
50 | .IsRequired()
51 | .HasMaxLength(60)
52 | .HasColumnType("nvarchar(60)");
53 |
54 | b.Property("ParentId")
55 | .HasColumnType("int");
56 |
57 | b.HasKey("CommentId");
58 |
59 | b.HasIndex("ParentId");
60 |
61 | b.ToTable("Comments");
62 | });
63 |
64 | modelBuilder.Entity("CommentingSystem.Domain.Comment", b =>
65 | {
66 | b.HasOne("CommentingSystem.Domain.Comment", "Parent")
67 | .WithMany("Children")
68 | .HasForeignKey("ParentId");
69 |
70 | b.Navigation("Parent");
71 | });
72 |
73 | modelBuilder.Entity("CommentingSystem.Domain.Comment", b =>
74 | {
75 | b.Navigation("Children");
76 | });
77 | #pragma warning restore 612, 618
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Program.cs:
--------------------------------------------------------------------------------
1 | using CommentingSystem.Web.Configurations;
2 |
3 | var builder = WebApplication.CreateBuilder(args);
4 |
5 | builder.Services.AddControllersWithViewsConfiguration();
6 |
7 | builder.Services.AddDbContextConfiguration(builder.Configuration);
8 |
9 | var app = builder.Build();
10 |
11 | app.UseStaticFiles();
12 |
13 | app.UseRouting();
14 |
15 | app.MapDefaultControllerRoute();
16 |
17 | await app.RunAsync();
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:14855",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "CommentingSystem": {
12 | "commandName": "Project",
13 | "dotnetRunMessages": true,
14 | "launchBrowser": true,
15 | "applicationUrl": "http://localhost:5000",
16 | "environmentVariables": {
17 | "ASPNETCORE_ENVIRONMENT": "Development",
18 | "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
19 | }
20 | },
21 | "IIS Express": {
22 | "commandName": "IISExpress",
23 | "launchBrowser": true,
24 | "environmentVariables": {
25 | "ASPNETCORE_ENVIRONMENT": "Development",
26 | "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Views/Home/Index.cshtml:
--------------------------------------------------------------------------------
1 | @model IEnumerable
2 |
3 | @{
4 | ViewData["Title"] = "Comments";
5 | }
6 |
7 |
8 |
9 |
10 |
11 |
Commenting System
12 |
13 |
14 |
15 |
16 |
17 | @if (Model.Any())
18 | {
19 |
24 | }
25 |
26 |
27 |
28 |
29 |
30 | @section scripts {
31 |
49 |
50 | }
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Views/Home/_CommentsPartialView.cshtml:
--------------------------------------------------------------------------------
1 | @model IEnumerable
2 |
3 |
4 | @foreach (var comment in Model)
5 | {
6 | -
7 |
16 |
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Views/Home/_CreateComment.cshtml:
--------------------------------------------------------------------------------
1 | @model CreateCommentDto
2 |
3 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Views/Home/_CreateReplyModal.cshtml:
--------------------------------------------------------------------------------
1 | @model CreateCommentDto
2 |
3 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Views/Home/_DeleteCommentModal.cshtml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Views/Shared/_Layout.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | @ViewBag.Title
8 |
9 |
19 |
20 |
21 |
22 |
23 |
24 | @RenderBody()
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
38 | @await RenderSectionAsync("scripts", false)
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Views/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
2 | @using CommentingSystem.DTOs
3 | @using CommentingSystem.Domain
4 | @using CommentingSystem
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/Views/_ViewStart.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | Layout = "_Layout";
3 | }
4 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*",
10 | "ConnectionStrings": {
11 | "CommentSystemConStr": "Server=.;Database=CommentingSystem;Trusted_Connection=True;MultipleActiveResultSets=True;"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/CommentingSystem.Web/wwwroot/img/Capture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ArminShoeibi/CommentingSystem/27f6839f4e447086c87a6b7552ac95e7b2925a5f/src/CommentingSystem.Web/wwwroot/img/Capture.png
--------------------------------------------------------------------------------
@comment.FullName
10 |@comment.DateCreated.DateTime
11 |@comment.Content
12 | 13 | 14 |