Przeglądaj źródła

Changed from == null to is null, better for null checking.

master
rodzic
commit
815b0303e3

+ 2
- 2
SecureSharing.Business/Infrastructure/StartupConfiguration.cs Wyświetl plik

@@ -9,10 +9,10 @@ public sealed class StartupConfiguration
public static TConfig ConfigureStartupConfig<TConfig>(IServiceCollection services, IConfiguration configuration)
where TConfig : class, new()
{
if (services == null)
if (services is null)
throw new ArgumentNullException(nameof(services));

if (configuration == null)
if (configuration is null)
throw new ArgumentNullException(nameof(configuration));

//create instance of config

+ 8
- 18
SecureSharing.Business/Services/MessageService.cs Wyświetl plik

@@ -26,24 +26,14 @@ public sealed class MessageService : IMessageService
public async Task<int> Create(MessageDto messageDto, PeriodOfValidity chosenPeriod)
{
var message = _mapper.Map<Message>(messageDto);
switch (chosenPeriod)
message.ExpiryDate = chosenPeriod switch
{
case PeriodOfValidity.ONE_TIME:
message.ExpiryDate = null;
break;
case PeriodOfValidity.ONE_DAY:
message.ExpiryDate = DateTime.UtcNow.AddMinutes(1);
break;
case PeriodOfValidity.ONE_HOUR:
message.ExpiryDate = DateTime.UtcNow.AddHours(1);
break;
case PeriodOfValidity.ONE_WEEK:
message.ExpiryDate = DateTime.UtcNow.AddDays(7);
break;
default:
message.ExpiryDate = null;
break;
}
PeriodOfValidity.ONE_TIME => null,
PeriodOfValidity.ONE_DAY => DateTime.UtcNow.AddMinutes(1),
PeriodOfValidity.ONE_HOUR => DateTime.UtcNow.AddHours(1),
PeriodOfValidity.ONE_WEEK => DateTime.UtcNow.AddDays(7),
_ => null
};

await _dbContext.Messages.AddAsync(message);
await _dbContext.SaveChangesAsync();
@@ -69,7 +59,7 @@ public sealed class MessageService : IMessageService
public async Task<bool> Delete(int messageId)
{
var messageDto = await GetById(messageId);
if (messageDto == null) return false;
if (messageDto is null) return false;
_dbContext.Set<Message>().Remove(_mapper.Map<Message>(messageDto));
try
{

+ 2
- 2
SecureSharing/Areas/Identity/Pages/Account/ResetPassword.cshtml.cs Wyświetl plik

@@ -21,7 +21,7 @@ public sealed class ResetPasswordModel : PageModel

public IActionResult OnGet(string code = null)
{
if (code == null)
if (code is null)
{
return BadRequest("A code must be supplied for password reset.");
}
@@ -38,7 +38,7 @@ public sealed class ResetPasswordModel : PageModel
if (!ModelState.IsValid) return Page();

var user = await _userManager.FindByEmailAsync(Input.Email);
if (user == null)
if (user is null)
// Don't reveal that the user does not exist
return RedirectToPage("./ResetPasswordConfirmation");


+ 1
- 3
SecureSharing/Infrastructure/ModelFactory.cs Wyświetl plik

@@ -1,6 +1,4 @@
using System;
using System.Threading.Tasks;
using SecureSharing.Business.Interfaces;
using SecureSharing.Business.Interfaces;
using SecureSharing.Models;

namespace SecureSharing.Infrastructure;

Ładowanie…
Anuluj
Zapisz