Last active
May 30, 2021 06:17
-
-
Save lakshithacodes/6d7a089b418c72b81594415cdb038ab7 to your computer and use it in GitHub Desktop.
SaveCustomerCommandHandler - CQRS with MediatR
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
public class SaveCustomerCommandHandler : IRequestHandler<SaveCustomerRequestModel, Unit> | |
{ | |
private readonly CustomerDbContext context; | |
public SaveCustomerCommandHandler(CustomerDbContext context) | |
{ | |
this.context = context; | |
} | |
public async Task<Unit> Handle(SaveCustomerRequestModel saveCustomerRequestModel, | |
CancellationToken cancellationToken) | |
{ | |
var newCustomer = new PersonalDetails | |
{ | |
Name = saveCustomerRequestModel.Name, | |
Title = saveCustomerRequestModel.Title, | |
City = saveCustomerRequestModel.City, | |
LoyaltyPoints = saveCustomerRequestModel.LoyaltyPoints | |
}; | |
this.context.PersonalDetails.Add(newCustomer); | |
await this.context.SaveChangesAsync(); | |
return Unit.Value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment