Skip to content

Commit

Permalink
remove some nullwarnings (#2842)
Browse files Browse the repository at this point in the history
  • Loading branch information
leotsarev authored Oct 16, 2024
1 parent 35c8085 commit 535d6d1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
6 changes: 4 additions & 2 deletions src/JoinRpg.Domain/ProjectEntityExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Linq.Expressions;
using JoinRpg.DataModel;
Expand Down Expand Up @@ -30,7 +31,7 @@ public static bool HasMasterAccess(this IProjectEntity entity, ICurrentUserAcces
return entity.HasMasterAccess(currentUserAccessor.UserIdOrDefault, acl => true);
}

public static T RequestMasterAccess<T>(this T field,
public static T RequestMasterAccess<T>([NotNull] this T? field,
int? currentUserId,
Expression<Func<ProjectAcl, bool>>? accessType = null)
where T : IProjectEntity
Expand All @@ -56,8 +57,9 @@ public static T RequestMasterAccess<T>(this T field,
return field;
}

public static T EnsureActive<T>(this T entity) where T : IDeletableSubEntity, IProjectEntity
public static T EnsureActive<T>([NotNull] this T? entity) where T : IDeletableSubEntity, IProjectEntity
{
ArgumentNullException.ThrowIfNull(entity);
if (!entity.IsActive)
{
throw new ProjectEntityDeactivatedException(entity);
Expand Down
12 changes: 7 additions & 5 deletions src/JoinRpg.Portal/Controllers/CharacterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ await CharacterService.EditCharacter(
[MasterAuthorize(Permission.CanEditRoles)]
public async Task<ActionResult> Create(int projectid, int? charactergroupid, bool continueCreating = false)
{
CharacterGroup characterGroup;
CharacterGroup? characterGroup;
if (charactergroupid is null)
{
characterGroup = await ProjectRepository.GetRootGroupAsync(projectid);
Expand Down Expand Up @@ -180,17 +180,19 @@ await CharacterService.AddCharacter(new AddCharacterRequest(
catch (Exception exception)
{
ModelState.AddException(exception);
CharacterGroup characterGroup;
CharacterGroup? characterGroup;
if (characterGroupId == 0)
{
characterGroup = (await ProjectRepository.GetProjectAsync(viewModel.ProjectId))
.RootGroup;
}
else
{
characterGroup =
await ProjectRepository.GetGroupAsync(viewModel.ProjectId,
characterGroupId);
characterGroup = await ProjectRepository.GetGroupAsync(viewModel.ProjectId, characterGroupId);
if (characterGroup is null)
{
return NotFound();
}
}

var projectInfo = await projectMetadataRepository.GetProjectMetadata(new ProjectIdentification(viewModel.ProjectId));
Expand Down
13 changes: 3 additions & 10 deletions src/JoinRpg.Portal/Controllers/CharacterListController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,19 @@ public CharacterListController(
ExportDataService = exportDataService;
}


private async Task<int[]> GetChildrenGroupIds(int projectId, int characterGroupId)
{
var groups = await ProjectRepository.GetGroupAsync(projectId, characterGroupId);
return groups.GetChildrenGroupsRecursive().Select(g => g.CharacterGroupId).Append(characterGroupId).ToArray();
}

[HttpGet("~/{ProjectId}/characters/bygroup/{CharacterGroupId}")]
public async Task<ActionResult> ByGroup(int projectId, int characterGroupId, string export)
{
var characterGroup = await ProjectRepository.GetGroupAsync(projectId, characterGroupId);
var groupIds = await GetChildrenGroupIds(projectId, characterGroupId);
var characters =
(await ProjectRepository.GetCharacterByGroups(projectId, groupIds)).Where(ch => ch.IsActive).ToList();

if (characterGroup == null)
{
return NotFound();
}

var groupIds = characterGroup.GetChildrenGroupsRecursive().Select(g => g.CharacterGroupId).Append(characterGroupId).ToArray();
var characters = (await ProjectRepository.GetCharacterByGroups(projectId, groupIds)).Where(ch => ch.IsActive).ToList();

var plots = await PlotRepository.GetPlotsWithTargets(projectId);
var projectInfo = await projectMetadataRepository.GetProjectMetadata(new(projectId));

Expand Down
2 changes: 1 addition & 1 deletion src/JoinRpg.Portal/Models/MainMenuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace JoinRpg.Portal.Models;

public class MainMenuViewModel
{
public List<MainMenuProjectLinkViewModel> ProjectLinks { get; set; }
public required List<MainMenuProjectLinkViewModel> ProjectLinks { get; set; }
}
12 changes: 6 additions & 6 deletions src/JoinRpg.Portal/TagHelpers/NavigationItemTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ public override async void Process(TagHelperContext context, TagHelperOutput out

private bool ShouldBeActive()
{
var currentController = ViewContext.RouteData.Values["Controller"].ToString();
var currentAction = ViewContext.RouteData.Values["Action"].ToString();
var currentController = ViewContext.RouteData.Values["Controller"]?.ToString();
var currentAction = ViewContext.RouteData.Values["Action"]?.ToString();

if (!string.IsNullOrWhiteSpace(Controller) && Controller.ToLower() != currentController.ToLower())
if (!string.IsNullOrWhiteSpace(Controller) && Controller.ToLower() != currentController?.ToLower())
{
return false;
}

if (!string.IsNullOrWhiteSpace(Action) && Action.ToLower() != currentAction.ToLower())
if (!string.IsNullOrWhiteSpace(Action) && Action.ToLower() != currentAction?.ToLower())
{
return false;
}

foreach (KeyValuePair<string, string> routeValue in RouteValues)
{
if (!ViewContext.RouteData.Values.ContainsKey(routeValue.Key) || ViewContext.RouteData.Values[routeValue.Key].ToString() != routeValue.Value)
if (!ViewContext.RouteData.Values.ContainsKey(routeValue.Key) || ViewContext.RouteData.Values[routeValue.Key]?.ToString() != routeValue.Value)
{
return false;
}
Expand All @@ -70,7 +70,7 @@ private void MakeActive(TagHelperOutput output)
classAttr = new TagHelperAttribute("class", "active");
output.Attributes.Add(classAttr);
}
else if (classAttr.Value == null || classAttr.Value.ToString().IndexOf("active") < 0)
else if (classAttr.Value.ToString() == null || classAttr.Value.ToString().IndexOf("active") < 0)
{
output.Attributes.SetAttribute("class", classAttr.Value == null
? "active"
Expand Down
6 changes: 3 additions & 3 deletions src/JoinRpg.Portal/Views/Finances/_PaymentTypesPartial.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
}
<table class="table" style="margin-top: 1em;">
<tr>
<th>@Html.DisplayNameFor(model => paymentType.Name)</th>
<th>@Html.DisplayNameFor(model => paymentType.Master)</th>
<th>@Html.DisplayNameFor(model => paymentType!.Name)</th>
<th>@Html.DisplayNameFor(model => paymentType!.Master)</th>
@if (Model.HasEditAccess)
{
<th></th>
Expand All @@ -30,7 +30,7 @@
<span style="display: inline-flex; align-items: center;">
@if (item.IsDefault)
{
<span class="label label-default" style="margin-right: 0.5em">@Html.DisplayNameFor(model => paymentType.IsDefault)</span>
<span class="label label-default" style="margin-right: 0.5em">@Html.DisplayNameFor(model => paymentType!.IsDefault)</span>
}
<span class="@(item.IsActive ? "" : "deleted")">@(item.Name)</span>
</span>
Expand Down
4 changes: 2 additions & 2 deletions src/JoinRpg.Services.Interfaces/Notification/PlotEmail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace JoinRpg.Services.Interfaces.Notification;
public class PlotElementEmail : EmailModelBase
{

public PlotElement PlotElement { get; set; }
public required PlotElement PlotElement { get; set; }

public IEnumerable<Claim> Claims { get; set; }
public required IEnumerable<Claim> Claims { get; set; }

}

Expand Down

0 comments on commit 535d6d1

Please sign in to comment.