public override async Task <RequestResult <Guid> > Handle(RemoveMeasureCommand request, CancellationToken cancellationToken) { var measure = await _measuresRepository.GetMeasure(request.MeasureGuid); if (measure.IsBaseline) { throw new DomainException(ErrorCode.CantRemoveBaselineMeasure, new { request.MeasureGuid }); } measure.Deactivate(); await _measuresRepository.Save(measure); return(request.Success()); }
public override async Task <RequestResult <MeasureDto> > Handle(UpdateMeasureCommand request, CancellationToken cancellationToken) { if (await _measuresRepository.IsNameTaken(request.MeasureGuid, request.Name)) { throw new DomainException(ErrorCode.MeasureNameTaken, new { request.Name }); } if (await _measuresRepository.IsSymbolTaken(request.MeasureGuid, request.Symbol)) { throw new DomainException(ErrorCode.MeasureSymbolTaken, new { request.Symbol }); } var measure = await _measuresRepository.GetMeasure(request.MeasureGuid); measure .SetName(request.Name) .SetSymbol(request.Symbol) .SetWeight(request.IsWeight, request.ValueInGrams); await _measuresRepository.Save(measure); return(request.Success(_mapper.Map <MeasureDto>(measure))); }