Skip to content

Commit ebe77f5

Browse files
committed
Refractored RecordsController
1 parent 3a9b89b commit ebe77f5

File tree

57 files changed

+449
-204
lines changed

Some content is hidden

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

57 files changed

+449
-204
lines changed

.vs/slnx.sqlite

0 Bytes
Binary file not shown.

SentimentAnalysisTool.Web/Enums/AlgorithmnType.cs SentimentAnalysisTool.Data/Enums/AlgorithmnType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55

6-
namespace SentimentAnalysisTool.Web.Enums
6+
namespace SentimentAnalysisTool.Data.Enums
77
{
88
public enum AlgorithmnType
99
{

SentimentAnalysisTool.Web/Enums/ConfusionMatrixType.cs SentimentAnalysisTool.Data/Enums/ConfusionMatrixType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55

6-
namespace SentimentAnalysisTool.Web.Enums
6+
namespace SentimentAnalysisTool.Data.Enums
77
{
88
public enum ConfusionMatrixType
99
{

SentimentAnalysisTool.Web/Enums/DataCorpusType.cs SentimentAnalysisTool.Data/Enums/DataCorpusType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55

6-
namespace SentimentAnalysisTool.Web.Enums
6+
namespace SentimentAnalysisTool.Data.Enums
77
{
88
/// <summary>
99
/// This is only a temporary enum, This should be removed

SentimentAnalysisTool.Web/Enums/SentimentType.cs SentimentAnalysisTool.Data/Enums/SentimentType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55

6-
namespace SentimentAnalysisTool.Web.Enums
6+
namespace SentimentAnalysisTool.Data.Enums
77
{
88
public enum SentimentType
99
{
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
11
using Microsoft.AspNetCore.Http;
22
using Newtonsoft.Json;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Threading.Tasks;
3+
using SentimentAnalysisTool.Data.Enums;
74

8-
namespace SentimentAnalysisTool.Web.Models
5+
namespace SentimentAnalysisTool.Data.Models
96
{
107
public class UploadCsvFileModel
118
{
129
public IFormFile File { get; set; }
13-
14-
[JsonProperty("algorithmn")]
15-
public string Algorithmn { get; set; }
16-
17-
[JsonProperty("shouldDeleteSlangs")]
10+
public AlgorithmnType Algorithmn { get; set; }
1811
public bool ShouldDeleteSlangs { get; set; }
19-
20-
[JsonProperty("shouldConvertAbbreviations")]
2112
public bool ShouldConvertAbbreviations { get; set; }
22-
23-
[JsonProperty("shouldConvertSynonyms")]
2413
public bool ShouldConvertSynonyms { get; set; }
25-
26-
[JsonProperty("corpusType")]
2714
public string CorpusType { get; set; }
28-
29-
[JsonProperty("maxNumberOfChars")]
3015
public int MaxNumberOfChars { get; set; }
31-
32-
[JsonProperty("subjectMatter")]
3316
public string SubjectMatter { get; set; } = string.Empty;
3417
}
3518
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
daa2e9f81957c3ec081876a5b9f45332825009bc
1+
6ab88ca2f1f025c8e051a0eb5d5c0aa66d0293ab
Binary file not shown.
Binary file not shown.
Binary file not shown.

SentimentAnalysisTool.Services/Implementations/RecordsService.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
using Microsoft.AspNetCore.Http;
2-
using Newtonsoft.Json;
3-
using SentimentAnalysisTool.Data.Models;
1+
using SentimentAnalysisTool.Data.Models;
42
using SentimentAnalysisTool.Services.Interfaces;
5-
using SentimentAnalysisTool.Web.Models;
63
using System;
74
using System.Collections.Generic;
85
using System.IO;
96
using System.Net.Http;
10-
using System.Text;
11-
using System.Text.Json;
127
using System.Threading.Tasks;
138

149
namespace SentimentAnalysisTool.Services.Implementations
@@ -78,7 +73,7 @@ private async Task<MultipartFormDataContent> ParseFile(UploadCsvFileModel file)
7873
var fileBytes = ms.ToArray();
7974
form.Add(new ByteArrayContent(fileBytes, 0, fileBytes.Length), "file", file.File.FileName);
8075
form.Add(new StringContent(file.ShouldDeleteSlangs.ToString()), "\"shouldDeleteSlangs\"");
81-
form.Add(new StringContent(file.Algorithmn), "\"algorithmn\"");
76+
form.Add(new StringContent(file.Algorithmn.ToString()), "\"algorithmn\"");
8277
form.Add(new StringContent(file.ShouldConvertAbbreviations.ToString()), "\"shouldConvertAbbreviations\"");
8378
form.Add(new StringContent(file.ShouldConvertSynonyms.ToString()), "\"shouldConvertSynonyms\"");
8479
form.Add(new StringContent(file.CorpusType.ToString()), "\"corpusType\"");

SentimentAnalysisTool.Services/Interfaces/IRecordsService.cs

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
using Microsoft.AspNetCore.Http;
2-
using SentimentAnalysisTool.Data.Models;
3-
using SentimentAnalysisTool.Web.Models;
4-
using System;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Net.Http;
8-
using System.Text;
1+
using SentimentAnalysisTool.Data.Models;
92
using System.Threading.Tasks;
103

114
namespace SentimentAnalysisTool.Services.Interfaces
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

SentimentAnalysisTool.Web/Controllers/RecordsController.cs

+6-26
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using Microsoft.AspNetCore.Http;
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.Extensions.Configuration;
4+
using SentimentAnalysisTool.Data.Enums;
45
using SentimentAnalysisTool.Data.Models;
56
using SentimentAnalysisTool.Services.Interfaces;
6-
using SentimentAnalysisTool.Web.Enums;
77
using SentimentAnalysisTool.Web.Helpers;
88
using SentimentAnalysisTool.Web.Helpers.Interfaces;
99
using SentimentAnalysisTool.Web.Models;
1010
using SentimentAnalysisTool.Web.Models.CommentViewModels;
1111
using System;
1212
using System.Linq;
13-
using System.Net.Http;
1413
using System.Threading.Tasks;
1514

1615
namespace SentimentAnalysisTool.Web.Controllers
@@ -38,30 +37,11 @@ public IActionResult Index(RecordDisplayViewModel model)
3837

3938
[HttpPost]
4039
[ValidateAntiForgeryToken]
41-
public async Task<ActionResult> UploadCsvFile(
42-
[FromForm] IFormFile file,
43-
[FromForm] AlgorithmnType algorithmnType,
44-
[FromForm] bool shouldDeleteSlangs,
45-
[FromForm] bool shouldConvertAbbreviations,
46-
[FromForm] bool shouldConvertSynonymns,
47-
[FromForm] string subjectMatter,
48-
[FromForm] string corpusType,
49-
[FromForm] int maxNumberOfChars)
40+
public async Task<ActionResult> UploadCsvFile([FromForm] UploadCsvFileModel uploadCsvFile)
5041
{
5142
try
5243
{
53-
var uploadCsvModel = new UploadCsvFileModel()
54-
{
55-
File = file,
56-
ShouldDeleteSlangs = shouldDeleteSlangs,
57-
ShouldConvertAbbreviations = shouldConvertAbbreviations,
58-
ShouldConvertSynonyms = shouldConvertSynonymns,
59-
CorpusType = corpusType,
60-
MaxNumberOfChars = maxNumberOfChars,
61-
Algorithmn = algorithmnType.ToString(),
62-
SubjectMatter = subjectMatter
63-
};
64-
RecordDisplayViewModel recordDisplay = await BuildRecordDisplayViewModelAsync(uploadCsvModel, algorithmnType);
44+
RecordDisplayViewModel recordDisplay = await BuildRecordDisplayViewModelAsync(uploadCsvFile);
6545

6646
var obj = new
6747
{
@@ -79,10 +59,10 @@ public async Task<ActionResult> UploadCsvFile(
7959
}
8060
}
8161

82-
private async Task<RecordDisplayViewModel> BuildRecordDisplayViewModelAsync(UploadCsvFileModel record, AlgorithmnType algorithmn)
62+
private async Task<RecordDisplayViewModel> BuildRecordDisplayViewModelAsync(UploadCsvFileModel record)
8363
{
8464
RecordDisplayViewModel recordDisplay = new();
85-
switch (algorithmn)
65+
switch (record.Algorithmn)
8666
{
8767
case AlgorithmnType.Hybrid:
8868
var recordModelHybridObjects = await _recordsService.AddRecordAsync<HybridModel>(record, _configuration.GetValue<string>("BaseUrl"));
@@ -145,7 +125,7 @@ private async Task<RecordDisplayViewModel> BuildRecordDisplayViewModelAsync(Uplo
145125
.ForEach(x => x.AlgorithmnGrade.CompoundScore = SentimentType.Positive.ToString());
146126
break;
147127
}
148-
recordDisplay.Algorithmn = algorithmn;
128+
recordDisplay.Algorithmn = record.Algorithmn;
149129
return recordDisplay;
150130
}
151131
}

SentimentAnalysisTool.Web/Helpers/Implementations/ComputingHelper.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
using SentimentAnalysisTool.Web.Enums;
1+
using SentimentAnalysisTool.Data.Enums;
22
using SentimentAnalysisTool.Web.Helpers.Interfaces;
33
using SentimentAnalysisTool.Web.Models;
44
using System;
5-
using System.Collections.Generic;
65
using System.Linq;
7-
using System.Threading.Tasks;
86

97
namespace SentimentAnalysisTool.Web.Helpers.Implementations
108
{

SentimentAnalysisTool.Web/Models/CommentViewModels/BaseCommentViewModel.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using SentimentAnalysisTool.Web.Enums;
1+
using SentimentAnalysisTool.Data.Enums;
22
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Threading.Tasks;
63

74
namespace SentimentAnalysisTool.Web.Models.CommentViewModels
85
{

SentimentAnalysisTool.Web/Models/CommentViewModels/CommentHybridViewModel.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
using Newtonsoft.Json;
1+
using SentimentAnalysisTool.Data.Enums;
22
using SentimentAnalysisTool.Data.Models;
3-
using SentimentAnalysisTool.Web.Enums;
43
using System;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Text.Json.Serialization;
8-
using System.Threading.Tasks;
94

105
namespace SentimentAnalysisTool.Web.Models.CommentViewModels
116
{

SentimentAnalysisTool.Web/Models/CommentViewModels/CommentSentiWordNetViewModel.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
using SentimentAnalysisTool.Data.Models;
2-
using SentimentAnalysisTool.Web.Enums;
1+
using SentimentAnalysisTool.Data.Enums;
2+
using SentimentAnalysisTool.Data.Models;
33
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text.Json.Serialization;
7-
using System.Threading.Tasks;
84

95
namespace SentimentAnalysisTool.Web.Models.CommentViewModels
106
{

SentimentAnalysisTool.Web/Models/CommentViewModels/CommentVaderViewModel.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using SentimentAnalysisTool.Data.Models;
2-
using SentimentAnalysisTool.Web.Enums;
1+
using SentimentAnalysisTool.Data.Enums;
2+
using SentimentAnalysisTool.Data.Models;
33
using System;
4-
using System.Text.Json.Serialization;
54

65
namespace SentimentAnalysisTool.Web.Models.CommentViewModels
76
{

SentimentAnalysisTool.Web/Models/RecordDisplayViewModel.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using SentimentAnalysisTool.Web.Enums;
1+
using SentimentAnalysisTool.Data.Enums;
22
using SentimentAnalysisTool.Web.Models.CommentViewModels;
3-
using System;
43
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Threading.Tasks;
74

85
namespace SentimentAnalysisTool.Web.Models
96
{

SentimentAnalysisTool.Web/Views/Records/Index.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
@await Html.PartialAsync("_RecordDisplayPartial", Model)
3434
</div>
3535

36-
@await Html.PartialAsync("_UploadFileFormPartial")
36+
@await Html.PartialAsync("_UploadFileFormPartial", new SentimentAnalysisTool.Data.Models.UploadCsvFileModel())
3737

3838
@section scripts{
3939
<script>

SentimentAnalysisTool.Web/Views/Records/_CommentsPartial.cshtml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@using SentimentAnalysisTool.Web.Enums
1+
@using SentimentAnalysisTool.Data.Enums
22
@using SentimentAnalysisTool.Data.Models
33
@model dynamic
44
@if (Model.Count == 0)
@@ -38,11 +38,11 @@ else
3838
<td><span class="badge badge-pill badge-secondary">@Model[i].CommentScore / 5</span></td>
3939
}
4040

41-
@if (Model[i].CommentPolarity == SentimentAnalysisTool.Web.Enums.SentimentType.Positive)
41+
@if (Model[i].CommentPolarity == SentimentAnalysisTool.Data.Enums.SentimentType.Positive)
4242
{
4343
<td><span class="badge badge-light">@Model[i].CommentPolarity <i class="fas fa-smile"></i></span></td>
4444
}
45-
else if (Model[i].CommentPolarity == SentimentAnalysisTool.Web.Enums.SentimentType.Negative)
45+
else if (Model[i].CommentPolarity == SentimentAnalysisTool.Data.Enums.SentimentType.Negative)
4646
{
4747
<td><span class="badge badge-secondary">@Model[i].CommentPolarity <i class="fas fa-sad-tear"></i></span></td>
4848
}

SentimentAnalysisTool.Web/Views/Records/_RecordDisplayPartial.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@using SentimentAnalysisTool.Web.Enums
1+
@using SentimentAnalysisTool.Data.Enums
22
@using SentimentAnalysisTool.Web.Models.CommentViewModels
33
@model SentimentAnalysisTool.Web.Models.RecordDisplayViewModel
44
<div class="col-6">

SentimentAnalysisTool.Web/Views/Records/_UploadFileFormPartial.cshtml

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<div class="modal fade" id="upload-modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
1+
@model SentimentAnalysisTool.Data.Models.UploadCsvFileModel
2+
3+
<div class="modal fade" id="upload-modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
24
<div class="modal-dialog" role="document">
35
<div class="modal-content">
46
<div class="modal-header">
@@ -18,32 +20,32 @@
1820
<hr />
1921
<h6><b>Select Algorithmn</b></h6>
2022
<div class="form-check form-check-inline mt-2">
21-
<input class="form-check-input" type="radio" name="algorithmnType" value="@SentimentAnalysisTool.Web.Enums.AlgorithmnType.Hybrid" required>
22-
<label class="form-check-label">@nameof(SentimentAnalysisTool.Web.Enums.AlgorithmnType.Hybrid)</label>
23+
<input class="form-check-input" type="radio" asp-for="@Model.Algorithmn" value="@SentimentAnalysisTool.Data.Enums.AlgorithmnType.Hybrid" required>
24+
<label class="form-check-label">@nameof(SentimentAnalysisTool.Data.Enums.AlgorithmnType.Hybrid)</label>
2325
</div>
2426
<div class="form-check form-check-inline">
25-
<input class="form-check-input" type="radio" name="algorithmnType" value="@SentimentAnalysisTool.Web.Enums.AlgorithmnType.SentiWordNet" required>
26-
<label class="form-check-label">@nameof(SentimentAnalysisTool.Web.Enums.AlgorithmnType.SentiWordNet)</label>
27+
<input class="form-check-input" type="radio" asp-for="@Model.Algorithmn" value="@SentimentAnalysisTool.Data.Enums.AlgorithmnType.SentiWordNet" required>
28+
<label class="form-check-label">@nameof(SentimentAnalysisTool.Data.Enums.AlgorithmnType.SentiWordNet)</label>
2729
</div>
2830
<div class="form-check form-check-inline">
29-
<input class="form-check-input" type="radio" name="algorithmnType" value="@SentimentAnalysisTool.Web.Enums.AlgorithmnType.Vader" required>
30-
<label class="form-check-label">@nameof(SentimentAnalysisTool.Web.Enums.AlgorithmnType.Vader)</label>
31+
<input class="form-check-input" type="radio" asp-for="@Model.Algorithmn" value="@SentimentAnalysisTool.Data.Enums.AlgorithmnType.Vader" required>
32+
<label class="form-check-label">@nameof(SentimentAnalysisTool.Data.Enums.AlgorithmnType.Vader)</label>
3133
</div>
3234
<hr />
3335
<h6><b>Select CorpusType</b></h6>
3436
<div class="row">
3537
<div class="col-6">
36-
<input type="text" class="form-control" id="corpus-type" name="corpusType" readonly value="FilmReview" required />
38+
<input type="text" class="form-control" id="corpus-type" asp-for="@Model.CorpusType" readonly value="FilmReview" required />
3739
</div>
3840
<div class="col-6">
3941
<div class="dropdown mb-1">
4042
<button class="btn btn-secondary dropdown-toggle btn-block" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
4143
CorpusType
4244
</button>
4345
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
44-
<a class="dropdown-item" id="drop-down-env">@nameof(SentimentAnalysisTool.Web.Enums.DataCorpusType.EnvironmentReview)</a>
45-
<a class="dropdown-item" id="drop-down-film">@nameof(SentimentAnalysisTool.Web.Enums.DataCorpusType.FilmReview)</a>
46-
<a class="dropdown-item" id="drop-down-prod">@nameof(SentimentAnalysisTool.Web.Enums.DataCorpusType.ProductReview)</a>
46+
<a class="dropdown-item" id="drop-down-env">@nameof(SentimentAnalysisTool.Data.Enums.DataCorpusType.EnvironmentReview)</a>
47+
<a class="dropdown-item" id="drop-down-film">@nameof(SentimentAnalysisTool.Data.Enums.DataCorpusType.FilmReview)</a>
48+
<a class="dropdown-item" id="drop-down-prod">@nameof(SentimentAnalysisTool.Data.Enums.DataCorpusType.ProductReview)</a>
4749
</div>
4850
</div>
4951
</div>
@@ -52,35 +54,35 @@
5254
<h6><b>Select Preprocessing techniques</b></h6>
5355
<p>Delete Slang Words? </p>
5456
<div class="form-check form-check-inline">
55-
<input class="form-check-input" type="radio" name="shouldDeleteSlangs" value="true" required>
57+
<input class="form-check-input" type="radio" asp-for="@Model.ShouldDeleteSlangs" value="true" required>
5658
<label class="form-check-label">True</label>
5759
</div>
5860
<div class="form-check form-check-inline">
59-
<input class="form-check-input" type="radio" name="shouldDeleteSlangs" value="false" required>
61+
<input class="form-check-input" type="radio" asp-for="@Model.ShouldDeleteSlangs" value="false" required>
6062
<label class="form-check-label">False</label>
6163
</div>
6264
<p class="mt-3">Convert Abbreviations? </p>
6365
<div class="form-check form-check-inline">
64-
<input class="form-check-input" type="radio" name="shouldConvertAbbreviations" value="true" required>
66+
<input class="form-check-input" type="radio" asp-for="@Model.ShouldConvertAbbreviations" value="true" required>
6567
<label class="form-check-label">True</label>
6668
</div>
6769
<div class="form-check form-check-inline">
68-
<input class="form-check-input" type="radio" name="shouldConvertAbbreviations" value="false" required>
70+
<input class="form-check-input" type="radio" asp-for="@Model.ShouldConvertAbbreviations" value="false" required>
6971
<label class="form-check-label">False</label>
7072
</div>
7173
<p class="mt-3">Convert words that are not in wordnet? </p>
7274
<div class="form-check form-check-inline">
73-
<input class="form-check-input" type="radio" name="shouldConvertSynonymns" value="true" required>
75+
<input class="form-check-input" type="radio" asp-for="@Model.ShouldConvertSynonyms" value="true" required>
7476
<label class="form-check-label">True</label>
7577
</div>
7678
<div class="form-check form-check-inline">
77-
<input class="form-check-input" type="radio" name="shouldConvertSynonymns" value="false" required>
79+
<input class="form-check-input" type="radio" asp-for="@Model.ShouldConvertSynonyms" value="false" required>
7880
<label class="form-check-label">False</label>
7981
</div>
8082
<p class="mt-3">Subject Matter</p>
81-
<input type="text" class="form-control" name="subjectMatter"/>
83+
<input type="text" class="form-control" name="subjectMatter" />
8284
<p class="mt-3">Maximum number of characters</p>
83-
<input type="number" class="form-control" name="maxNumberOfChars" min="1" max="250" value="250" required />
85+
<input type="number" class="form-control" asp-for="@Model.MaxNumberOfChars" min="1" max="250" value="250" required />
8486
</form>
8587
</div>
8688
<div class="modal-footer">
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)