Fixed half of warnings having to do with allowing Null string objects. (#791)
This commit is contained in:
@@ -24,24 +24,24 @@ public class LoginModel : PageModel
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public InputModel Input { get; set; }
|
||||
public InputModel? Input { get; set; }
|
||||
|
||||
public IList<AuthenticationScheme> ExternalLogins { get; set; }
|
||||
public IList<AuthenticationScheme>? ExternalLogins { get; set; }
|
||||
|
||||
public string ReturnUrl { get; set; }
|
||||
public string? ReturnUrl { get; set; }
|
||||
|
||||
[TempData]
|
||||
public string ErrorMessage { get; set; }
|
||||
public string? ErrorMessage { get; set; }
|
||||
|
||||
public class InputModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
public string Email { get; set; }
|
||||
public string? Email { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
public string Password { get; set; }
|
||||
public string? Password { get; set; }
|
||||
|
||||
[Display(Name = "Remember me?")]
|
||||
public bool RememberMe { get; set; }
|
||||
@@ -101,7 +101,7 @@ public class LoginModel : PageModel
|
||||
return Page();
|
||||
}
|
||||
|
||||
private async Task TransferAnonymousBasketToUserAsync(string userName)
|
||||
private async Task TransferAnonymousBasketToUserAsync(string? userName)
|
||||
{
|
||||
if (Request.Cookies.ContainsKey(Constants.BASKET_COOKIENAME))
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ public class LogoutModel : PageModel
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPost(string returnUrl = null)
|
||||
public async Task<IActionResult> OnPost(string? returnUrl = null)
|
||||
{
|
||||
await _signInManager.SignOutAsync();
|
||||
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
|
||||
@@ -34,35 +34,35 @@ public class RegisterModel : PageModel
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public InputModel Input { get; set; }
|
||||
public InputModel? Input { get; set; }
|
||||
|
||||
public string ReturnUrl { get; set; }
|
||||
public string? ReturnUrl { get; set; }
|
||||
|
||||
public class InputModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[Display(Name = "Email")]
|
||||
public string Email { get; set; }
|
||||
public string? Email { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Password")]
|
||||
public string Password { get; set; }
|
||||
public string? Password { get; set; }
|
||||
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Confirm password")]
|
||||
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
|
||||
public string ConfirmPassword { get; set; }
|
||||
public string? ConfirmPassword { get; set; }
|
||||
}
|
||||
|
||||
public void OnGet(string returnUrl = null)
|
||||
public void OnGet(string? returnUrl = null)
|
||||
{
|
||||
ReturnUrl = returnUrl;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
|
||||
public async Task<IActionResult> OnPostAsync(string? returnUrl = null)
|
||||
{
|
||||
returnUrl = returnUrl ?? Url.Content("~/");
|
||||
if (ModelState.IsValid)
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ManageController : Controller
|
||||
}
|
||||
|
||||
[TempData]
|
||||
public string StatusMessage { get; set; }
|
||||
public string? StatusMessage { get; set; }
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> MyAccount()
|
||||
@@ -377,7 +377,7 @@ public class ManageController : Controller
|
||||
[HttpGet]
|
||||
public IActionResult ShowRecoveryCodes()
|
||||
{
|
||||
var recoveryCodes = (string[])TempData[RecoveryCodesKey];
|
||||
var recoveryCodes = (string[]?)TempData[RecoveryCodesKey];
|
||||
if (recoveryCodes == null)
|
||||
{
|
||||
return RedirectToAction(nameof(TwoFactorAuthentication));
|
||||
|
||||
@@ -4,7 +4,7 @@ public class BasketViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public List<BasketItemViewModel> Items { get; set; } = new List<BasketItemViewModel>();
|
||||
public string BuyerId { get; set; }
|
||||
public string? BuyerId { get; set; }
|
||||
|
||||
public decimal Total()
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ public class CheckoutModel : PageModel
|
||||
private readonly IBasketService _basketService;
|
||||
private readonly SignInManager<ApplicationUser> _signInManager;
|
||||
private readonly IOrderService _orderService;
|
||||
private string _username = null;
|
||||
private string? _username = null;
|
||||
private readonly IBasketViewModelService _basketViewModelService;
|
||||
private readonly IAppLogger<CheckoutModel> _logger;
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class IndexModel : PageModel
|
||||
|
||||
private string GetOrSetBasketCookieAndUserName()
|
||||
{
|
||||
string userName = null;
|
||||
string? userName = null;
|
||||
|
||||
if (Request.HttpContext.User.Identity.IsAuthenticated)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Microsoft.eShopWeb.Web.Pages;
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public class ErrorModel : PageModel
|
||||
{
|
||||
public string RequestId { get; set; }
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Microsoft.eShopWeb.Web;
|
||||
|
||||
public class SlugifyParameterTransformer : IOutboundParameterTransformer
|
||||
{
|
||||
public string TransformOutbound(object value)
|
||||
public string? TransformOutbound(object value)
|
||||
{
|
||||
if (value == null) { return null; }
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ public class LoginViewModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
public string Email { get; set; }
|
||||
public string? Email { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
public string Password { get; set; }
|
||||
public string? Password { get; set; }
|
||||
|
||||
[Display(Name = "Remember me?")]
|
||||
public bool RememberMe { get; set; }
|
||||
|
||||
@@ -8,7 +8,7 @@ public class LoginWith2faViewModel
|
||||
[StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||
[DataType(DataType.Text)]
|
||||
[Display(Name = "Authenticator code")]
|
||||
public string TwoFactorCode { get; set; }
|
||||
public string? TwoFactorCode { get; set; }
|
||||
|
||||
[Display(Name = "Remember this machine")]
|
||||
public bool RememberMachine { get; set; }
|
||||
|
||||
@@ -7,16 +7,16 @@ public class RegisterViewModel
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[Display(Name = "Email")]
|
||||
public string Email { get; set; }
|
||||
public string? Email { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Password")]
|
||||
public string Password { get; set; }
|
||||
public string? Password { get; set; }
|
||||
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Confirm password")]
|
||||
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
|
||||
public string ConfirmPassword { get; set; }
|
||||
public string? ConfirmPassword { get; set; }
|
||||
}
|
||||
|
||||
@@ -6,17 +6,17 @@ public class ResetPasswordViewModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
public string Email { get; set; }
|
||||
public string? Email { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||
[DataType(DataType.Password)]
|
||||
public string Password { get; set; }
|
||||
public string? Password { get; set; }
|
||||
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Confirm password")]
|
||||
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
|
||||
public string ConfirmPassword { get; set; }
|
||||
public string? ConfirmPassword { get; set; }
|
||||
|
||||
public string Code { get; set; }
|
||||
public string? Code { get; set; }
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ namespace Microsoft.eShopWeb.Web.ViewModels;
|
||||
|
||||
public class CatalogIndexViewModel
|
||||
{
|
||||
public List<CatalogItemViewModel> CatalogItems { get; set; }
|
||||
public List<SelectListItem> Brands { get; set; }
|
||||
public List<SelectListItem> Types { get; set; }
|
||||
public List<CatalogItemViewModel>? CatalogItems { get; set; }
|
||||
public List<SelectListItem>? Brands { get; set; }
|
||||
public List<SelectListItem>? Types { get; set; }
|
||||
public int? BrandFilterApplied { get; set; }
|
||||
public int? TypesFilterApplied { get; set; }
|
||||
public PaginationInfoViewModel PaginationInfo { get; set; }
|
||||
public PaginationInfoViewModel? PaginationInfo { get; set; }
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
public class CatalogItemViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string PictureUri { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? PictureUri { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
public class FileViewModel
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string DataBase64 { get; set; }
|
||||
public string? FileName { get; set; }
|
||||
public string? Url { get; set; }
|
||||
public string? DataBase64 { get; set; }
|
||||
}
|
||||
|
||||
@@ -7,18 +7,18 @@ public class ChangePasswordViewModel
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Current password")]
|
||||
public string OldPassword { get; set; }
|
||||
public string? OldPassword { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "New password")]
|
||||
public string NewPassword { get; set; }
|
||||
public string? NewPassword { get; set; }
|
||||
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Confirm new password")]
|
||||
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
|
||||
public string ConfirmPassword { get; set; }
|
||||
public string? ConfirmPassword { get; set; }
|
||||
|
||||
public string StatusMessage { get; set; }
|
||||
public string? StatusMessage { get; set; }
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ public class EnableAuthenticatorViewModel
|
||||
[StringLength(7, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||
[DataType(DataType.Text)]
|
||||
[Display(Name = "Verification Code")]
|
||||
public string Code { get; set; }
|
||||
public string? Code { get; set; }
|
||||
|
||||
[BindNever]
|
||||
public string SharedKey { get; set; }
|
||||
public string? SharedKey { get; set; }
|
||||
|
||||
[BindNever]
|
||||
public string AuthenticatorUri { get; set; }
|
||||
public string? AuthenticatorUri { get; set; }
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace Microsoft.eShopWeb.Web.ViewModels.Manage;
|
||||
|
||||
public class ExternalLoginsViewModel
|
||||
{
|
||||
public IList<UserLoginInfo> CurrentLogins { get; set; }
|
||||
public IList<AuthenticationScheme> OtherLogins { get; set; }
|
||||
public IList<UserLoginInfo>? CurrentLogins { get; set; }
|
||||
public IList<AuthenticationScheme>? OtherLogins { get; set; }
|
||||
public bool ShowRemoveButton { get; set; }
|
||||
public string StatusMessage { get; set; }
|
||||
public string? StatusMessage { get; set; }
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ public class IndexViewModel
|
||||
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
public string Email { get; set; }
|
||||
public string? Email { get; set; }
|
||||
|
||||
[Phone]
|
||||
[Display(Name = "Phone number")]
|
||||
public string PhoneNumber { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
|
||||
public string? StatusMessage { get; set; }
|
||||
}
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
public class RemoveLoginViewModel
|
||||
{
|
||||
public string LoginProvider { get; set; }
|
||||
public string ProviderKey { get; set; }
|
||||
public string? LoginProvider { get; set; }
|
||||
public string? ProviderKey { get; set; }
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ public class SetPasswordViewModel
|
||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "New password")]
|
||||
public string NewPassword { get; set; }
|
||||
public string? NewPassword { get; set; }
|
||||
|
||||
[DataType(DataType.Password)]
|
||||
[Display(Name = "Confirm new password")]
|
||||
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
|
||||
public string ConfirmPassword { get; set; }
|
||||
public string? ConfirmPassword { get; set; }
|
||||
|
||||
public string StatusMessage { get; set; }
|
||||
public string? StatusMessage { get; set; }
|
||||
}
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
public class ShowRecoveryCodesViewModel
|
||||
{
|
||||
public string[] RecoveryCodes { get; set; }
|
||||
public string[]? RecoveryCodes { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
public class OrderItemViewModel
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public string ProductName { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal UnitPrice { get; set; }
|
||||
public decimal Discount => 0;
|
||||
public int Units { get; set; }
|
||||
public string PictureUrl { get; set; }
|
||||
public string? PictureUrl { get; set; }
|
||||
}
|
||||
|
||||
@@ -12,6 +12,6 @@ public class OrderViewModel
|
||||
public DateTimeOffset OrderDate { get; set; }
|
||||
public decimal Total { get; set; }
|
||||
public string Status => DEFAULT_STATUS;
|
||||
public Address ShippingAddress { get; set; }
|
||||
public Address? ShippingAddress { get; set; }
|
||||
public List<OrderItemViewModel> OrderItems { get; set; } = new List<OrderItemViewModel>();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ public class PaginationInfoViewModel
|
||||
public int ItemsPerPage { get; set; }
|
||||
public int ActualPage { get; set; }
|
||||
public int TotalPages { get; set; }
|
||||
public string Previous { get; set; }
|
||||
public string Next { get; set; }
|
||||
public string? Previous { get; set; }
|
||||
public string? Next { get; set; }
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public static class ManageNavPages
|
||||
public static string PageNavClass(ViewContext viewContext, string page)
|
||||
{
|
||||
var activePage = viewContext.ViewData["ActivePage"] as string;
|
||||
return string.Equals(activePage, page, StringComparison.OrdinalIgnoreCase) ? "active" : null;
|
||||
return string.Equals(activePage, page, StringComparison.OrdinalIgnoreCase) ? "active" : string.Empty;
|
||||
}
|
||||
|
||||
public static void AddActivePage(this ViewDataDictionary viewData, string activePage) => viewData[ActivePageKey] = activePage;
|
||||
|
||||
Reference in New Issue
Block a user