public void ImportWarehouse(Warehouse warehouse) { logger.LogDebug($"Validating warehouse {warehouse.Code}"); WarehouseValidator validator = new WarehouseValidator(); ValidationResult result = validator.Validate(warehouse); Console.WriteLine(warehouse.Code); Console.WriteLine(warehouse.Description); if (result.IsValid) { Data.Warehouse dataWarehouse = this.mapper.Map <Data.Warehouse>(warehouse); logger.LogDebug($"Importing warehouse {warehouse.Code} into repo"); try { //TODO: delete before importing new hierarchy!!! //delete Hierarchy wareHouseRepository.Create(dataWarehouse); } catch (DataAccessLayerException e) { throw new BusinessLayerException("DAL Exception", e); } } else { throw new InvalidWarehouseException(string.Join("\n", result.Errors)); } }
public async Task <EntityValidationResult <Warehouse> > AddWarehouse(Warehouse data) { try { var result = new EntityValidationResult <Warehouse>(); var validationResult = _validator.Validate(data); result.IsValid = validationResult.IsValid; result.Object = data; if (validationResult.IsValid) { data.Id = Guid.NewGuid(); _warehouseRepository.Create(data); await _warehouseRepository.SaveAsync(); } else { result.Errors = validationResult.Errors.Select(x => new EntityValidationFailure { PropertyName = x.PropertyName, ErrorMessage = x.ErrorMessage }).ToList(); } return(result); } catch (Exception ex) { throw ex; } }
private string ValidateWarehouse(Entities.Warehouse blWarehouse) { StringBuilder validationResults = new StringBuilder(); var validator = new WarehouseValidator(); ValidationResult results = validator.Validate(blWarehouse); bool validationSucceeded = results.IsValid; IList <ValidationFailure> failures = results.Errors; foreach (var failure in failures) { validationResults.Append(failure); } return(validationResults.ToString()); }
public async Task <IActionResult> Create([FromBody] AddWarehouseModel item) { var result = _warehouseValidator.Validate(item); if (result.IsValid) { int itemId = await _warehouseService.CreateAsync(item); return(CreatedAtAction(nameof(Get), new { id = itemId }, item)); } else { return(BadRequest(result.Errors.Select(t => t.ErrorMessage))); } }
public bool ValidateWarehouseModel(WarehouseModel warehouse) { try { ValidationResult valRes = _wVal.Validate(warehouse); if (!valRes.IsValid) { throw new BLException(valRes.Errors, new ArgumentException()); } return(true); } catch (BLException ex) { _logger.Error(ex.Message); throw ex; } }