forked from neozhu/CleanArchitectureWithBlazorServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'neozhu:main' into main
- Loading branch information
Showing
184 changed files
with
10,112 additions
and
7,100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace CleanArchitecture.Blazor.Application.Common.Models; | ||
|
||
public class UploadRequest | ||
{ | ||
public UploadRequest(string fileName, UploadType uploadType, byte[] data) | ||
public UploadRequest(string fileName, UploadType uploadType, byte[] data, bool overwrite=false) | ||
{ | ||
FileName = fileName; | ||
UploadType = uploadType; | ||
Data = data; | ||
Overwrite = overwrite; | ||
} | ||
|
||
public string FileName { get; set; } | ||
public string? Extension { get; set; } | ||
public UploadType UploadType { get; set; } | ||
public bool Overwrite { get; set; } | ||
public byte[] Data { get; set; } | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Application/Common/Security/UserProfileStateService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace CleanArchitecture.Blazor.Application.Common.Security; | ||
|
||
public class UserProfileStateService | ||
{ | ||
private UserProfile _userProfile = new UserProfile() { Email="", UserId="", UserName="" }; | ||
|
||
public UserProfile UserProfile | ||
{ | ||
get => _userProfile; | ||
set | ||
{ | ||
_userProfile = value; | ||
NotifyStateChanged(); | ||
} | ||
} | ||
|
||
public event Action OnChange; | ||
Check warning on line 23 in src/Application/Common/Security/UserProfileStateService.cs GitHub Actions / build
|
||
|
||
private void NotifyStateChanged() => OnChange?.Invoke(); | ||
|
||
public void UpdateUserProfile(string? profilePictureDataUrl, string? fullName,string? phoneNumber) | ||
{ | ||
_userProfile.ProfilePictureDataUrl = profilePictureDataUrl; | ||
_userProfile.DisplayName = fullName; | ||
_userProfile.PhoneNumber = phoneNumber; | ||
NotifyStateChanged(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/Application/Features/Contacts/Commands/AddEdit/AddEditContactCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using CleanArchitecture.Blazor.Application.Features.Contacts.DTOs; | ||
using CleanArchitecture.Blazor.Application.Features.Contacts.Caching; | ||
namespace CleanArchitecture.Blazor.Application.Features.Contacts.Commands.AddEdit; | ||
|
||
public class AddEditContactCommand: ICacheInvalidatorRequest<Result<int>> | ||
{ | ||
[Description("Id")] | ||
public int Id { get; set; } | ||
[Description("Name")] | ||
public string Name {get;set;} = String.Empty; | ||
[Description("Description")] | ||
public string? Description {get;set;} | ||
[Description("Email")] | ||
public string? Email {get;set;} | ||
[Description("Phone Number")] | ||
public string? PhoneNumber {get;set;} | ||
[Description("Country")] | ||
public string? Country {get;set;} | ||
|
||
|
||
public string CacheKey => ContactCacheKey.GetAllCacheKey; | ||
public CancellationTokenSource? SharedExpiryTokenSource => ContactCacheKey.GetOrCreateTokenSource(); | ||
|
||
private class Mapping : Profile | ||
{ | ||
public Mapping() | ||
{ | ||
CreateMap<ContactDto, AddEditContactCommand>(MemberList.None); | ||
CreateMap<AddEditContactCommand,Contact>(MemberList.None); | ||
|
||
} | ||
} | ||
} | ||
|
||
public class AddEditContactCommandHandler : IRequestHandler<AddEditContactCommand, Result<int>> | ||
{ | ||
private readonly IApplicationDbContext _context; | ||
private readonly IMapper _mapper; | ||
private readonly IStringLocalizer<AddEditContactCommandHandler> _localizer; | ||
public AddEditContactCommandHandler( | ||
IApplicationDbContext context, | ||
IStringLocalizer<AddEditContactCommandHandler> localizer, | ||
IMapper mapper | ||
) | ||
{ | ||
_context = context; | ||
_localizer = localizer; | ||
_mapper = mapper; | ||
} | ||
public async Task<Result<int>> Handle(AddEditContactCommand request, CancellationToken cancellationToken) | ||
{ | ||
if (request.Id > 0) | ||
{ | ||
var item = await _context.Contacts.FindAsync(new object[] { request.Id }, cancellationToken) ?? throw new NotFoundException($"Contact with id: [{request.Id}] not found."); | ||
item = _mapper.Map(request, item); | ||
// raise a update domain event | ||
item.AddDomainEvent(new ContactUpdatedEvent(item)); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return await Result<int>.SuccessAsync(item.Id); | ||
} | ||
else | ||
{ | ||
var item = _mapper.Map<Contact>(request); | ||
// raise a create domain event | ||
item.AddDomainEvent(new ContactCreatedEvent(item)); | ||
_context.Contacts.Add(item); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return await Result<int>.SuccessAsync(item.Id); | ||
} | ||
|
||
} | ||
} | ||
|
6 changes: 3 additions & 3 deletions
6
...ddEdit/AddEditCustomerCommandValidator.cs → ...AddEdit/AddEditContactCommandValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/Application/Features/Contacts/Commands/Create/CreateContactCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
using System.ComponentModel; | ||
using CleanArchitecture.Blazor.Application.Features.Contacts.DTOs; | ||
using CleanArchitecture.Blazor.Application.Features.Contacts.Caching; | ||
|
||
namespace CleanArchitecture.Blazor.Application.Features.Contacts.Commands.Create; | ||
|
||
public class CreateContactCommand: ICacheInvalidatorRequest<Result<int>> | ||
{ | ||
[Description("Id")] | ||
public int Id { get; set; } | ||
[Description("Name")] | ||
public string Name {get;set;} = String.Empty; | ||
[Description("Description")] | ||
public string? Description {get;set;} | ||
[Description("Email")] | ||
public string? Email {get;set;} | ||
[Description("Phone Number")] | ||
public string? PhoneNumber {get;set;} | ||
[Description("Country")] | ||
public string? Country {get;set;} | ||
|
||
public string CacheKey => ContactCacheKey.GetAllCacheKey; | ||
public CancellationTokenSource? SharedExpiryTokenSource => ContactCacheKey.GetOrCreateTokenSource(); | ||
private class Mapping : Profile | ||
{ | ||
public Mapping() | ||
{ | ||
CreateMap<ContactDto,CreateContactCommand>(MemberList.None); | ||
CreateMap<CreateContactCommand,Contact>(MemberList.None); | ||
} | ||
} | ||
} | ||
|
||
public class CreateContactCommandHandler : IRequestHandler<CreateContactCommand, Result<int>> | ||
{ | ||
private readonly IApplicationDbContext _context; | ||
private readonly IMapper _mapper; | ||
private readonly IStringLocalizer<CreateContactCommand> _localizer; | ||
public CreateContactCommandHandler( | ||
IApplicationDbContext context, | ||
IStringLocalizer<CreateContactCommand> localizer, | ||
IMapper mapper | ||
) | ||
{ | ||
_context = context; | ||
_localizer = localizer; | ||
_mapper = mapper; | ||
} | ||
public async Task<Result<int>> Handle(CreateContactCommand request, CancellationToken cancellationToken) | ||
{ | ||
var item = _mapper.Map<Contact>(request); | ||
// raise a create domain event | ||
item.AddDomainEvent(new ContactCreatedEvent(item)); | ||
_context.Contacts.Add(item); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return await Result<int>.SuccessAsync(item.Id); | ||
} | ||
} | ||
|
6 changes: 3 additions & 3 deletions
6
.../Create/CreateCustomerCommandValidator.cs → ...s/Create/CreateContactCommandValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.