Creating endpoint that allows for student update

This commit is contained in:
2019-04-27 15:23:12 -04:00
parent 1a95acac01
commit 8cacaa36ce
7 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
using BrightGlimmer.Domain;
using MediatR;
using System;
using System.Collections.Generic;
using System.Text;
namespace BrightGlimmer.Service.Commands
{
public class UpdateStudentCommand : IRequest<Student>
{
public Guid Id { get; set; }
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; }
}
}

View File

@@ -0,0 +1,39 @@
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 UpdateStudentCommandHandler : IRequestHandler<UpdateStudentCommand, Student>
{
private readonly ICommandRepository<Student> repository;
public UpdateStudentCommandHandler(ICommandRepository<Student> repository)
{
this.repository = repository;
}
public async Task<Student> Handle(UpdateStudentCommand request, CancellationToken cancellationToken)
{
var student = await repository.GetAsync(request.Id);
student.FirstName = request.FirstName;
student.MiddleName = request.MiddleName;
student.LastName = request.LastName;
student.Email = request.Email;
if (student.Address != null)
{
}
return student;
}
}
}