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 { 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); } }