public async Task UnassignAsync(CarColorAssignmentCommand unassignCommand) { var itemsToRemove = await _readRepository.GetAsync(_modelColorFiltersProvider.ByModelIdAndColorId(unassignCommand.ModelId, unassignCommand.ColorId)); await WriteRepository.RemoveRangeAsync(itemsToRemove); await UnitOfWork.CommitAsync(); }
protected override bool PreValidate(ValidationContext <CarColorAssignmentCommand> context, ValidationResult result) { var isExists = ReadRepository.ValidateExists(_modelColorFiltersProvider.ByModelIdAndColorId(context.InstanceToValidate.ModelId, context.InstanceToValidate.ColorId)); if (isExists) { result.Errors.Add(new ValidationFailure("", "Item is already assigned!")); return(false); } return(true); }
private async Task <bool> ColorIsValid(CarStockUpdateCommand model, int id, CancellationToken cancellationToken) { return(await Task.Run(() => ReadRepository.ValidateExists(_modelColorFiltersProvider.ByModelIdAndColorId(model.ModelId, model.ColorId)), cancellationToken)); }