31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
namespace Brizco.Repository.Handlers.Sections;
|
|
|
|
public class UpdateSectionCommandHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
|
|
: IRequestHandler<UpdateSectionCommand, bool>
|
|
{
|
|
public async Task<bool> Handle(UpdateSectionCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var shift = await repositoryWrapper.SetRepository<Section>()
|
|
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
|
|
if (shift == null)
|
|
throw new AppException("Section not found", ApiResultStatusCode.NotFound);
|
|
|
|
if (currentUserService.ComplexId == null)
|
|
throw new AppException("ComplexId is null", ApiResultStatusCode.NotFound);
|
|
if (!Guid.TryParse(currentUserService.ComplexId, out Guid complexId))
|
|
throw new AppException("ComplexId is wrong", ApiResultStatusCode.NotFound);
|
|
|
|
var newSection = Section.Create(request.Title,
|
|
request.Description,
|
|
complexId);
|
|
newSection.Id = request.Id;
|
|
|
|
|
|
repositoryWrapper.SetRepository<Section>()
|
|
.Update(newSection);
|
|
|
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
|
|
return true;
|
|
}
|
|
} |