diff --git a/Packages.props b/Packages.props index 3bf36c705..2b899c196 100644 --- a/Packages.props +++ b/Packages.props @@ -35,9 +35,9 @@ - - + + - + diff --git a/src/Feature/Selections/rendering/Attributes/HttpsUrlAttribute.cs b/src/Feature/Selections/rendering/Attributes/HttpsUrlAttribute.cs new file mode 100644 index 000000000..336c97372 --- /dev/null +++ b/src/Feature/Selections/rendering/Attributes/HttpsUrlAttribute.cs @@ -0,0 +1,21 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace Mvp.Feature.Selections.Attributes +{ + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)] + public class HttpsUrlAttribute() + : ValidationAttribute("The field {0} must be a Url starting with 'https'.") + { + public override bool IsValid(object value) + { + if (value == null) + { + return true; + } + + return value is string valueAsString && + valueAsString.StartsWith("https://", StringComparison.OrdinalIgnoreCase); + } + } +} diff --git a/src/Feature/Selections/rendering/Models/Admin/ApplicationReviewSettingsModel.cs b/src/Feature/Selections/rendering/Models/Admin/ApplicationReviewSettingsModel.cs index 53194a0a8..edf9f6840 100644 --- a/src/Feature/Selections/rendering/Models/Admin/ApplicationReviewSettingsModel.cs +++ b/src/Feature/Selections/rendering/Models/Admin/ApplicationReviewSettingsModel.cs @@ -35,7 +35,7 @@ public class ApplicationReviewSettingsModel : BaseModel public TextField AddReviewerUserEmailLabel { get; set; } - public List AddReviewerUserEmails { get; set; } = new (); + public List AddReviewerUserEmails { get; set; } = []; public Guid? RemoveReviewerUserId { get; set; } @@ -45,6 +45,6 @@ public class ApplicationReviewSettingsModel : BaseModel public Application Application { get; set; } - public List Reviewers { get; set; } = new (); + public List Reviewers { get; set; } = []; } } diff --git a/src/Feature/Selections/rendering/Models/Admin/ApplicationsOverviewModel.cs b/src/Feature/Selections/rendering/Models/Admin/ApplicationsOverviewModel.cs index 9bf19d983..d527f02af 100644 --- a/src/Feature/Selections/rendering/Models/Admin/ApplicationsOverviewModel.cs +++ b/src/Feature/Selections/rendering/Models/Admin/ApplicationsOverviewModel.cs @@ -40,9 +40,9 @@ public ApplicationsOverviewModel() public TextField ReviewLinkFormat { get; set; } - public List Countries { get; set; } = new (); + public List Countries { get; set; } = []; - public List Selections { get; set; } = new (); + public List Selections { get; set; } = []; public HyperLinkField ReviewSettingsLink { get; set; } diff --git a/src/Feature/Selections/rendering/Models/Admin/AwardModel.cs b/src/Feature/Selections/rendering/Models/Admin/AwardModel.cs index db5ceb6ab..51c261bb9 100644 --- a/src/Feature/Selections/rendering/Models/Admin/AwardModel.cs +++ b/src/Feature/Selections/rendering/Models/Admin/AwardModel.cs @@ -40,9 +40,9 @@ public class AwardModel : BaseModel public Application Application { get; set; } - public List Comments { get; set; } = new (); + public List Comments { get; set; } = []; - public List MvpTypes { get; set; } = new (); + public List MvpTypes { get; set; } = []; public short MvpTypeId { get; set; } diff --git a/src/Feature/Selections/rendering/Models/Admin/ScoreCardDetailModel.cs b/src/Feature/Selections/rendering/Models/Admin/ScoreCardDetailModel.cs index 3496bf8ef..29d00c83b 100644 --- a/src/Feature/Selections/rendering/Models/Admin/ScoreCardDetailModel.cs +++ b/src/Feature/Selections/rendering/Models/Admin/ScoreCardDetailModel.cs @@ -13,11 +13,11 @@ public class ScoreCardDetailModel : BaseModel public Application Application { get; set; } - public List Reviews { get; set; } = new (); + public List Reviews { get; set; } = []; - public List ScoreCategories { get; set; } = new (); + public List ScoreCategories { get; set; } = []; - public List Comments { get; set; } = new (); + public List Comments { get; set; } = []; public TextField TitleLabel { get; set; } diff --git a/src/Feature/Selections/rendering/Models/Admin/ScoreCardsModel.cs b/src/Feature/Selections/rendering/Models/Admin/ScoreCardsModel.cs index f9a573049..f38e5b776 100644 --- a/src/Feature/Selections/rendering/Models/Admin/ScoreCardsModel.cs +++ b/src/Feature/Selections/rendering/Models/Admin/ScoreCardsModel.cs @@ -8,17 +8,17 @@ namespace Mvp.Feature.Selections.Models.Admin { public class ScoreCardsModel : BaseModel { - public List Selections { get; set; } = new (); + public List Selections { get; set; } = []; public Guid SelectedSelectionId { get; set; } = Guid.Empty; - public List MvpTypes { get; set; } = new (); + public List MvpTypes { get; set; } = []; public short SelectedMvpTypeId { get; set; } = 0; - public List ScoreCards { get; set; } = new (); + public List ScoreCards { get; set; } = []; - public List Titles { get; set; } = new (); + public List<Title> Titles { get; set; } = []; public TextField TitleLabel { get; set; } diff --git a/src/Feature/Selections/rendering/Models/Admin/UserEditModel.cs b/src/Feature/Selections/rendering/Models/Admin/UserEditModel.cs index 2c57b4ef5..65dfb56c2 100644 --- a/src/Feature/Selections/rendering/Models/Admin/UserEditModel.cs +++ b/src/Feature/Selections/rendering/Models/Admin/UserEditModel.cs @@ -33,7 +33,7 @@ public class UserEditModel : BaseModel [Required] public short CountryId { get; set; } - public List<Country> Countries { get; } = new (); + public List<Country> Countries { get; } = []; public TextField SubmitLabel { get; set; } diff --git a/src/Feature/Selections/rendering/Models/Any/MyDataEditModel.cs b/src/Feature/Selections/rendering/Models/Any/MyDataEditModel.cs index 4bda1c89f..cff9bdd28 100644 --- a/src/Feature/Selections/rendering/Models/Any/MyDataEditModel.cs +++ b/src/Feature/Selections/rendering/Models/Any/MyDataEditModel.cs @@ -33,7 +33,7 @@ public class MyDataEditModel : BaseModel [FromForm(Name = $"{nameof(MyDataEditModel)}.{nameof(CountryId)}")] public short CountryId { get; set; } - public List<Country> Countries { get; init; } = new (); + public List<Country> Countries { get; init; } = []; public TextField ImageTypeLabel { get; set; } @@ -43,7 +43,7 @@ public class MyDataEditModel : BaseModel public Uri ImageUri { get; set; } - public List<Consent> Consents { get; init; } = new (); + public List<Consent> Consents { get; init; } = []; public TextField SubmitLabel { get; set; } diff --git a/src/Feature/Selections/rendering/Models/Any/MyProfilesFormModel.cs b/src/Feature/Selections/rendering/Models/Any/MyProfilesFormModel.cs index a50862adc..19419ce72 100644 --- a/src/Feature/Selections/rendering/Models/Any/MyProfilesFormModel.cs +++ b/src/Feature/Selections/rendering/Models/Any/MyProfilesFormModel.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc; +using Mvp.Feature.Selections.Attributes; using Mvp.Selections.Domain; using Sitecore.LayoutService.Client.Response.Model.Fields; @@ -23,6 +24,7 @@ public class MyProfilesFormModel : BaseModel public TextField LinkLabel { get; set; } [Required] + [HttpsUrl] [FromForm(Name = $"{nameof(MyProfilesFormModel)}.{nameof(Link)}")] public Uri Link { get; set; } @@ -34,7 +36,7 @@ public class MyProfilesFormModel : BaseModel public TextField SubmitLabel { get; set; } - public List<ProfileLink> Links { get; init; } = new (); + public List<ProfileLink> Links { get; init; } = []; public Guid? RemoveProfileLinkId { get; set; } diff --git a/src/Feature/Selections/rendering/Models/Apply/ApplicationFormModel.cs b/src/Feature/Selections/rendering/Models/Apply/ApplicationFormModel.cs index a89256c5c..0ab0a843b 100644 --- a/src/Feature/Selections/rendering/Models/Apply/ApplicationFormModel.cs +++ b/src/Feature/Selections/rendering/Models/Apply/ApplicationFormModel.cs @@ -101,13 +101,13 @@ public class ApplicationFormModel : BaseModel public TextField ContributionProductsLabel { get; set; } - public List<int> ContributionProductIds { get; set; } = new (); + public List<int> ContributionProductIds { get; set; } = []; public TextField PublicContributionLabel { get; set; } public bool ContributionIsPublic { get; set; } = false; - public List<Product> Products { get; } = new (); + public List<Product> Products { get; } = []; public TextField AddLabel { get; set; } diff --git a/src/Feature/Selections/rendering/Models/BaseModel.cs b/src/Feature/Selections/rendering/Models/BaseModel.cs index c1b133902..734981c35 100644 --- a/src/Feature/Selections/rendering/Models/BaseModel.cs +++ b/src/Feature/Selections/rendering/Models/BaseModel.cs @@ -8,6 +8,6 @@ public abstract class BaseModel [SitecoreContextProperty] public bool IsEditing { get; set; } - public List<string> ErrorMessages { get; set; } = new (); + public List<string> ErrorMessages { get; set; } = []; } } diff --git a/src/Feature/Selections/rendering/Models/ListModel.cs b/src/Feature/Selections/rendering/Models/ListModel.cs index fa4d36137..e7cccff42 100644 --- a/src/Feature/Selections/rendering/Models/ListModel.cs +++ b/src/Feature/Selections/rendering/Models/ListModel.cs @@ -12,7 +12,7 @@ public abstract class ListModel<T> : BaseModel [FromQuery(Name = "ps")] public short PageSize { get; set; } = 50; - public List<T> List { get; } = new (); + public List<T> List { get; } = []; public BaseFilter Filter { get; set; } = new BaseFilter.None(); } diff --git a/src/Feature/Selections/rendering/ViewComponents/Admin/ApplicationCommentViewComponent.cs b/src/Feature/Selections/rendering/ViewComponents/Admin/ApplicationCommentViewComponent.cs index e511dedda..ade2ba991 100644 --- a/src/Feature/Selections/rendering/ViewComponents/Admin/ApplicationCommentViewComponent.cs +++ b/src/Feature/Selections/rendering/ViewComponents/Admin/ApplicationCommentViewComponent.cs @@ -39,7 +39,7 @@ private async Task PostComment(ApplicationCommentModel model) Response<User> getUserResponse = await Client.GetCurrentUserAsync(); if (getUserResponse.StatusCode == HttpStatusCode.OK && getUserResponse.Result != null) { - ApplicationComment newComment = new (Guid.Empty) + ApplicationComment newComment = new(Guid.Empty) { Application = new Application(model.ApplicationId), User = getUserResponse.Result, diff --git a/src/Feature/Selections/rendering/ViewComponents/Admin/ApplicationOverviewViewComponent.cs b/src/Feature/Selections/rendering/ViewComponents/Admin/ApplicationOverviewViewComponent.cs index c1f16e8dd..358e4c289 100644 --- a/src/Feature/Selections/rendering/ViewComponents/Admin/ApplicationOverviewViewComponent.cs +++ b/src/Feature/Selections/rendering/ViewComponents/Admin/ApplicationOverviewViewComponent.cs @@ -12,15 +12,11 @@ namespace Mvp.Feature.Selections.ViewComponents.Admin { [ViewComponent(Name = ViewComponentName)] - public class ApplicationOverviewViewComponent : BaseViewComponent + public class ApplicationOverviewViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client) + : BaseViewComponent(modelBinder, client) { public const string ViewComponentName = "AdminApplicationsOverview"; - public ApplicationOverviewViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client) - : base(modelBinder, client) - { - } - public override async Task<IViewComponentResult> InvokeAsync() { IViewComponentResult result; @@ -118,7 +114,7 @@ private async Task LoadFilterValues(ApplicationsOverviewModel model) { Task<Response<IList<Country>>> countriesResponseTask = Client.GetCountriesAsync(1, short.MaxValue); Task<Response<IList<Selection>>> selectionResponseTask = Client.GetSelectionsAsync(1, short.MaxValue); - List<Task> tasks = new () { countriesResponseTask, selectionResponseTask }; + List<Task> tasks = [countriesResponseTask, selectionResponseTask]; while (tasks.Count > 0) { Task finished = await Task.WhenAny(tasks); diff --git a/src/Feature/Selections/rendering/ViewComponents/Admin/ApplicationReviewSettingsViewComponent.cs b/src/Feature/Selections/rendering/ViewComponents/Admin/ApplicationReviewSettingsViewComponent.cs index 454ca2626..366a08a15 100644 --- a/src/Feature/Selections/rendering/ViewComponents/Admin/ApplicationReviewSettingsViewComponent.cs +++ b/src/Feature/Selections/rendering/ViewComponents/Admin/ApplicationReviewSettingsViewComponent.cs @@ -15,15 +15,11 @@ namespace Mvp.Feature.Selections.ViewComponents.Admin { [ViewComponent(Name = ViewComponentName)] - public class ApplicationReviewSettingsViewComponent : BaseViewComponent + public class ApplicationReviewSettingsViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client) + : BaseViewComponent(modelBinder, client) { public const string ViewComponentName = "AdminApplicationReviewSettings"; - public ApplicationReviewSettingsViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client) - : base(modelBinder, client) - { - } - public override async Task<IViewComponentResult> InvokeAsync() { ApplicationReviewSettingsModel model = await ModelBinder.Bind<ApplicationReviewSettingsModel>(ViewContext); @@ -75,7 +71,7 @@ private async Task LoadData(ApplicationReviewSettingsModel model) { Task<Response<IList<User>>> usersResponseTask = Client.GetUsersForApplicationReview(model.Id); Task<Response<Application>> applicationResponseTask = Client.GetApplicationAsync(model.Id); - List<Task> tasks = new () { usersResponseTask, applicationResponseTask }; + List<Task> tasks = [usersResponseTask, applicationResponseTask]; while (tasks.Count > 0) { Task finished = await Task.WhenAny(tasks); @@ -114,7 +110,7 @@ private async Task LoadData(ApplicationReviewSettingsModel model) private async Task AddReviewers(ApplicationReviewSettingsModel model) { - Dictionary<Task<Response<IList<User>>>, string> tasks = new (model.AddReviewerUserEmails.Count); + Dictionary<Task<Response<IList<User>>>, string> tasks = new(model.AddReviewerUserEmails.Count); foreach (string email in model.AddReviewerUserEmails) { tasks.Add(Client.GetUsersAsync(email: email), email); @@ -187,7 +183,7 @@ private async Task RemoveReviewer(ApplicationReviewSettingsModel model) Response<IList<SelectionRole>> selectionRolesResponse = await Client.GetSelectionRolesAsync(applicationId: model.Id); if (selectionRolesResponse.StatusCode == HttpStatusCode.OK && selectionRolesResponse.Result != null) { - List<Task> removeTasks = new (selectionRolesResponse.Result.Count); + List<Task> removeTasks = new(selectionRolesResponse.Result.Count); foreach (SelectionRole role in selectionRolesResponse.Result) { removeTasks.Add(Client.RemoveUserFromRoleAsync(role.Id, model.RemoveReviewerUserId!.Value)); diff --git a/src/Feature/Selections/rendering/ViewComponents/Admin/AwardViewComponent.cs b/src/Feature/Selections/rendering/ViewComponents/Admin/AwardViewComponent.cs index 4d7d7e48e..2c3369ad2 100644 --- a/src/Feature/Selections/rendering/ViewComponents/Admin/AwardViewComponent.cs +++ b/src/Feature/Selections/rendering/ViewComponents/Admin/AwardViewComponent.cs @@ -64,17 +64,17 @@ await Task.WhenAll( private static void GenerateFakeDataForEdit(AwardModel model) { - MvpType loremMvp = new (1) + MvpType loremMvp = new(1) { Name = "Lorem" }; - MvpType ipsumMvp = new (2) + MvpType ipsumMvp = new(2) { Name = "Ipsum" }; - Application dolorApplication = new (Guid.NewGuid()) + Application dolorApplication = new(Guid.NewGuid()) { Applicant = new User(Guid.NewGuid()) { @@ -92,7 +92,7 @@ private static void GenerateFakeDataForEdit(AwardModel model) Status = ApplicationStatus.Submitted }; - model.Title = new (Guid.NewGuid()) + model.Title = new(Guid.NewGuid()) { Warning = "Donec varius, leo eget iaculis placerat, sapien orci iaculis nulla, ut facilisis eros arcu a ex.", MvpType = loremMvp, @@ -138,7 +138,7 @@ private static void GenerateFakeDataForEdit(AwardModel model) private async Task AwardTitle(AwardModel model) { - Title newTitle = new (Guid.Empty) + Title newTitle = new(Guid.Empty) { MvpType = model.MvpTypes.Single(t => t.Id == model.MvpTypeId), Application = model.Application, diff --git a/src/Feature/Selections/rendering/ViewComponents/Admin/RegionsOverviewViewComponent.cs b/src/Feature/Selections/rendering/ViewComponents/Admin/RegionsOverviewViewComponent.cs index 6ed541e99..936e710f2 100644 --- a/src/Feature/Selections/rendering/ViewComponents/Admin/RegionsOverviewViewComponent.cs +++ b/src/Feature/Selections/rendering/ViewComponents/Admin/RegionsOverviewViewComponent.cs @@ -11,15 +11,11 @@ namespace Mvp.Feature.Selections.ViewComponents.Admin { [ViewComponent(Name = ViewComponentName)] - public class RegionsOverviewViewComponent : BaseViewComponent + public class RegionsOverviewViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client) + : BaseViewComponent(modelBinder, client) { public const string ViewComponentName = "AdminRegionsOverview"; - public RegionsOverviewViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client) - : base(modelBinder, client) - { - } - public override async Task<IViewComponentResult> InvokeAsync() { RegionsOverviewModel model = await ModelBinder.Bind<RegionsOverviewModel>(ViewContext); @@ -41,7 +37,7 @@ public override async Task<IViewComponentResult> InvokeAsync() private static void GenerateFakeDataForEdit(RegionsOverviewModel model) { - Region region = new (1) + Region region = new(1) { Name = "Lorem" }; diff --git a/src/Feature/Selections/rendering/ViewComponents/Admin/ScoreCardDetailViewComponent.cs b/src/Feature/Selections/rendering/ViewComponents/Admin/ScoreCardDetailViewComponent.cs index 8935599f4..e8c5bef27 100644 --- a/src/Feature/Selections/rendering/ViewComponents/Admin/ScoreCardDetailViewComponent.cs +++ b/src/Feature/Selections/rendering/ViewComponents/Admin/ScoreCardDetailViewComponent.cs @@ -52,8 +52,8 @@ await Task.WhenAll( private static void GenerateFakeDataForEdit(ScoreCardDetailModel model) { - Random rnd = new (); - Application application = new (Guid.NewGuid()) + Random rnd = new(); + Application application = new(Guid.NewGuid()) { Applicant = new User(Guid.NewGuid()) { @@ -69,49 +69,49 @@ private static void GenerateFakeDataForEdit(ScoreCardDetailModel model) } }; - Score goodScore = new (Guid.NewGuid()) + Score goodScore = new(Guid.NewGuid()) { Name = "Good", Value = 10 }; - Score badScore = new (Guid.NewGuid()) + Score badScore = new(Guid.NewGuid()) { Name = "Bad", Value = -10 }; - ScoreCategory topCategory1 = new (Guid.NewGuid()) + ScoreCategory topCategory1 = new(Guid.NewGuid()) { Name = "Pulvinar", Weight = (decimal)rnd.NextDouble() }; - ScoreCategory topCategory2 = new (Guid.NewGuid()) + ScoreCategory topCategory2 = new(Guid.NewGuid()) { Name = "Aliquam", Weight = (decimal)rnd.NextDouble() }; - ScoreCategory subCategory1 = new (Guid.NewGuid()) + ScoreCategory subCategory1 = new(Guid.NewGuid()) { Name = "Imper", Weight = (decimal)rnd.NextDouble(), ParentCategory = topCategory1, ScoreOptions = new List<Score> { goodScore, badScore } }; - ScoreCategory subCategory2 = new (Guid.NewGuid()) + ScoreCategory subCategory2 = new(Guid.NewGuid()) { Name = "Proin", Weight = (decimal)rnd.NextDouble(), ParentCategory = topCategory1, ScoreOptions = new List<Score> { goodScore, badScore } }; - ScoreCategory subCategory3 = new (Guid.NewGuid()) + ScoreCategory subCategory3 = new(Guid.NewGuid()) { Name = "Turpis", Weight = (decimal)rnd.NextDouble(), ParentCategory = topCategory1, ScoreOptions = new List<Score> { goodScore, badScore } }; - ScoreCategory subCategory4 = new (Guid.NewGuid()) + ScoreCategory subCategory4 = new(Guid.NewGuid()) { Name = "Congue", Weight = (decimal)rnd.NextDouble(), @@ -145,22 +145,22 @@ private static void GenerateFakeDataForEdit(ScoreCardDetailModel model) }, CategoryScores = new List<ReviewCategoryScore> { - new () + new() { ScoreCategoryId = subCategory1.Id, ScoreId = goodScore.Id }, - new () + new() { ScoreCategoryId = subCategory2.Id, ScoreId = goodScore.Id }, - new () + new() { ScoreCategoryId = subCategory3.Id, ScoreId = goodScore.Id }, - new () + new() { ScoreCategoryId = subCategory4.Id, ScoreId = badScore.Id @@ -177,22 +177,22 @@ private static void GenerateFakeDataForEdit(ScoreCardDetailModel model) }, CategoryScores = new List<ReviewCategoryScore> { - new () + new() { ScoreCategoryId = subCategory1.Id, ScoreId = goodScore.Id }, - new () + new() { ScoreCategoryId = subCategory2.Id, ScoreId = badScore.Id }, - new () + new() { ScoreCategoryId = subCategory3.Id, ScoreId = badScore.Id }, - new () + new() { ScoreCategoryId = subCategory4.Id, ScoreId = badScore.Id diff --git a/src/Feature/Selections/rendering/ViewComponents/Admin/ScoreCardsViewComponent.cs b/src/Feature/Selections/rendering/ViewComponents/Admin/ScoreCardsViewComponent.cs index 9982eb004..fd0f53b87 100644 --- a/src/Feature/Selections/rendering/ViewComponents/Admin/ScoreCardsViewComponent.cs +++ b/src/Feature/Selections/rendering/ViewComponents/Admin/ScoreCardsViewComponent.cs @@ -54,10 +54,10 @@ await Task.WhenAll( private static void GenerateFakeDataForEdit(ScoreCardsModel model) { - Random rnd = new (); - MvpType loremMvpType = new (1) { Name = "Lorem" }; - Country dolorCountry = new (1) { Name = "Dolor" }; - Selection conseceturSelection = new (Guid.NewGuid()) { Year = (short)(DateTime.Now.Year + rnd.Next(10, 20)) }; + Random rnd = new(); + MvpType loremMvpType = new(1) { Name = "Lorem" }; + Country dolorCountry = new(1) { Name = "Dolor" }; + Selection conseceturSelection = new(Guid.NewGuid()) { Year = (short)(DateTime.Now.Year + rnd.Next(10, 20)) }; model.SelectedSelectionId = conseceturSelection.Id; model.SelectedMvpTypeId = 1; diff --git a/src/Feature/Selections/rendering/ViewComponents/Admin/UserEditViewComponent.cs b/src/Feature/Selections/rendering/ViewComponents/Admin/UserEditViewComponent.cs index 0ecc23156..8af142509 100644 --- a/src/Feature/Selections/rendering/ViewComponents/Admin/UserEditViewComponent.cs +++ b/src/Feature/Selections/rendering/ViewComponents/Admin/UserEditViewComponent.cs @@ -30,7 +30,7 @@ public override async Task<IViewComponentResult> InvokeAsync() Response<User> userResponse = null; if (model.IsEdit && ModelState.IsValid) { - User updatedUser = new (model.Id) + User updatedUser = new(model.Id) { Identifier = model.Identifier, Name = model.Name, diff --git a/src/Feature/Selections/rendering/ViewComponents/Admin/UsersOverviewViewComponent.cs b/src/Feature/Selections/rendering/ViewComponents/Admin/UsersOverviewViewComponent.cs index 19ff7b115..8be80cd07 100644 --- a/src/Feature/Selections/rendering/ViewComponents/Admin/UsersOverviewViewComponent.cs +++ b/src/Feature/Selections/rendering/ViewComponents/Admin/UsersOverviewViewComponent.cs @@ -33,7 +33,7 @@ public override async Task<IViewComponentResult> InvokeAsync() else if (model.RemoveUserId != null && model.RemoveConfirmed) { // TODO [ILs] Implement remove user - Response<bool> removeUserResponse = new () { Result = false }; ////await Client.RemoveUserAsync(model.RemoveUserId.Value); + Response<bool> removeUserResponse = new() { Result = false }; ////await Client.RemoveUserAsync(model.RemoveUserId.Value); if (removeUserResponse.Result) { await LoadUsers(model); diff --git a/src/Feature/Selections/rendering/ViewComponents/Any/MyDataEditViewComponent.cs b/src/Feature/Selections/rendering/ViewComponents/Any/MyDataEditViewComponent.cs index c3ff72098..133da717f 100644 --- a/src/Feature/Selections/rendering/ViewComponents/Any/MyDataEditViewComponent.cs +++ b/src/Feature/Selections/rendering/ViewComponents/Any/MyDataEditViewComponent.cs @@ -26,7 +26,7 @@ public override async Task<IViewComponentResult> InvokeAsync() Response<User> userResponse = null; if (model.IsEdit && ModelState.IsValid) { - User updatedUser = new (Guid.Empty) + User updatedUser = new(Guid.Empty) { Name = model.Name, Email = model.Email, diff --git a/src/Feature/Selections/rendering/ViewComponents/Any/MyProfilesFormViewComponent.cs b/src/Feature/Selections/rendering/ViewComponents/Any/MyProfilesFormViewComponent.cs index 0a248361d..d24fc7240 100644 --- a/src/Feature/Selections/rendering/ViewComponents/Any/MyProfilesFormViewComponent.cs +++ b/src/Feature/Selections/rendering/ViewComponents/Any/MyProfilesFormViewComponent.cs @@ -12,15 +12,11 @@ namespace Mvp.Feature.Selections.ViewComponents.Any { [ViewComponent(Name = ViewComponentName)] - public class MyProfilesFormViewComponent : BaseViewComponent + public class MyProfilesFormViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client) + : BaseViewComponent(modelBinder, client) { public const string ViewComponentName = "AnyMyProfilesForm"; - public MyProfilesFormViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client) - : base(modelBinder, client) - { - } - public override async Task<IViewComponentResult> InvokeAsync() { IViewComponentResult result; @@ -59,7 +55,7 @@ public override async Task<IViewComponentResult> InvokeAsync() } else if (model.IsEdit && ModelState.IsValid) { - ProfileLink newProfileLink = new (Guid.Empty) + ProfileLink newProfileLink = new(Guid.Empty) { Name = model.Name, Uri = model.Link, diff --git a/src/Feature/Selections/rendering/ViewComponents/Apply/ApplicationFormViewComponent.cs b/src/Feature/Selections/rendering/ViewComponents/Apply/ApplicationFormViewComponent.cs index bcd8a4d74..d9aa4959d 100644 --- a/src/Feature/Selections/rendering/ViewComponents/Apply/ApplicationFormViewComponent.cs +++ b/src/Feature/Selections/rendering/ViewComponents/Apply/ApplicationFormViewComponent.cs @@ -15,17 +15,15 @@ namespace Mvp.Feature.Selections.ViewComponents.Apply { [ViewComponent(Name = ViewComponentName)] - public class ApplicationFormViewComponent : BaseViewComponent + public class ApplicationFormViewComponent( + IViewModelBinder modelBinder, + MvpSelectionsApiClient client, + IOptions<MvpSelectionsOptions> options) + : BaseViewComponent(modelBinder, client) { public const string ViewComponentName = "ApplyApplicationForm"; - private readonly MvpSelectionsOptions _options; - - public ApplicationFormViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client, IOptions<MvpSelectionsOptions> options) - : base(modelBinder, client) - { - _options = options.Value; - } + private readonly MvpSelectionsOptions _options = options.Value; public override async Task<IViewComponentResult> InvokeAsync() { @@ -116,38 +114,38 @@ private static void GenerateFakeDataForEdit(ApplicationFormModel model) } }; - Product product1 = new (1) + Product product1 = new(1) { Name = "Lorem Product" }; - Product product2 = new (2) + Product product2 = new(2) { Name = "Ipsum Product" }; - MvpType mvpType1 = new (1) + MvpType mvpType1 = new(1) { Name = "Lorem MVP" }; model.CurrentApplication = new Application(Guid.NewGuid()) { - Contributions = new List<Contribution> - { - new (Guid.NewGuid()) + Contributions = + [ + new Contribution(Guid.NewGuid()) { Date = DateTime.UtcNow, Name = "Lorem Link", Description = "This would be a description of the link submitted as a contribution.", Uri = new Uri("https://www.google.com"), Type = ContributionType.Other, - RelatedProducts = new List<Product> - { + RelatedProducts = + [ product1, product2 - } + ] } - }, + ], ModifiedOn = DateTime.UtcNow, MvpType = mvpType1 }; @@ -158,14 +156,14 @@ private static void GenerateFakeDataForEdit(ApplicationFormModel model) model.CurrentSelection = new Selection(Guid.NewGuid()) { Year = (short)DateTime.UtcNow.Year, - MvpTypes = new List<MvpType> - { + MvpTypes = + [ mvpType1, - new (2) + new MvpType(2) { Name = "Ipsum MVP" } - } + ] }; } @@ -258,7 +256,7 @@ private async Task ExecuteConsentStep(ApplicationFormModel model) if (consentsResponse.StatusCode == HttpStatusCode.OK && (consentsResponse.Result?.All(c => c.Type != ConsentType.PersonalInformation) ?? false)) { - Consent consent = new (Guid.Empty) + Consent consent = new(Guid.Empty) { Type = ConsentType.PersonalInformation }; @@ -317,7 +315,7 @@ private async Task ExecuteMvpTypeStep(ApplicationFormModel model) { if (model.CurrentApplication != null) { - Application updateApplication = new (model.CurrentApplication.Id) + Application updateApplication = new(model.CurrentApplication.Id) { MvpType = new MvpType(model.MvpTypeId) }; @@ -336,7 +334,7 @@ private async Task ExecuteMvpTypeStep(ApplicationFormModel model) } else { - Application newApplication = new (Guid.Empty) + Application newApplication = new(Guid.Empty) { Country = model.CurrentUser.Country!, Selection = model.CurrentSelection, @@ -373,7 +371,7 @@ private async Task ExecuteObjectivesStep(ApplicationFormModel model) { if (model.IsNavigation.HasValue && !model.IsNavigation.Value && !string.IsNullOrWhiteSpace(model.Eligibility) && !string.IsNullOrWhiteSpace(model.Objectives)) { - Application updateApplication = new (model.CurrentApplication.Id) + Application updateApplication = new(model.CurrentApplication.Id) { Eligibility = model.Eligibility, Objectives = model.Objectives, @@ -445,7 +443,7 @@ private async Task ExecuteContributionsStep(ApplicationFormModel model) && model.ContributionDate.Value >= model.CurrentSelection.ApplicationsEnd.AddMonths(-_options.TimeFrameMonths) && model.ContributionDate.Value <= model.CurrentSelection.ApplicationsEnd) { - Contribution contribution = new (model.UpdateContributionId ?? Guid.Empty) + Contribution contribution = new(model.UpdateContributionId ?? Guid.Empty) { Date = model.ContributionDate.Value, Name = model.ContributionName, @@ -482,7 +480,7 @@ private async Task ExecuteContributionsStep(ApplicationFormModel model) model.ContributionDescription = null; model.ContributionLink = null; model.ContributionType = ContributionType.Other; - model.ContributionProductIds = new List<int>(); + model.ContributionProductIds = []; model.ContributionIsPublic = false; ModelState.Clear(); } @@ -553,7 +551,7 @@ private async Task ExecuteConfirmationStep(ApplicationFormModel model) } else if (model.IsNavigation.HasValue && !model.IsNavigation.Value && model.UnderstandsReviewConsent && model.UnderstandsProgramAgreement && model.IsComplete) { - Application updateApplication = new (model.CurrentApplication.Id) + Application updateApplication = new(model.CurrentApplication.Id) { Status = ApplicationStatus.Submitted }; @@ -580,7 +578,7 @@ private async Task ExecuteSubmittedStep(ApplicationFormModel model) { if (model.IsNavigation.HasValue && !model.IsNavigation.Value) { - Application updateApplication = new (model.CurrentApplication.Id) + Application updateApplication = new(model.CurrentApplication.Id) { Status = ApplicationStatus.Open };