Skip to content

Commit 535d6d1

Browse files
authored
remove some nullwarnings (#2842)
1 parent 35c8085 commit 535d6d1

File tree

7 files changed

+26
-29
lines changed

7 files changed

+26
-29
lines changed

src/JoinRpg.Domain/ProjectEntityExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using System.Diagnostics.Contracts;
23
using System.Linq.Expressions;
34
using JoinRpg.DataModel;
@@ -30,7 +31,7 @@ public static bool HasMasterAccess(this IProjectEntity entity, ICurrentUserAcces
3031
return entity.HasMasterAccess(currentUserAccessor.UserIdOrDefault, acl => true);
3132
}
3233

33-
public static T RequestMasterAccess<T>(this T field,
34+
public static T RequestMasterAccess<T>([NotNull] this T? field,
3435
int? currentUserId,
3536
Expression<Func<ProjectAcl, bool>>? accessType = null)
3637
where T : IProjectEntity
@@ -56,8 +57,9 @@ public static T RequestMasterAccess<T>(this T field,
5657
return field;
5758
}
5859

59-
public static T EnsureActive<T>(this T entity) where T : IDeletableSubEntity, IProjectEntity
60+
public static T EnsureActive<T>([NotNull] this T? entity) where T : IDeletableSubEntity, IProjectEntity
6061
{
62+
ArgumentNullException.ThrowIfNull(entity);
6163
if (!entity.IsActive)
6264
{
6365
throw new ProjectEntityDeactivatedException(entity);

src/JoinRpg.Portal/Controllers/CharacterController.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ await CharacterService.EditCharacter(
123123
[MasterAuthorize(Permission.CanEditRoles)]
124124
public async Task<ActionResult> Create(int projectid, int? charactergroupid, bool continueCreating = false)
125125
{
126-
CharacterGroup characterGroup;
126+
CharacterGroup? characterGroup;
127127
if (charactergroupid is null)
128128
{
129129
characterGroup = await ProjectRepository.GetRootGroupAsync(projectid);
@@ -180,17 +180,19 @@ await CharacterService.AddCharacter(new AddCharacterRequest(
180180
catch (Exception exception)
181181
{
182182
ModelState.AddException(exception);
183-
CharacterGroup characterGroup;
183+
CharacterGroup? characterGroup;
184184
if (characterGroupId == 0)
185185
{
186186
characterGroup = (await ProjectRepository.GetProjectAsync(viewModel.ProjectId))
187187
.RootGroup;
188188
}
189189
else
190190
{
191-
characterGroup =
192-
await ProjectRepository.GetGroupAsync(viewModel.ProjectId,
193-
characterGroupId);
191+
characterGroup = await ProjectRepository.GetGroupAsync(viewModel.ProjectId, characterGroupId);
192+
if (characterGroup is null)
193+
{
194+
return NotFound();
195+
}
194196
}
195197

196198
var projectInfo = await projectMetadataRepository.GetProjectMetadata(new ProjectIdentification(viewModel.ProjectId));

src/JoinRpg.Portal/Controllers/CharacterListController.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,19 @@ public CharacterListController(
9393
ExportDataService = exportDataService;
9494
}
9595

96-
97-
private async Task<int[]> GetChildrenGroupIds(int projectId, int characterGroupId)
98-
{
99-
var groups = await ProjectRepository.GetGroupAsync(projectId, characterGroupId);
100-
return groups.GetChildrenGroupsRecursive().Select(g => g.CharacterGroupId).Append(characterGroupId).ToArray();
101-
}
102-
10396
[HttpGet("~/{ProjectId}/characters/bygroup/{CharacterGroupId}")]
10497
public async Task<ActionResult> ByGroup(int projectId, int characterGroupId, string export)
10598
{
10699
var characterGroup = await ProjectRepository.GetGroupAsync(projectId, characterGroupId);
107-
var groupIds = await GetChildrenGroupIds(projectId, characterGroupId);
108-
var characters =
109-
(await ProjectRepository.GetCharacterByGroups(projectId, groupIds)).Where(ch => ch.IsActive).ToList();
110100

111101
if (characterGroup == null)
112102
{
113103
return NotFound();
114104
}
115105

106+
var groupIds = characterGroup.GetChildrenGroupsRecursive().Select(g => g.CharacterGroupId).Append(characterGroupId).ToArray();
107+
var characters = (await ProjectRepository.GetCharacterByGroups(projectId, groupIds)).Where(ch => ch.IsActive).ToList();
108+
116109
var plots = await PlotRepository.GetPlotsWithTargets(projectId);
117110
var projectInfo = await projectMetadataRepository.GetProjectMetadata(new(projectId));
118111

src/JoinRpg.Portal/Models/MainMenuViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ namespace JoinRpg.Portal.Models;
44

55
public class MainMenuViewModel
66
{
7-
public List<MainMenuProjectLinkViewModel> ProjectLinks { get; set; }
7+
public required List<MainMenuProjectLinkViewModel> ProjectLinks { get; set; }
88
}

src/JoinRpg.Portal/TagHelpers/NavigationItemTagHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ public override async void Process(TagHelperContext context, TagHelperOutput out
3838

3939
private bool ShouldBeActive()
4040
{
41-
var currentController = ViewContext.RouteData.Values["Controller"].ToString();
42-
var currentAction = ViewContext.RouteData.Values["Action"].ToString();
41+
var currentController = ViewContext.RouteData.Values["Controller"]?.ToString();
42+
var currentAction = ViewContext.RouteData.Values["Action"]?.ToString();
4343

44-
if (!string.IsNullOrWhiteSpace(Controller) && Controller.ToLower() != currentController.ToLower())
44+
if (!string.IsNullOrWhiteSpace(Controller) && Controller.ToLower() != currentController?.ToLower())
4545
{
4646
return false;
4747
}
4848

49-
if (!string.IsNullOrWhiteSpace(Action) && Action.ToLower() != currentAction.ToLower())
49+
if (!string.IsNullOrWhiteSpace(Action) && Action.ToLower() != currentAction?.ToLower())
5050
{
5151
return false;
5252
}
5353

5454
foreach (KeyValuePair<string, string> routeValue in RouteValues)
5555
{
56-
if (!ViewContext.RouteData.Values.ContainsKey(routeValue.Key) || ViewContext.RouteData.Values[routeValue.Key].ToString() != routeValue.Value)
56+
if (!ViewContext.RouteData.Values.ContainsKey(routeValue.Key) || ViewContext.RouteData.Values[routeValue.Key]?.ToString() != routeValue.Value)
5757
{
5858
return false;
5959
}
@@ -70,7 +70,7 @@ private void MakeActive(TagHelperOutput output)
7070
classAttr = new TagHelperAttribute("class", "active");
7171
output.Attributes.Add(classAttr);
7272
}
73-
else if (classAttr.Value == null || classAttr.Value.ToString().IndexOf("active") < 0)
73+
else if (classAttr.Value.ToString() == null || classAttr.Value.ToString().IndexOf("active") < 0)
7474
{
7575
output.Attributes.SetAttribute("class", classAttr.Value == null
7676
? "active"

src/JoinRpg.Portal/Views/Finances/_PaymentTypesPartial.cshtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
}
1616
<table class="table" style="margin-top: 1em;">
1717
<tr>
18-
<th>@Html.DisplayNameFor(model => paymentType.Name)</th>
19-
<th>@Html.DisplayNameFor(model => paymentType.Master)</th>
18+
<th>@Html.DisplayNameFor(model => paymentType!.Name)</th>
19+
<th>@Html.DisplayNameFor(model => paymentType!.Master)</th>
2020
@if (Model.HasEditAccess)
2121
{
2222
<th></th>
@@ -30,7 +30,7 @@
3030
<span style="display: inline-flex; align-items: center;">
3131
@if (item.IsDefault)
3232
{
33-
<span class="label label-default" style="margin-right: 0.5em">@Html.DisplayNameFor(model => paymentType.IsDefault)</span>
33+
<span class="label label-default" style="margin-right: 0.5em">@Html.DisplayNameFor(model => paymentType!.IsDefault)</span>
3434
}
3535
<span class="@(item.IsActive ? "" : "deleted")">@(item.Name)</span>
3636
</span>

src/JoinRpg.Services.Interfaces/Notification/PlotEmail.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace JoinRpg.Services.Interfaces.Notification;
55
public class PlotElementEmail : EmailModelBase
66
{
77

8-
public PlotElement PlotElement { get; set; }
8+
public required PlotElement PlotElement { get; set; }
99

10-
public IEnumerable<Claim> Claims { get; set; }
10+
public required IEnumerable<Claim> Claims { get; set; }
1111

1212
}
1313

0 commit comments

Comments
 (0)