Skip to content

Commit a7a1c8b

Browse files
first commit (having trouble in configuring entity props)
1 parent cd62be3 commit a7a1c8b

File tree

348 files changed

+24059
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

348 files changed

+24059
-0
lines changed

.idea/.idea.Movie_asp/.idea/.gitignore

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.Movie_asp/.idea/indexLayout.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Application/Application.csproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="FluentResults" Version="3.15.2" />
11+
<PackageReference Include="MediatR" Version="12.1.1" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\Domain\Domain.csproj" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Domain.Entities;
2+
using Microsoft.EntityFrameworkCore;
3+
using Movie_asp.Entities;
4+
5+
namespace Application.Data;
6+
7+
public interface IApplicationDbContext
8+
{
9+
public DbSet<User> Users { get; set; }
10+
11+
public Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
12+
}

Application/Data/IUnitOfWork.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Application.Data;
2+
3+
public interface IUnitOfWork
4+
{
5+
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Domain.Entities;
2+
using FluentResults;
3+
using MediatR;
4+
using Movie_asp.Entities;
5+
6+
namespace Application.Users.Commands;
7+
8+
public record AddUserCommand(
9+
string FullName,
10+
string Username,
11+
string Password,
12+
string Email) : IRequest<Result<User>>;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Application.Data;
2+
using Domain.Entities;
3+
using Domain.Repositories;
4+
using FluentResults;
5+
using MediatR;
6+
using Movie_asp.Entities;
7+
using Movie_asp.ValueObjects;
8+
9+
namespace Application.Users.Commands;
10+
11+
public class AddUserCommandHandler : IRequestHandler<AddUserCommand, Result<User>>
12+
{
13+
14+
private readonly IUserRepository _userRepository;
15+
private readonly IUnitOfWork _unitOfWork;
16+
17+
18+
public AddUserCommandHandler(IUserRepository userRepository, IUnitOfWork unitOfWork)
19+
{
20+
_userRepository = userRepository;
21+
_unitOfWork = unitOfWork;
22+
}
23+
24+
25+
public async Task<Result<User>> Handle(AddUserCommand request, CancellationToken cancellationToken)
26+
{
27+
var fullNameResult = UserFullName.Create(request.FullName);
28+
var usernameResult = Username.Create(request.Username);
29+
var passwordResult = Password.Create(request.Password);
30+
var emailResult = Email.Create(request.Email);
31+
32+
33+
var user = new User(
34+
new UserId(Guid.NewGuid()),
35+
fullNameResult.Value,
36+
usernameResult.Value,
37+
passwordResult.Value,
38+
emailResult.Value,
39+
new CreatedAt(DateTime.Now)
40+
);
41+
42+
_userRepository.Add(user);
43+
44+
await _unitOfWork.SaveChangesAsync(cancellationToken);
45+
return Result.Ok(user);
46+
}
47+
}

0 commit comments

Comments
 (0)