Fleshed out entity classes and created command to create student
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Interfaces\" />
|
||||
<Folder Include="Handlers\CommandHandlers\" />
|
||||
<Folder Include="Handlers\QueryHandlers\" />
|
||||
<Folder Include="Queries\" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
using MediatR;
|
||||
using BrightGlimmer.Domain;
|
||||
using MediatR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BrightGlimmer.Service.Commands
|
||||
{
|
||||
public class CreateStudentCommand : IRequest<bool>
|
||||
public class CreateStudentCommand : IRequest<Student>
|
||||
{
|
||||
public string FirstName { get; set; }
|
||||
public string MiddleName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string Email { get; set; }
|
||||
public List<Phone> Phones { get; set; }
|
||||
public Address Address { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using BrightGlimmer.Data.Interfaces;
|
||||
using BrightGlimmer.Domain;
|
||||
using BrightGlimmer.Service.Commands;
|
||||
using MediatR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BrightGlimmer.Service.Handlers.CommandHandlers
|
||||
{
|
||||
public class CreateStudentCommandHandler : IRequestHandler<CreateStudentCommand, Student>
|
||||
{
|
||||
private readonly ICommandRepository<Student> repository;
|
||||
|
||||
public CreateStudentCommandHandler(ICommandRepository<Student> repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public async Task<Student> Handle(CreateStudentCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var student = new Student(request.FirstName,
|
||||
request.LastName,
|
||||
request.Email,
|
||||
request.Phones,
|
||||
request.Address);
|
||||
repository.Create(student);
|
||||
await repository.UnitOfWork.SaveChangesAsync();
|
||||
return student;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user