V10: Build warnings in Web.Website (#12332)

* add new rule to globalconfig

* Fix warnings in Web.Website

* Fix more warnings in Web.Website

* Fix more build warnings in Web.Website

* Fix more warnings in Web.Website

* Fix tests

* Fix proper constructor call

* Fix not being able to run project

* Fix Obsolete method

Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk>
This commit is contained in:
Nikolaj Geisle
2022-05-06 15:06:39 +02:00
committed by GitHub
parent b648177a40
commit 4f3d680f06
47 changed files with 3525 additions and 3447 deletions

View File

@@ -1,67 +1,67 @@
using System;
using System.Linq;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
namespace Umbraco.Cms.Web.Website.Models
namespace Umbraco.Cms.Web.Website.Models;
/// <summary>
/// Builds a <see cref="RegisterModel" /> for use on the front-end
/// </summary>
public class RegisterModelBuilder : MemberModelBuilderBase
{
private bool _lookupProperties;
private string? _memberTypeAlias;
private string? _redirectUrl;
private bool _usernameIsEmail;
/// <summary>
/// Builds a <see cref="RegisterModel"/> for use on the front-end
/// </summary>
public class RegisterModelBuilder : MemberModelBuilderBase
public RegisterModelBuilder(IMemberTypeService memberTypeService, IShortStringHelper shortStringHelper)
: base(memberTypeService, shortStringHelper)
{
private string? _memberTypeAlias;
private bool _lookupProperties;
private bool _usernameIsEmail;
private string? _redirectUrl;
}
public RegisterModelBuilder(IMemberTypeService memberTypeService, IShortStringHelper shortStringHelper)
: base(memberTypeService, shortStringHelper)
public RegisterModelBuilder WithRedirectUrl(string? redirectUrl)
{
_redirectUrl = redirectUrl;
return this;
}
public RegisterModelBuilder UsernameIsEmail(bool usernameIsEmail = true)
{
_usernameIsEmail = usernameIsEmail;
return this;
}
public RegisterModelBuilder WithMemberTypeAlias(string memberTypeAlias)
{
_memberTypeAlias = memberTypeAlias;
return this;
}
public RegisterModelBuilder WithCustomProperties(bool lookupProperties)
{
_lookupProperties = lookupProperties;
return this;
}
public RegisterModel Build()
{
var providedOrDefaultMemberTypeAlias = _memberTypeAlias ?? Constants.Conventions.MemberTypes.DefaultAlias;
IMemberType? memberType = MemberTypeService.Get(providedOrDefaultMemberTypeAlias);
if (memberType == null)
{
throw new InvalidOperationException(
$"Could not find a member type with alias: {providedOrDefaultMemberTypeAlias}.");
}
public RegisterModelBuilder WithRedirectUrl(string redirectUrl)
var model = new RegisterModel
{
_redirectUrl = redirectUrl;
return this;
}
public RegisterModelBuilder UsernameIsEmail(bool usernameIsEmail = true)
{
_usernameIsEmail = usernameIsEmail;
return this;
}
public RegisterModelBuilder WithMemberTypeAlias(string memberTypeAlias)
{
_memberTypeAlias = memberTypeAlias;
return this;
}
public RegisterModelBuilder WithCustomProperties(bool lookupProperties)
{
_lookupProperties = lookupProperties;
return this;
}
public RegisterModel Build()
{
var providedOrDefaultMemberTypeAlias = _memberTypeAlias ?? Core.Constants.Conventions.MemberTypes.DefaultAlias;
IMemberType? memberType = MemberTypeService.Get(providedOrDefaultMemberTypeAlias);
if (memberType == null)
{
throw new InvalidOperationException($"Could not find a member type with alias: {providedOrDefaultMemberTypeAlias}.");
}
var model = new RegisterModel
{
MemberTypeAlias = providedOrDefaultMemberTypeAlias,
UsernameIsEmail = _usernameIsEmail,
MemberProperties = _lookupProperties ? GetMemberPropertiesViewModel(memberType) : Enumerable.Empty<MemberPropertyModel>().ToList()
};
return model;
}
MemberTypeAlias = providedOrDefaultMemberTypeAlias,
UsernameIsEmail = _usernameIsEmail,
MemberProperties = _lookupProperties
? GetMemberPropertiesViewModel(memberType)
: Enumerable.Empty<MemberPropertyModel>().ToList(),
};
return model;
}
}