feat: add a campus command
This commit is contained in:
		| @@ -0,0 +1,10 @@ | ||||
| using MediatR; | ||||
|  | ||||
| namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Commands.UpdateCampus; | ||||
|  | ||||
| public class UpdateCampusCommand : IRequest | ||||
| { | ||||
|     public required int Id { get; set; } | ||||
|     public string? FullName { get; set; } | ||||
|     public string? Address { get; set; } | ||||
| } | ||||
| @@ -0,0 +1,23 @@ | ||||
| using MediatR; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Mirea.Api.DataAccess.Application.Common.Exceptions; | ||||
| using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; | ||||
| using System.Threading; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Mirea.Api.DataAccess.Application.Cqrs.Campus.Commands.UpdateCampus; | ||||
|  | ||||
| public class UpdateCampusCommandHandler(ICampusDbContext dbContext) : IRequestHandler<UpdateCampusCommand> | ||||
| { | ||||
|     public async Task Handle(UpdateCampusCommand request, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var entity = await dbContext.Campuses.FirstOrDefaultAsync(c => c.Id == request.Id, cancellationToken: cancellationToken) ?? throw new NotFoundException(typeof(Domain.Schedule.Campus), nameof(Domain.Schedule.Campus.Id), request.Id); | ||||
|  | ||||
|         if (!string.IsNullOrEmpty(request.FullName)) | ||||
|             entity.FullName = request.FullName; | ||||
|         if (!string.IsNullOrEmpty(request.Address)) | ||||
|             entity.Address = request.Address; | ||||
|  | ||||
|         await dbContext.SaveChangesAsync(cancellationToken); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user