Skip to content

Commit dc19a6c

Browse files
Merge pull request #1 from MatteoZampariniDev/main
Sync with main
2 parents cb0e43d + 957a047 commit dc19a6c

File tree

6 files changed

+123
-84
lines changed

6 files changed

+123
-84
lines changed
Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,55 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
3-
using CleanArchitecture.Blazor.Application.Features.Customers.DTOs;
43
using CleanArchitecture.Blazor.Application.Features.Customers.Caching;
5-
using CleanArchitecture.Blazor.Application.Features.Customers.Commands.AddEdit;
4+
using CleanArchitecture.Blazor.Application.Features.Customers.DTOs;
65

76
namespace CleanArchitecture.Blazor.Application.Features.Customers.Commands.Create;
87

9-
public class CreateCustomerCommand: ICacheInvalidatorRequest<Result<int>>
8+
public class CreateCustomerCommand : ICacheInvalidatorRequest<Result<int>>
109
{
11-
[Description("Id")]
12-
public int Id {get;set;}
10+
[Description("Id")]
11+
public int Id { get; set; }
1312
[Description("Name")]
14-
public string Name {get;set;} = String.Empty;
13+
public string Name { get; set; } = String.Empty;
1514
[Description("Description")]
16-
public string? Description {get;set;}
15+
public string? Description { get; set; }
1716

18-
public string CacheKey => CustomerCacheKey.GetAllCacheKey;
19-
public CancellationTokenSource? SharedExpiryTokenSource => CustomerCacheKey.SharedExpiryTokenSource();
17+
public string CacheKey => CustomerCacheKey.GetAllCacheKey;
18+
public CancellationTokenSource? SharedExpiryTokenSource => CustomerCacheKey.SharedExpiryTokenSource();
2019
private class Mapping : Profile
2120
{
2221
public Mapping()
2322
{
24-
CreateMap<CustomerDto, AddEditCustomerCommand>(MemberList.None);
25-
CreateMap<AddEditCustomerCommand, Customer>(MemberList.None);
23+
CreateMap<CustomerDto, CreateCustomerCommand>(MemberList.None);
24+
CreateMap<CreateCustomerCommand, Customer>(MemberList.None);
2625
}
2726
}
2827
}
29-
30-
public class CreateCustomerCommandHandler : IRequestHandler<CreateCustomerCommand, Result<int>>
28+
29+
public class CreateCustomerCommandHandler : IRequestHandler<CreateCustomerCommand, Result<int>>
30+
{
31+
private readonly IApplicationDbContext _context;
32+
private readonly IMapper _mapper;
33+
private readonly IStringLocalizer<CreateCustomerCommand> _localizer;
34+
public CreateCustomerCommandHandler(
35+
IApplicationDbContext context,
36+
IStringLocalizer<CreateCustomerCommand> localizer,
37+
IMapper mapper
38+
)
3139
{
32-
private readonly IApplicationDbContext _context;
33-
private readonly IMapper _mapper;
34-
private readonly IStringLocalizer<CreateCustomerCommand> _localizer;
35-
public CreateCustomerCommandHandler(
36-
IApplicationDbContext context,
37-
IStringLocalizer<CreateCustomerCommand> localizer,
38-
IMapper mapper
39-
)
40-
{
41-
_context = context;
42-
_localizer = localizer;
43-
_mapper = mapper;
44-
}
45-
public async Task<Result<int>> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
46-
{
47-
48-
var item = _mapper.Map<Customer>(request);
49-
// raise a create domain event
50-
item.AddDomainEvent(new CustomerCreatedEvent(item));
51-
_context.Customers.Add(item);
52-
await _context.SaveChangesAsync(cancellationToken);
53-
return await Result<int>.SuccessAsync(item.Id);
54-
}
40+
_context = context;
41+
_localizer = localizer;
42+
_mapper = mapper;
43+
}
44+
public async Task<Result<int>> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
45+
{
46+
47+
var item = _mapper.Map<Customer>(request);
48+
// raise a create domain event
49+
item.AddDomainEvent(new CustomerCreatedEvent(item));
50+
_context.Customers.Add(item);
51+
await _context.SaveChangesAsync(cancellationToken);
52+
return await Result<int>.SuccessAsync(item.Id);
5553
}
54+
}
5655

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,55 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
3-
using CleanArchitecture.Blazor.Application.Features.Customers.DTOs;
43
using CleanArchitecture.Blazor.Application.Features.Customers.Caching;
5-
using CleanArchitecture.Blazor.Application.Features.Customers.Commands.AddEdit;
4+
using CleanArchitecture.Blazor.Application.Features.Customers.DTOs;
65

76
namespace CleanArchitecture.Blazor.Application.Features.Customers.Commands.Update;
87

9-
public class UpdateCustomerCommand: ICacheInvalidatorRequest<Result<int>>
8+
public class UpdateCustomerCommand : ICacheInvalidatorRequest<Result<int>>
109
{
11-
[Description("Id")]
12-
public int Id {get;set;}
10+
[Description("Id")]
11+
public int Id { get; set; }
1312
[Description("Name")]
14-
public string Name {get;set;} = String.Empty;
13+
public string Name { get; set; } = String.Empty;
1514
[Description("Description")]
16-
public string? Description {get;set;}
15+
public string? Description { get; set; }
1716

18-
public string CacheKey => CustomerCacheKey.GetAllCacheKey;
19-
public CancellationTokenSource? SharedExpiryTokenSource => CustomerCacheKey.SharedExpiryTokenSource();
17+
public string CacheKey => CustomerCacheKey.GetAllCacheKey;
18+
public CancellationTokenSource? SharedExpiryTokenSource => CustomerCacheKey.SharedExpiryTokenSource();
2019
private class Mapping : Profile
2120
{
2221
public Mapping()
2322
{
24-
CreateMap<CustomerDto, AddEditCustomerCommand>(MemberList.None);
25-
CreateMap<AddEditCustomerCommand, Customer>(MemberList.None);
23+
CreateMap<CustomerDto, UpdateCustomerCommand>(MemberList.None);
24+
CreateMap<UpdateCustomerCommand, Customer>(MemberList.None);
2625
}
2726
}
2827
}
2928

30-
public class UpdateCustomerCommandHandler : IRequestHandler<UpdateCustomerCommand, Result<int>>
29+
public class UpdateCustomerCommandHandler : IRequestHandler<UpdateCustomerCommand, Result<int>>
30+
{
31+
private readonly IApplicationDbContext _context;
32+
private readonly IMapper _mapper;
33+
private readonly IStringLocalizer<UpdateCustomerCommandHandler> _localizer;
34+
public UpdateCustomerCommandHandler(
35+
IApplicationDbContext context,
36+
IStringLocalizer<UpdateCustomerCommandHandler> localizer,
37+
IMapper mapper
38+
)
39+
{
40+
_context = context;
41+
_localizer = localizer;
42+
_mapper = mapper;
43+
}
44+
public async Task<Result<int>> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
3145
{
32-
private readonly IApplicationDbContext _context;
33-
private readonly IMapper _mapper;
34-
private readonly IStringLocalizer<UpdateCustomerCommandHandler> _localizer;
35-
public UpdateCustomerCommandHandler(
36-
IApplicationDbContext context,
37-
IStringLocalizer<UpdateCustomerCommandHandler> localizer,
38-
IMapper mapper
39-
)
40-
{
41-
_context = context;
42-
_localizer = localizer;
43-
_mapper = mapper;
44-
}
45-
public async Task<Result<int>> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
46-
{
4746

48-
var item =await _context.Customers.FindAsync( new object[] { request.Id }, cancellationToken)?? throw new NotFoundException($"Customer with id: [{request.Id}] not found.");;
49-
item = _mapper.Map(request, item);
50-
// raise a update domain event
51-
item.AddDomainEvent(new CustomerUpdatedEvent(item));
52-
await _context.SaveChangesAsync(cancellationToken);
53-
return await Result<int>.SuccessAsync(item.Id);
54-
}
47+
var item = await _context.Customers.FindAsync(new object[] { request.Id }, cancellationToken) ?? throw new NotFoundException($"Customer with id: [{request.Id}] not found."); ;
48+
item = _mapper.Map(request, item);
49+
// raise a update domain event
50+
item.AddDomainEvent(new CustomerUpdatedEvent(item));
51+
await _context.SaveChangesAsync(cancellationToken);
52+
return await Result<int>.SuccessAsync(item.Id);
5553
}
54+
}
5655

src/Blazor.Server.UI/Pages/_Layout.cshtml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,33 @@
2020
z-index: 9999;
2121
}
2222
.mud-input {
23-
font-size: 0.8125rem;
23+
font-size: var(--mud-typography-default-size);
2424
}
2525
2626
.mud-input-control > .mud-input-control-input-container > .mud-input-label-inputcontrol {
27-
font-size: 0.8125rem;
27+
font-size: var(--mud-typography-default-size);
2828
}
2929
30+
.mud-expand-panel .mud-expand-panel-header{
31+
font-size: var(--mud-typography-subtitle1-size);
32+
}
3033
.mud-button-year {
31-
font-size: 0.8125rem;
34+
font-size: var(--mud-typography-default-size);
3235
}
3336
3437
.mud-table-cell {
3538
font-size: var(--mud-typography-default-size);
3639
}
3740
3841
.mud-typography-body1{
39-
font-size: var(--mud-typography-default-size);
42+
font-size: var(--mud-typography-body1-size);
4043
}
4144
45+
.mud-typography-body2 {
46+
font-size: var(--mud-typography-body2-size);
47+
}
4248
.mud-button-outlined-size-small{
43-
font-size: var(--mud-typography-default-size);
49+
font-size: var(--mud-typography-body2-size);
4450
}
4551
#blazor-error-ui {
4652
background: lightyellow;

src/Blazor.Server.UI/Services/Layout/LayoutService.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ public void SetDarkMode(bool value)
5353
CurrentTheme.PaletteDark.PrimaryLighten = _userPreferences.PrimaryLighten;
5454
CurrentTheme.LayoutProperties.DefaultBorderRadius = BorderRadius + "px";
5555
CurrentTheme.Typography.Default.FontSize = DefaultFontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
56+
CurrentTheme.Typography.Button.FontSize = _userPreferences.ButtonFontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
57+
CurrentTheme.Typography.Body1.FontSize = _userPreferences.Body1FontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
58+
CurrentTheme.Typography.Body2.FontSize = _userPreferences.Body2FontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
59+
CurrentTheme.Typography.Caption.FontSize = _userPreferences.CaptionFontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
60+
CurrentTheme.Typography.Overline.FontSize = _userPreferences.OverlineFontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
61+
CurrentTheme.Typography.Subtitle1.FontSize = _userPreferences.Subtitle1FontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
62+
CurrentTheme.Typography.Subtitle2.FontSize = _userPreferences.Subtitle1FontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
5663
}
5764
else
5865
{
@@ -174,9 +181,26 @@ public async Task UpdateUserPreferences(UserPreferences.UserPreferences preferen
174181
PrimaryColor = _userPreferences.PrimaryColor;
175182
BorderRadius = _userPreferences.BorderRadius;
176183
DefaultFontSize = _userPreferences.DefaultFontSize;
177-
DarkModeToggle = _userPreferences.DarkLightTheme;
184+
CurrentTheme.Palette.Primary = PrimaryColor;
185+
CurrentTheme.PaletteDark.Primary = PrimaryColor;
186+
CurrentTheme.Palette.PrimaryDarken = _userPreferences.PrimaryDarken;
187+
CurrentTheme.Palette.PrimaryLighten = _userPreferences.PrimaryLighten;
188+
CurrentTheme.PaletteDark.PrimaryDarken = _userPreferences.PrimaryDarken;
189+
CurrentTheme.PaletteDark.PrimaryLighten = _userPreferences.PrimaryLighten;
190+
CurrentTheme.LayoutProperties.DefaultBorderRadius = BorderRadius + "px";
191+
CurrentTheme.Typography.Default.FontSize = DefaultFontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
192+
CurrentTheme.Typography.Button.FontSize = _userPreferences.ButtonFontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
193+
CurrentTheme.Typography.Body1.FontSize = _userPreferences.Body1FontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
194+
CurrentTheme.Typography.Body2.FontSize = _userPreferences.Body2FontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
195+
CurrentTheme.Typography.Caption.FontSize = _userPreferences.CaptionFontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
196+
CurrentTheme.Typography.Overline.FontSize = _userPreferences.OverlineFontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
197+
CurrentTheme.Typography.Subtitle1.FontSize = _userPreferences.Subtitle1FontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
198+
CurrentTheme.Typography.Subtitle2.FontSize = _userPreferences.Subtitle1FontSize.ToString("0.0000", CultureInfo.InvariantCulture) + "rem";
199+
200+
201+
178202
await _userPreferencesService.SaveUserPreferences(_userPreferences);
179-
SetBaseTheme(Theme.Theme.ApplicationTheme());
203+
180204

181205
}
182206
}

src/Blazor.Server.UI/Services/UserPreferences/UserPreferences.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ public class UserPreferences
2121
public string SecondaryColor { get; set; } = "#ff4081ff";
2222
public double BorderRadius { get; set; } = 4;
2323
public double DefaultFontSize { get; set; } = 0.8125;
24+
25+
public double Body1FontSize => DefaultFontSize;
26+
public double Body2FontSize => DefaultFontSize - 0.125;
27+
public double ButtonFontSize => DefaultFontSize;
28+
public double CaptionFontSize => DefaultFontSize - 0.125;
29+
public double OverlineFontSize=> DefaultFontSize - 0.125;
30+
public double Subtitle1FontSize => DefaultFontSize + 0.125;
31+
public double Subtitle2FontSize => DefaultFontSize;
2432
public DarkLightMode DarkLightTheme { get; set; }
2533

2634

tests/Application.UnitTests/Common/Mappings/MappingTests.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,20 @@ public void ShouldHaveValidConfiguration()
2929
}
3030

3131
[Test]
32-
[TestCase(typeof(Document), typeof(DocumentDto))]
33-
[TestCase(typeof(KeyValue), typeof(KeyValueDto))]
34-
[TestCase(typeof(Product), typeof(ProductDto))]
35-
[TestCase(typeof(ProductDto), typeof(Product))]
36-
[TestCase(typeof(KeyValueDto), typeof(KeyValue))]
37-
[TestCase(typeof(DocumentDto), typeof(Document))]
38-
public void ShouldSupportMappingFromSourceToDestination(Type source, Type destination)
32+
[TestCase(typeof(Document), typeof(DocumentDto), true)]
33+
[TestCase(typeof(KeyValue), typeof(KeyValueDto), true)]
34+
[TestCase(typeof(Product), typeof(ProductDto), true)]
35+
36+
public void ShouldSupportMappingFromSourceToDestination(Type source, Type destination, bool inverseMap = false)
3937
{
4038
var instance = GetInstanceOf(source);
4139

4240
_mapper.Map(instance, source, destination);
41+
42+
if (inverseMap)
43+
{
44+
ShouldSupportMappingFromSourceToDestination(destination, source, false);
45+
}
4346
}
4447

4548
private object GetInstanceOf(Type type)

0 commit comments

Comments
 (0)