public override ValidationOutput DTOIsValidForUpdate(MaterialDto consideredDto) { ValidationOutput validationOutput = new ValidationOutputBadRequest(); if (consideredDto.Name != null) { if (!NameIsValid(consideredDto.Name)) { validationOutput.AddError("Name of material", "New name'" + consideredDto.Name + "' is not valid!"); } } if (consideredDto.Description != null) { if (!DescriptionIsValid(consideredDto.Description)) { validationOutput.AddError("Description of material", "New description'" + consideredDto.Description + "' is not valid!"); } } if (consideredDto.Price != null) { ValidationOutput priceDTOValidationOutput = _priceDTOValidator.DTOIsValid(consideredDto.Price); if (priceDTOValidationOutput.HasErrors()) { priceDTOValidationOutput.AppendToAllkeys("Material '" + consideredDto.Reference + "' > "); validationOutput.Join(priceDTOValidationOutput); } } return(validationOutput); }
public ValidationOutput PossibleWidthsIsValid(DimensionValuesDto consideredDto) { ValidationOutput validationOutput = new ValidationOutputBadRequest(); List <ValuesDto> possibleWidths = new List <ValuesDto>(); foreach (var setOfValuesDto in consideredDto.PossibleWidths) { ValidationOutput eachValueValidationOutput = _valuesDTOValidator.DTOIsValid(setOfValuesDto); if (eachValueValidationOutput.HasErrors()) { validationOutput.Join(eachValueValidationOutput); return(validationOutput); } validationOutput = new ValidationOutputBadRequest(); if (possibleWidths.Contains(setOfValuesDto)) { if (setOfValuesDto is ContinuousValueDto) { ContinuousValueDto temp = (ContinuousValueDto)setOfValuesDto; validationOutput.AddError("Dimension's widths", "The width interval [" + temp.MinValue + ", " + temp.MaxValue + "] is duplicated in the list of possible widths."); } if (setOfValuesDto is DiscreteValueDto) { validationOutput.AddError("Dimension's widths", "The width '" + setOfValuesDto + "' is duplicated in the list of possible widths."); } return(validationOutput); } possibleWidths.Add(setOfValuesDto); } return(validationOutput); }
public override ValidationOutput DTOIsValidForUpdate(FinishDto consideredDto) { ValidationOutput validationOutput = new ValidationOutputBadRequest(); if (!ReferenceIsValid(consideredDto.Reference)) { validationOutput.AddError("Reference of finish", "New reference '" + consideredDto.Reference + "' is invalid!"); } if (!NameIsValid(consideredDto.Name)) { validationOutput.AddError("Name of finish", "New name '" + consideredDto.Name + "' is invalid!"); } if (!DescriptionIsValid(consideredDto.Description)) { validationOutput.AddError("Description of finish", "New description '" + consideredDto.Description + "' is invalid!"); } if (consideredDto.Price != null) { ValidationOutput priceDTOValidationOutput = _priceDTOValidator.DTOIsValid(consideredDto.Price); if (priceDTOValidationOutput.HasErrors()) { priceDTOValidationOutput.AppendToAllkeys("Finish '" + consideredDto.Reference + "' | "); validationOutput.Join(priceDTOValidationOutput); } } else { validationOutput.AddError("Price of finish", "The price has can not be null!"); } return(validationOutput); }
public async Task <IActionResult> Create([FromHeader(Name = "Authorization")] string authorization, ChildConfiguredProductDto receivedDto) { if (!_userValidationService.CheckAuthorizationToken(authorization)) { return(Unauthorized()); } var userRef = await _userValidationService.GetUserRef(authorization.Split(" ")[1]); _logger.logInformation(userRef, LoggingEvents.PostItem, "Creating By Dto: {0}", receivedDto.Reference); ValidationOutput validationOutput = _configuredProductService.Register(receivedDto); if (validationOutput.HasErrors()) { if (validationOutput is ValidationOutputBadRequest) { _logger.logCritical(userRef, LoggingEvents.PostBadRequest, "Creating Configured Product Failed: {0}", ((ValidationOutputBadRequest)validationOutput).ToString()); return(BadRequest(validationOutput.FoundErrors)); } if (validationOutput is ValidationOutputNotFound) { _logger.logCritical(userRef, LoggingEvents.PostNotFound, "Creating Configured Product Failed: {0}", ((ValidationOutputNotFound)validationOutput).ToString()); return(NotFound(validationOutput.FoundErrors)); } _logger.logCritical(userRef, LoggingEvents.PostInternalError, "Type of validation output not recognized. Please contact your software provider."); return(BadRequest("Type of validation output not recognized. Please contact your software provider.")); } else { ConfiguredProductDto dto = (ConfiguredProductDto)validationOutput.DesiredReturn; _logger.logInformation(userRef, LoggingEvents.PostOk, "Creating Configured Product Succeeded: {0}", dto.ToString()); return(CreatedAtRoute("GetConfiguredProduct", new { reference = receivedDto.Reference }, dto)); } }
public ValidationOutput GetAllInfoByReference(string reference) { ValidationOutput validationOutput = _configuredProductDTOValidator.DTOReferenceIsValid(reference); if (validationOutput.HasErrors()) { return(validationOutput); } ConfiguredProduct configuredProduct = _configuredProductRepository.GetByReference(reference); if (configuredProduct == null) { validationOutput = new ValidationOutputNotFound(); validationOutput.AddError("Configured Product's reference", "There are no configured products with the given reference"); return(validationOutput); } var product = _mapper.Map <ProductOrderDto>(configuredProduct); foreach (var part in product.Parts) { GetAllByReference(part.ConfiguredChildReference, product); } validationOutput.DesiredReturn = product; return(validationOutput); }
public async Task <IActionResult> DeleteProduct([FromHeader(Name = "Authorization")] string authorization, [FromRoute] string reference) { if (!_userValidationService.CheckAuthorizationToken(authorization)) { return(Unauthorized()); } var userRef = await _userValidationService.GetUserRef(authorization.Split(" ")[1]); _logger.logInformation(userRef, LoggingEvents.SoftDeleteItem, "Deleting By Reference: {0}", reference); ValidationOutput validationOutput = _configuredProductService.Remove(reference); if (validationOutput.HasErrors()) { if (validationOutput is ValidationOutputBadRequest) { _logger.logCritical(userRef, LoggingEvents.DeleteBadRequest, "Deleting Failed: {0}", ((ValidationOutputBadRequest)validationOutput).ToString()); return(BadRequest(validationOutput.FoundErrors)); } if (validationOutput is ValidationOutputNotFound) { _logger.logCritical(userRef, LoggingEvents.DeleteNotFound, "Deleting Failed: {0}", ((ValidationOutputNotFound)validationOutput).ToString()); return(NotFound(validationOutput.FoundErrors)); } _logger.logCritical(userRef, LoggingEvents.DeleteInternalError, "Type of validation output not recognized. Please contact your software provider."); return(BadRequest("Type of validation output not recognized. Please contact your software provider.")); } else { _logger.logInformation(userRef, LoggingEvents.DeleteNoContent, "Deleting Configured Product: {0}", reference); _logger.logInformation(userRef, LoggingEvents.SoftDeleteOk, "Deleting Configured Product: {0}", reference); return(NoContent()); } }
private void ConfiguredMaterialDtoIsValid(ConfiguredMaterialDto dto, ValidationOutput validationOutput) { if (dto == null) { validationOutput.AddError("Material", "Material is missing!"); return; } if (dto.OriginMaterialReference == null) { validationOutput.AddError("Material's reference", "Material's reference is missing!"); } if (dto.ColorReference == null) { validationOutput.AddError("Color", "Color is missing!"); return; } if (dto.ColorReference == null) { validationOutput.AddError("Color's reference", "Color's reference is missing!"); } if (dto.FinishReference == null) { validationOutput.AddError("Finish", "Finish is missing!"); return; } if (dto.FinishReference == null) { validationOutput.AddError("Finish's reference", "Finish's reference is missing!"); } }
private void ProductReferenceIsValid(string productReference, ValidationOutput validationOutput) { if (productReference == null) { validationOutput.AddError("Product's reference", "Product's reference is missing!"); } }
// ============ Methods to CREATE something ============ /** * Method that will validate and create a new material in the database. * * Validations performed: * 1. Validation of the new material's reference (business rules); * 2. Validation of the new material's reference (database); * 3. Validation of the received info. (name, description, colors, finishes) (business rules) */ public ValidationOutput Register(MaterialDto dto) { //1. ValidationOutput validationOutput = _materialDTOValidator.DTOReferenceIsValid(dto.Reference); if (validationOutput.HasErrors()) { return(validationOutput); } //2. validationOutput = new ValidationOutputBadRequest(); if (MaterialExists(dto.Reference)) { validationOutput.AddError("Reference of material", "A material with the reference '" + dto.Reference + "' already exists in the system!"); return(validationOutput); } //3. validationOutput = _materialDTOValidator.DTOIsValidForRegister(dto); if (validationOutput.HasErrors()) { return(validationOutput); } if (dto.Colors.Count > 0) { validationOutput = PrivateAddColorsWithMaterial(dto.Colors); if (validationOutput.HasErrors()) { return(validationOutput); } } if (dto.Finishes.Count > 0) { validationOutput = PrivateAddFinishesWithMaterial(dto.Finishes); if (validationOutput.HasErrors()) { return(validationOutput); } } //NOTA: Ainda que este método verifique se o atributo Price é != null, nós, aqui no Register, nunca deixamos que seja null devido às validações AddNewPriceToMaterialHistory(dto); foreach (var finish in dto.Finishes) { finish.IsActive = true; } //If we reached here then that means we can add the new material validationOutput.DesiredReturn = _mapper.Map <MaterialDto>( _materialRepository.Add(_mapper.Map <Material>(dto))); return(validationOutput); }
public WarningList() : base(null) { this.Caption = Resources.ToolWindowTitle; this.BitmapResourceID = 301; this.BitmapIndex = 1; _validationOutput = new ValidationOutput(); }
/// <summary> /// Checks if a Waternet can be generated. /// </summary> /// <exception cref="WaternetKernelWrapperException">Thrown when the Waternet can not be generated.</exception> private void CheckIfWaternetCanBeGenerated() { ValidationOutput output = validator.ValidateWaternetCreator(); if (!output.IsValid) { throw new WaternetKernelWrapperException(); } }
public override ValidationOutput DTOIsValidForUpdate(ProductDto consideredDto) { ValidationOutput validationOutput = new ValidationOutputBadRequest(); if (consideredDto.Name != null) { if (!NameIsValid(consideredDto.Name)) { validationOutput.AddError("Name of product", "New name '" + consideredDto.Name + "' is not valid!"); } } if (consideredDto.Description != null) { if (!DescriptionIsValid(consideredDto.Description)) { validationOutput.AddError("Description of product", "New description '" + consideredDto.Description + "' is not valid!"); } } if (consideredDto.Price != null) { ValidationOutput priceDTOValidationOutput = _priceDTOValidator.DTOIsValid(consideredDto.Price); if (priceDTOValidationOutput.HasErrors()) { priceDTOValidationOutput.AppendToAllkeys("Product '" + consideredDto.Reference + "' > "); validationOutput.Join(priceDTOValidationOutput); } } if (consideredDto.SlotDefinition != null) { ValidationOutput slotDefinitionDTOValidationOutput = _slotDefinitionDTOValidator.DTOIsValid(consideredDto.SlotDefinition); if (slotDefinitionDTOValidationOutput.HasErrors()) { slotDefinitionDTOValidationOutput.AppendToAllkeys("Product '" + consideredDto.Reference + "' > "); validationOutput.Join(slotDefinitionDTOValidationOutput); } } var modelGroup = consideredDto.ModelGroup; if (modelGroup != null) { ValidationOutput modelGroupValidationOutput = _modelGroupDTOValidator.DTOIsValid(modelGroup); if (validationOutput.HasErrors()) { validationOutput.Join(modelGroupValidationOutput); } } return(validationOutput); }
public ValidationOutput GetAvailableProducts(string reference) { ValidationOutput validationOutput = _configuredProductDTOValidator.DTOReferenceIsValid(reference); if (validationOutput.HasErrors()) { return(validationOutput); } ConfiguredProduct configuredProduct = _configuredProductRepository.GetByReference(reference); if (configuredProduct == null) { validationOutput = new ValidationOutputNotFound(); validationOutput.AddError("Configured Product's reference", "There are no configured products with the given reference"); return(validationOutput); } List <ProductDto> productsDto = (List <ProductDto>)_productService .GetPartProductsAvailableToProduct(configuredProduct.ProductReference).DesiredReturn; List <Product> productsAvailable = new List <Product>(); foreach (var dto in productsDto) { productsAvailable.Add(_mapper.Map <Product>(dto)); } List <ProductDto> productsAvailableFinal = new List <ProductDto>(); foreach (var product in productsAvailable) { if (ProductFitsConfigured(product.Dimensions, configuredProduct.ConfiguredDimension)) { productsAvailableFinal.Add(_mapper.Map <ProductDto>(product)); } } var category_products = new List <CategoryProductDto>(); foreach (var product in productsAvailableFinal) { var categoryName = _categoryRepository.GetByReference(product.CategoryReference).Name; CategoryProductDto cpd = new CategoryProductDto(categoryName); if (!category_products.Contains(cpd)) { cpd.Products.Add(product); category_products.Add(cpd); } else { int index = category_products.IndexOf(cpd); category_products[index].Products.Add(product); } } validationOutput.DesiredReturn = category_products; return(validationOutput); }
/** * Method that will join the errors found of two ValidationOutput objects */ public bool Join(ValidationOutput other) { if (!other.GetType().Equals(this.GetType())) { return(false); } foreach (var key in other.FoundErrors.Keys.ToList()) { FoundErrors.Add(key, other.FoundErrors[key]); } return(true); }
public IEnumerable <Message> Validate() { try { ValidationOutput output = validator.ValidateWaternetCreator(); return(output.Messages); } catch (Exception e) { throw new WaternetKernelWrapperException(e.Message, e); } }
public async Task <IActionResult> DeleteFinishPriceHistoryFromMaterial([FromHeader(Name = "Authorization")] string authorization, [FromRoute] string reference, [FromRoute] string finishReference, [FromBody] IEnumerable <PriceHistoryDto> enumerablePriceHistoryDto) { if (!_userValidationService.CheckAuthorizationToken(authorization)) { return(Unauthorized()); } if (!(await _userValidationService.ValidateContentManager(authorization.Split(" ")[1]))) { return(Unauthorized()); } var userRef = await _userValidationService.GetUserRef(authorization.Split(" ")[1]); _logger.logInformation(userRef, LoggingEvents.HardDeleteItem, "Deleting Price History Of Finish {0} of Material By Reference: {1}", finishReference, reference); ValidationOutput validationOutput = _materialService.DeleteFinishPriceHistoryFromMaterial(reference, finishReference, enumerablePriceHistoryDto); if (validationOutput.HasErrors()) { if (validationOutput is ValidationOutputBadRequest) { _logger.logCritical(userRef, LoggingEvents.DeleteBadRequest, "Deleting Failed: {0}", ((ValidationOutputBadRequest)validationOutput).ToString()); return(BadRequest(validationOutput.FoundErrors)); } if (validationOutput is ValidationOutputNotFound) { _logger.logCritical(userRef, LoggingEvents.DeleteNotFound, "Deleting Failed: {0}", ((ValidationOutputNotFound)validationOutput).ToString()); return(NotFound(validationOutput.FoundErrors)); } _logger.logCritical(userRef, LoggingEvents.DeleteInternalError, "Type of validation output not recognized. Please contact your software provider."); return(BadRequest("Type of validation output not recognized. Please contact your software provider.")); } else { _logger.logInformation(userRef, LoggingEvents.DeleteNoContent, "Deleting Price History Of Finish {0} of Material By Reference: {1}", finishReference, reference, EnumerableUtils.convert(enumerablePriceHistoryDto)); _logger.logInformation(userRef, LoggingEvents.HardDeleteOk, "Deleting Price History Of Finish {0} of Material By Reference: {1}", finishReference, reference, EnumerableUtils.convert(enumerablePriceHistoryDto)); return(NoContent()); } }
public async Task <IActionResult> AddPriceDateItems([FromHeader(Name = "Authorization")] string authorization, [FromRoute] string materialReference, string finishReference, [FromBody] IEnumerable <PriceHistoryDto> enumerablePriceHistory) { if (!_userValidationService.CheckAuthorizationToken(authorization)) { return(Unauthorized()); } if (!(await _userValidationService.ValidateContentManager(authorization.Split(" ")[1]))) { return(Unauthorized()); } var userRef = await _userValidationService.GetUserRef(authorization.Split(" ")[1]); object[] array = new object[3]; array[0] = materialReference; array[1] = finishReference; array[2] = EnumerableUtils.convert(enumerablePriceHistory); _logger.logInformation(userRef, LoggingEvents.PostItem, "Adding Prices to Finish By Reference: {0} - {1} -- {2}", array); ValidationOutput validationOutput = _materialService.AddPriceHistoryItemsToFinishOfMaterial(materialReference, finishReference, enumerablePriceHistory); if (validationOutput.HasErrors()) { if (validationOutput is ValidationOutputBadRequest) { _logger.logCritical(userRef, LoggingEvents.PostBadRequest, "Adding Prices to Finish Failed: {0}", ((ValidationOutputBadRequest)validationOutput).ToString()); return(BadRequest(validationOutput.FoundErrors)); } if (validationOutput is ValidationOutputNotFound) { _logger.logCritical(userRef, LoggingEvents.PostNotFound, "Adding Prices to Finish Failed: {0}", ((ValidationOutputNotFound)validationOutput).ToString()); return(NotFound(validationOutput.FoundErrors)); } _logger.logCritical(userRef, LoggingEvents.PostInternalError, "Type of validation output not recognized. Please contact your software provider."); return(BadRequest("Type of validation output not recognized. Please contact your software provider.")); } else { _logger.logInformation(userRef, LoggingEvents.PostOk, "Adding Prices to Finish of Material Succeeded: {0}", array[2]); return(Ok(validationOutput.DesiredReturn)); } }
public async Task <IActionResult> UpdateMaterial([FromHeader(Name = "Authorization")] string authorization, [FromRoute] string reference, [FromBody] MaterialDto materialDto) { if (!_userValidationService.CheckAuthorizationToken(authorization)) { return(Unauthorized()); } if (!(await _userValidationService.ValidateContentManager(authorization.Split(" ")[1]))) { return(Unauthorized()); } var userRef = await _userValidationService.GetUserRef(authorization.Split(" ")[1]); _logger.logInformation(userRef, LoggingEvents.UpdateItem, "Updating By Reference: {0}", reference); ValidationOutput validationOutput = _materialService.Update(reference, materialDto); if (validationOutput.HasErrors()) { if (validationOutput is ValidationOutputBadRequest) { _logger.logCritical(userRef, LoggingEvents.UpdateBadRequest, "Updating Failed: {0}", ((ValidationOutputBadRequest)validationOutput).ToString()); return(BadRequest(validationOutput.FoundErrors)); } if (validationOutput is ValidationOutputNotFound) { _logger.logCritical(userRef, LoggingEvents.UpdateNotFound, "Updating Failed: {0}", ((ValidationOutputNotFound)validationOutput).ToString()); return(NotFound(validationOutput.FoundErrors)); } if (validationOutput is ValidationOutputForbidden) { _logger.logCritical(userRef, LoggingEvents.UpdateForbidden, "Updating Failed: {0}", ((ValidationOutputForbidden)validationOutput).ToString()); return(new ForbiddenObjectResult(validationOutput.FoundErrors)); } _logger.logCritical(userRef, LoggingEvents.UpdateInternalError, "Type of validation output not recognized. Please contact your software provider."); return(BadRequest("Type of validation output not recognized. Please contact your software provider.")); } else { _logger.logInformation(userRef, LoggingEvents.UpdateNoContent, "Updating Material: {0}", ((MaterialDto)validationOutput.DesiredReturn).ToString()); _logger.logInformation(userRef, LoggingEvents.UpdateOk, "Updating Material: {0}", ((MaterialDto)validationOutput.DesiredReturn).ToString()); return(NoContent()); } }
internal void InitializeToolWindowInternal(float dpiFactor = 0) { ToolWindowPane window = this.FindToolWindow(typeof(WarningList), 0, true); if ((null == window) || (null == window.Frame)) { throw new NotSupportedException(Resources.CanNotCreateWindow); } _validationOutput = (ValidationOutput)window.Window; if (dpiFactor != 0) { _validationOutput.Rescale(dpiFactor); } _toolWindowFrame = (IVsWindowFrame)window.Frame; ShowToolWindow(); }
public ValidationOutput ClientGetByReference(string reference) { ValidationOutput validationOutput = _configuredProductDTOValidator.DTOReferenceIsValid(reference); if (validationOutput.HasErrors()) { return(validationOutput); } if (!ExistsAndIsActive(reference)) { validationOutput = new ValidationOutputNotFound(); validationOutput.AddError("Configured Product's reference", "There are no configured products with the given reference"); return(validationOutput); } validationOutput.DesiredReturn = _mapper.Map <ConfiguredProductDto>(_configuredProductRepository.GetByReference(reference)); return(validationOutput); }
// ============ Methods to CREATE something ============ /** * Method that will validate and create a new category in the database. * * Validations performed: * 1. Validation of the new category's reference (business rules); * 2. Validation of the new category's reference (database); * 3. Validation of the received info. (name, description, parent category) (business rules) * 4. Validation of the category's parent category reference (database) */ public ValidationOutput Register(CategoryDto dto) { //1. ValidationOutput validationOutput = _categoryDTOValidator.DTOReferenceIsValid(dto.Reference); if (validationOutput.HasErrors()) { return(validationOutput); } //2. validationOutput = new ValidationOutputBadRequest(); if (Exists(dto.Reference)) { validationOutput.AddError("Category's reference", "A category with the reference '" + dto.Reference + "' already exists in the system!"); return(validationOutput); } //3. validationOutput = _categoryDTOValidator.DTOIsValidForRegister(dto); if (validationOutput.HasErrors()) { return(validationOutput); } //4. validationOutput = new ValidationOutputNotFound(); if (!string.IsNullOrEmpty(dto.ParentCategoryReference)) { if (!Exists(dto.ParentCategoryReference)) { validationOutput.AddError("Category's parent category reference", "No category with the reference '" + dto.ParentCategoryReference + "' exists in the system."); return(validationOutput); } } //If we reached here than that means we can add the new category Category passedCategory = _mapper.Map <Category>(dto); validationOutput.DesiredReturn = _mapper.Map <CategoryDto>(_categoryRepository.Add(passedCategory)); return(validationOutput); }
public async Task <IActionResult> DeleteVariousProductCollection([FromHeader(Name = "Authorization")] string authorization, [FromRoute] string reference, [FromBody] IEnumerable <ProductCollectionDto> enumerableProductCollectionDto) { if (!_userValidationService.CheckAuthorizationToken(authorization)) { return(Unauthorized()); } if (!(await _userValidationService.ValidateContentManager(authorization.Split(" ")[1]))) { return(Unauthorized()); } var userRef = await _userValidationService.GetUserRef(authorization.Split(" ")[1]); object[] array = new object[2]; array[0] = reference; array[1] = EnumerableUtils.convert(enumerableProductCollectionDto); _logger.logInformation(userRef, LoggingEvents.HardDeleteItem, "Deleting Product Collections By Reference: {0} -- {1}", array); ValidationOutput validationOutput = _catalogService.DeleteVariousProductCollection(reference, enumerableProductCollectionDto); if (validationOutput.HasErrors()) { if (validationOutput is ValidationOutputBadRequest) { _logger.logCritical(userRef, LoggingEvents.DeleteBadRequest, "Deleting Failed: {0}", ((ValidationOutputBadRequest)validationOutput).ToString()); return(BadRequest(validationOutput.FoundErrors)); } if (validationOutput is ValidationOutputNotFound) { _logger.logCritical(userRef, LoggingEvents.DeleteNotFound, "Deleting Failed: {0}", ((ValidationOutputNotFound)validationOutput).ToString()); return(NotFound(validationOutput.FoundErrors)); } _logger.logCritical(userRef, LoggingEvents.DeleteInternalError, "Type of validation output not recognized. Please contact your software provider."); return(BadRequest("Type of validation output not recognized. Please contact your software provider.")); } else { _logger.logInformation(userRef, LoggingEvents.DeleteNoContent, "Deleting Product Collections of Catalog: {0}", array[1]); _logger.logInformation(userRef, LoggingEvents.HardDeleteOk, "Deleting Product Collections of Catalog: {0}", array[1]); return(NoContent()); } }
private void ValidateMaterial(ChildConfiguredProductDto configuredDto, ValidationOutput validationOutput) { var material = _materialRepository.GetByReference(configuredDto.ConfiguredMaterial.OriginMaterialReference); if (!material.ChosenColorIsValid(configuredDto.ConfiguredMaterial.ColorReference)) { validationOutput.AddError("Chosen Color", "Material does not support the chosen color!"); } Price finishPrice = material.ChosenFinishIsValid(configuredDto.ConfiguredMaterial.FinishReference); if (finishPrice == null) { validationOutput.AddError("Chosen Finish", "Material does not support the chosen finish!"); } else { validationOutput.DesiredReturn = new Price[] { material.CurrentPrice(), finishPrice }; } }
public async Task <IActionResult> CreateMaterial([FromHeader(Name = "Authorization")] string authorization, [FromBody] MaterialDto materialDto) { if (!_userValidationService.CheckAuthorizationToken(authorization)) { return(Unauthorized()); } if (!(await _userValidationService.ValidateContentManager(authorization.Split(" ")[1]))) { return(Unauthorized()); } var userRef = await _userValidationService.GetUserRef(authorization.Split(" ")[1]); _logger.logInformation(userRef, LoggingEvents.PostItem, "Creating By Dto: {0}", materialDto.Reference); ValidationOutput validationOutput = _materialService.Register(materialDto); if (validationOutput.HasErrors()) { if (validationOutput is ValidationOutputBadRequest) { _logger.logCritical(userRef, LoggingEvents.PostBadRequest, "Creating Material Failed: {0}", ((ValidationOutputBadRequest)validationOutput).ToString()); return(BadRequest(validationOutput.FoundErrors)); } if (validationOutput is ValidationOutputNotFound) { _logger.logCritical(userRef, LoggingEvents.PostNotFound, "Creating Material Failed: {0}", ((ValidationOutputNotFound)validationOutput).ToString()); return(NotFound(validationOutput.FoundErrors)); } _logger.logCritical(userRef, LoggingEvents.PostInternalError, "Type of validation output not recognized. Please contact your software provider."); return(BadRequest("Type of validation output not recognized. Please contact your software provider.")); } else { MaterialDto newMaterialDto = (MaterialDto)validationOutput.DesiredReturn; _logger.logInformation(userRef, LoggingEvents.PostOk, "Creating Material Succeeded: {0}", newMaterialDto.Reference); return(CreatedAtRoute("GetMaterial", new { reference = newMaterialDto.Reference }, newMaterialDto)); } }
private void ConfiguredDimensionDtoIsValid(ConfiguredDimensionDto dto, ValidationOutput validationOutput) { if (dto == null) { validationOutput.AddError("Dimensions", "Dimensions are missing!"); return; } if (dto.Depth <= 0) { validationOutput.AddError("Depth", "Depth is less or equals to 0"); } if (dto.Height <= 0) { validationOutput.AddError("Height", "Height is less or equals to 0"); } if (dto.Width <= 0) { validationOutput.AddError("Width", "Width is less or equals to 0"); } }
public async Task <IActionResult> GetProductCollection([FromHeader(Name = "Authorization")] string authorization, [FromRoute] string reference) { if (!_userValidationService.CheckAuthorizationToken(authorization)) { return(Unauthorized()); } if (!(await _userValidationService.Validate(authorization.Split(" ")[1]))) { return(Unauthorized()); } var userRef = await _userValidationService.GetUserRef(authorization.Split(" ")[1]); _logger.logInformation(userRef, LoggingEvents.SoftDeleteItem, "Getting ProductsCollection By Reference: {0}", reference); ValidationOutput validationOutput = _catalogService.GetAllProductCollection(reference); if (validationOutput.HasErrors()) { if (validationOutput is ValidationOutputBadRequest) { _logger.logCritical(userRef, LoggingEvents.GetItemBadRequest, "Getting ProductsCollection Failed: {0}", ((ValidationOutputBadRequest)validationOutput).ToString()); return(BadRequest(validationOutput.FoundErrors)); } if (validationOutput is ValidationOutputNotFound) { _logger.logCritical(userRef, LoggingEvents.GetItemNotFound, "Getting ProductsCollection Failed: {0}", ((ValidationOutputNotFound)validationOutput).ToString()); return(NotFound(validationOutput.FoundErrors)); } _logger.logCritical(userRef, LoggingEvents.GetItemInternalError, "Type of validation output not recognized. Please contact your software provider."); return(BadRequest("Type of validation output not recognized. Please contact your software provider.")); } else { IEnumerable <ConfiguredProductCollectionDto> list = (List <ConfiguredProductCollectionDto>)validationOutput.DesiredReturn; _logger.logInformation(userRef, LoggingEvents.GetItemOk, "Getting ProductsCollection: {0}", (EnumerableUtils.convert(list))); return(Ok(list)); } }
public async Task <IActionResult> GetMaterial(/* [FromHeader(Name="Authorization")] string authorization, */ [FromRoute] string reference) { // if(!_userValidationService.CheckAuthorizationToken(authorization)) { // return Unauthorized(); // } // if(!(await _userValidationService.Validate(authorization.Split(" ")[1]))) { // return Unauthorized(); // } // var userRef = await _userValidationService.GetUserRef(authorization.Split(" ")[1]); // _logger.logInformation(userRef, LoggingEvents.GetItem, "Getting By Reference: {0}", reference); ValidationOutput validationOutput = _materialService.GetByReference(reference); if (validationOutput.HasErrors()) { if (validationOutput is ValidationOutputBadRequest) { // _logger.logCritical(userRef, LoggingEvents.GetItemBadRequest, "Getting Material Failed: {0}", // ((ValidationOutputBadRequest) validationOutput).ToString()); return(BadRequest(validationOutput.FoundErrors)); } if (validationOutput is ValidationOutputNotFound) { // _logger.logCritical(userRef, LoggingEvents.GetItemNotFound, "Getting Material Failed: {0}", // ((ValidationOutputNotFound) validationOutput).ToString()); return(NotFound(validationOutput.FoundErrors)); } // _logger.logCritical(userRef, LoggingEvents.GetItemInternalError, // "Type of validation output not recognized. Please contact your software provider."); return(BadRequest("Type of validation output not recognized. Please contact your software provider.")); } else { // _logger.logInformation(userRef, LoggingEvents.GetItemOk, "Getting Material: {0}", // ((MaterialDto) validationOutput.DesiredReturn).ToString()); return(Ok((MaterialDto)validationOutput.DesiredReturn)); } }
public ValidationOutput Remove(string reference) { ValidationOutput validationOutput = _configuredProductDTOValidator.DTOReferenceIsValid(reference); if (validationOutput.HasErrors()) { return(validationOutput); } ConfiguredProduct configuredProduct = _configuredProductRepository.GetByReference(reference); if (configuredProduct == null) { validationOutput = new ValidationOutputNotFound(); validationOutput.AddError("Configured Product's reference", "There are no configured products with the given reference"); return(validationOutput); } _configuredProductRepository.Delete(configuredProduct); return(validationOutput); }
public async Task <ActionResult> GetAllInfoByReference([FromHeader(Name = "Authorization")] string authorization, [FromRoute] string reference) { if (!_userValidationService.CheckAuthorizationToken(authorization)) { return(Unauthorized()); } var userRef = ""; if (authorization != null) { userRef = await _userValidationService.GetUserRef(authorization.Split(" ")[1]); } _logger.logInformation(userRef, LoggingEvents.GetItem, "Getting Info By Reference: {0}", reference); ValidationOutput validationOutput = _configuredProductService.GetAllInfoByReference(reference); if (validationOutput.HasErrors()) { if (validationOutput is ValidationOutputBadRequest) { _logger.logCritical(userRef, LoggingEvents.GetItemBadRequest, "Getting Info Failed: {0}", ((ValidationOutputBadRequest)validationOutput).ToString()); return(BadRequest(validationOutput.FoundErrors)); } if (validationOutput is ValidationOutputNotFound) { _logger.logCritical(userRef, LoggingEvents.GetItemNotFound, "Getting Info Failed: {0}", ((ValidationOutputNotFound)validationOutput).ToString()); return(NotFound(validationOutput.FoundErrors)); } _logger.logCritical(userRef, LoggingEvents.GetItemInternalError, "Type of validation output not recognized. Please contact your software provider."); return(BadRequest("Type of validation output not recognized. Please, contact your software provider.")); } else { _logger.logInformation(userRef, LoggingEvents.GetItemOk, "Getting Info: {0}", ((ConfiguredProductDto)validationOutput.DesiredReturn).ToString()); return(Ok((ProductOrderDto)validationOutput.DesiredReturn)); } }
public async Task <IActionResult> GetProductsOfCategory([FromHeader(Name = "Authorization")] string authorization, [FromRoute] string reference) { if (!_userValidationService.CheckAuthorizationToken(authorization)) { return(Unauthorized()); } if (!(await _userValidationService.Validate(authorization.Split(" ")[1]))) { return(Unauthorized()); } var userRef = await _userValidationService.GetUserRef(authorization.Split(" ")[1]); _logger.logInformation(userRef, LoggingEvents.GetAllItems, "Getting Products By Reference: {0}", reference); ValidationOutput validationOutput = _productService.GetProductsOfCategory(reference); if (validationOutput.HasErrors()) { if (validationOutput is ValidationOutputBadRequest) { _logger.logCritical(userRef, LoggingEvents.GetAllBadRequest, "Getting Products Failed: {0}", ((ValidationOutputBadRequest)validationOutput).ToString()); return(BadRequest(validationOutput.FoundErrors)); } if (validationOutput is ValidationOutputNotFound) { _logger.logCritical(userRef, LoggingEvents.GetAllNotFound, "Getting Products Failed: {0}", ((ValidationOutputNotFound)validationOutput).ToString()); return(NotFound(validationOutput.FoundErrors)); } _logger.logCritical(userRef, LoggingEvents.GetAllInternalError, "Type of validation output not recognized. Please contact your software provider."); return(BadRequest("Type of validation output not recognized. Please contact your software provider.")); } else { _logger.logInformation(userRef, LoggingEvents.GetAllOk, "Getting Products: {0}", EnumerableUtils.convert((List <ProductDto>)validationOutput.DesiredReturn)); return(Ok(validationOutput.DesiredReturn)); } }