public async Task <bool> Handle(UnregisterCropCommand request, CancellationToken cancellationToken) { var planification = await _repo.GetByIdAsync(request.CropId); _ = planification ?? throw new NullReferenceException("Planification with this id doesn't extst!"); planification.RemoveCrop(request.CropId); _log.LogInformation("-> Canceling Crop - Crop: {@Crop} is unregistred from {@Planification}", request.CropId, planification.Id); await _repo.Update(planification); return(await _repo.Uow.SaveChangesEventsAsync(cancellationToken)); }
public async Task <bool> Handle(RegisterCropCommand request, CancellationToken cancellationToken) { var planification = await _repo.GetByIdAsync(request.PlanificationId); _ = planification ?? throw new NullReferenceException("Planification wasn't found or dont't exist!"); var croptype = await _cRepo.GetByCodeAsync(request.CropCode); _ = croptype ?? throw new NullReferenceException("There is no crop type with this code!"); planification.AddCrop(croptype , new Surface(request.Surface) , new Code(request.PhysicalBlockCode) , new Code(request.ParcelCode)); await _repo.Update(planification); _log.LogInformation("-> Registring Crop -> Crop : {@CropTypeCod} - {@Surface}", request.CropCode, request.Surface); return(await _repo.Uow.SaveChangesEventsAsync()); }