Skip to content

Commit bc2e61a

Browse files
committed
Dotnet 9 syntax.
1 parent 6a78671 commit bc2e61a

8 files changed

+24
-27
lines changed

SkredvarselGarminWeb/SkredvarselGarminWeb/Endpoints/ForecastAreaEndpointsRouteBuilderExtensions.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ public static void MapForecastAreaEndpoints(this IEndpointRouteBuilder app)
2626

2727
var geometry = serializer.Deserialize<FeatureCollection>(jsonReader);
2828

29-
if (geometry == null)
30-
{
31-
return Results.BadRequest("Invalid GeoJSON");
32-
}
33-
34-
return Results.Ok(forecastAreaService.ReplaceForecastAreas(geometry));
29+
return geometry == null ?
30+
Results.BadRequest("Invalid GeoJSON") :
31+
Results.Ok(forecastAreaService.ReplaceForecastAreas(geometry));
3532
}).DisableAntiforgery().RequireAuthorization("Admin");
3633
}
3734
}

SkredvarselGarminWeb/SkredvarselGarminWeb/Endpoints/StripeSubscriptionEndpointsRouteBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void MapStripeSubscriptionEndpoints(this IEndpointRouteBuilder app
4242
SuccessUrl = $"{baseUrl}/stripe-subscribe-callback?session_id={{CHECKOUT_SESSION_ID}}",
4343
CancelUrl = $"{baseUrl}/account",
4444
Mode = "subscription",
45-
CustomerEmail = string.IsNullOrEmpty(user.StripeCustomerId) ? user.Email : null,
45+
CustomerEmail = user.StripeCustomerId is { Length: > 0 } ? user.Email : null,
4646
Customer = user.StripeCustomerId,
4747
ClientReferenceId = user.Id,
4848
LineItems = [

SkredvarselGarminWeb/SkredvarselGarminWeb/Endpoints/SubscriptionEndpointsRouteBuilderExtensions.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,14 @@ public static void MapSubscriptionApiEndpoints(this IEndpointRouteBuilder app)
7171
var activeStripeSubscription = stripeSubscriptionsInDb
7272
.FirstOrDefault(ss => ss.Status == Entities.StripeSubscriptionStatus.ACTIVE
7373
|| ss.Status == Entities.StripeSubscriptionStatus.UNSUBSCRIBED);
74-
if (activeStripeSubscription != null)
75-
{
76-
return Results.Ok(new SubscriptionResponse
74+
return activeStripeSubscription != null
75+
? Results.Ok(new SubscriptionResponse
7776
{
7877
SubscriptionType = SubscriptionType.Stripe,
7978
StripeSubscriptionStatus = activeStripeSubscription.Status,
8079
NextChargeDate = activeStripeSubscription.NextChargeDate,
81-
});
82-
}
83-
84-
return Results.NoContent();
80+
})
81+
: Results.NoContent();
8582
}).RequireAuthorization();
8683
}
8784
}

SkredvarselGarminWeb/SkredvarselGarminWeb/Endpoints/VippsSubscriptionEndpointsRouteBuilderExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,15 @@ public static void MapVippsSubscriptionEndpoints(this IEndpointRouteBuilder app)
145145
vippsAgreement = await vippsApiClient.GetAgreement(agreement.Id);
146146
}
147147

148-
if (vippsAgreement.Status == VippsAgreementStatus.Stopped ||
149-
vippsAgreement.Status == VippsAgreementStatus.Expired)
148+
if (vippsAgreement.Status is
149+
VippsAgreementStatus.Stopped or
150+
VippsAgreementStatus.Expired)
150151
{
151152
dbContext.Remove(agreement);
152153
}
153154
else if (vippsAgreement.Status == VippsAgreementStatus.Active)
154155
{
155-
if (string.IsNullOrEmpty(agreement.UserId))
156+
if (agreement.UserId is { Length: > 0 })
156157
{
157158
var signedInUser = dbContext.GetUserOrNull(ctx.User);
158159
if (signedInUser != null)

SkredvarselGarminWeb/SkredvarselGarminWeb/Endpoints/WatchApiRouteBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static void MapWatchApiEndpoints(this IEndpointRouteBuilder app)
7474
[FromHeader(Name = "Authorization")] string authorizationHeader,
7575
IGarminAuthenticationService garminAuthenticationService) =>
7676
{
77-
if (string.IsNullOrEmpty(authorizationHeader))
77+
if (authorizationHeader is { Length: > 0 })
7878
{
7979
return Results.Unauthorized();
8080
}

SkredvarselGarminWeb/SkredvarselGarminWeb/Hangfire/HangfireService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ public async Task RemoveStalePendingAgreements()
4747
{
4848
var vippsAgreement = await vippsApiClient.GetAgreement(agreement.Id);
4949

50-
if (vippsAgreement.Status == VippsAgreementStatus.Expired ||
51-
vippsAgreement.Status == VippsAgreementStatus.Stopped)
50+
if (vippsAgreement.Status is
51+
VippsAgreementStatus.Expired or
52+
VippsAgreementStatus.Stopped)
5253
{
5354
logger.LogInformation("Deleting stale agreement {agreementId} since it was expired in Vipps.", agreement.Id);
5455
dbContext.Remove(agreement);

SkredvarselGarminWeb/SkredvarselGarminWeb/Services/StripeService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ public void HandleWebhook(Event stripeEvent)
3434
StoreNewSubscriptionIfNotExists(session);
3535
}
3636
else if (
37-
stripeEvent.Type == EventTypes.CustomerSubscriptionUpdated ||
38-
stripeEvent.Type == EventTypes.CustomerSubscriptionDeleted ||
39-
stripeEvent.Type == EventTypes.CustomerSubscriptionPaused ||
40-
stripeEvent.Type == EventTypes.CustomerSubscriptionResumed)
37+
stripeEvent.Type is
38+
EventTypes.CustomerSubscriptionUpdated or
39+
EventTypes.CustomerSubscriptionDeleted or
40+
EventTypes.CustomerSubscriptionPaused or
41+
EventTypes.CustomerSubscriptionResumed)
4142
{
4243
var subscription = (Subscription)stripeEvent.Data.Object;
4344
HandleSubscriptionUpdated(subscription);

SkredvarselGarminWeb/SkredvarselGarminWeb/Services/VippsAgreementService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ private async Task<CreateChargeResponse> CreateChargeInVipps(string agreementId,
349349
{
350350
var campaign = vippsAgreement.Campaign;
351351

352-
if (campaign.Type == VippsCampaignType.PeriodCampaign)
352+
if (campaign.Type is VippsCampaignType.PeriodCampaign)
353353
{
354354
var periodEndDate = GetNextChargeDate(DateOnly.FromDateTime(vippsAgreement.Start!.Value), campaign.Period!.Unit, campaign.Period!.Count);
355355

@@ -365,7 +365,7 @@ private async Task<CreateChargeResponse> CreateChargeInVipps(string agreementId,
365365
return charge;
366366
}
367367
}
368-
else if (campaign.Type == VippsCampaignType.PriceCampaign && now < campaign.End)
368+
else if (campaign.Type is VippsCampaignType.PriceCampaign && now < campaign.End)
369369
{
370370
var nextChargeDate = DateOnly.FromDateTime(now) < previousChargeDate ? previousChargeDate : GetNextChargeDate(previousChargeDate, vippsAgreement.Interval.Unit, vippsAgreement.Interval.Count);
371371

@@ -379,7 +379,7 @@ private async Task<CreateChargeResponse> CreateChargeInVipps(string agreementId,
379379

380380
return charge;
381381
}
382-
else if (campaign.Type == VippsCampaignType.EventCampaign || campaign.Type == VippsCampaignType.FullFlexCampaign)
382+
else if (campaign.Type is VippsCampaignType.EventCampaign or VippsCampaignType.FullFlexCampaign)
383383
{
384384
throw new Exception("Unsupported campaign type");
385385
}

0 commit comments

Comments
 (0)