Skip to content

Commit

Permalink
Add null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bolatovumar committed Aug 28, 2022
1 parent 41814d0 commit 5f2b179
Showing 1 changed file with 11 additions and 4 deletions.
@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -121,12 +122,12 @@ public async Task<IActionResult> ContributeToCrowdfund(string appId, ContributeT
var store = await _appService.GetStore(app);
var title = settings.Title;
decimal? price = request.Amount;
Dictionary<string, InvoiceSupportedTransactionCurrency> paymentMethods = null;
ViewPointOfSaleViewModel.Item choice = null;
Dictionary<string, InvoiceSupportedTransactionCurrency>? paymentMethods = null;
ViewPointOfSaleViewModel.Item? choice = null;
if (!string.IsNullOrEmpty(request.ChoiceKey))
{
var choices = _appService.GetPOSItems(settings.PerksTemplate, settings.TargetCurrency);
choice = choices.FirstOrDefault(c => c.Id == request.ChoiceKey);
choice = choices?.FirstOrDefault(c => c.Id == request.ChoiceKey);
if (choice == null)
return NotFound("Incorrect option provided");
title = choice.Title;
Expand Down Expand Up @@ -379,7 +380,13 @@ private async Task<string> GetStoreDefaultCurrentIfEmpty(string storeId, string
{
if (string.IsNullOrWhiteSpace(currency))
{
currency = (await _storeRepository.FindStore(storeId)).GetStoreBlob().DefaultCurrency;
var store = await _storeRepository.FindStore(storeId);
if (store == null)
{
throw new Exception($"Could not find store with id {storeId}");
}

currency = store.GetStoreBlob().DefaultCurrency;
}
return currency.Trim().ToUpperInvariant();
}
Expand Down

0 comments on commit 5f2b179

Please sign in to comment.