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 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 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()); } }
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 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); }
// ============ 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 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); }
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()); } }
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()); } }
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)); } }
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)); } }
// ============ Methods to CREATE something ============ /** * Method that will validate and create a new catalog in the database. * * Validations performed: * 1. Validation of the new catalog's reference (business rules); * 2. Validation of the new catalog's reference (database); * 3. Validation of the received info. (name, description) (business rules) * 4. The received CatalogProductCollection list has 1 or more elements. * FOREACH RECEIVED CatalogProductCollection { * 5. Validation of the collection's reference in ProductCollection of current CatalogProductCollection (database); * 6. Validation of the configured product's reference in ProductCollection of current CatalogProductCollection (database); * 7. Validation to assert whether the indicated configured product actually belongs to the indicated collection (ProductCollection in current CatalogProductCollection) * 8. Validation for duplication between each CatalogProductCollection * } */ public ValidationOutput Register(CatalogDto dto) { //1. ValidationOutput validationOutput = _catalogDTOValidator.DTOReferenceIsValid(dto.Reference); if (validationOutput.HasErrors()) { return(validationOutput); } //2. validationOutput = new ValidationOutputBadRequest(); if (CatalogExists(dto.Reference)) { validationOutput.AddError("Reference of catalog", "A catalog with the reference '" + dto.Reference + "' already exists in the system!"); return(validationOutput); } //3. validationOutput = _catalogDTOValidator.DTOIsValidForRegister(dto); if (validationOutput.HasErrors()) { return(validationOutput); } //4. validationOutput = new ValidationOutputBadRequest(); /*if (dto.CatalogProductCollectionList.Count == 0) * { * validationOutput.AddError("Selected 'configured product - collection' items", "No 'configured product - collection' items were selected!"); * return validationOutput; * }*/ if (dto.CatalogProductCollectionList.Count > 0) { List <ProductCollection> productCollectionListToAdd = new List <ProductCollection>(); foreach (var currentCatalogProductCollectionDto in dto.CatalogProductCollectionList) { ProductCollectionDto productCollectionDto = currentCatalogProductCollectionDto.ProductCollection; //Just to simplify the code //5. validationOutput = new ValidationOutputNotFound(); if (!CollectionExists(productCollectionDto.CollectionReference)) { validationOutput.AddError("Reference of collection of a 'configured product - collection' item", "No collection with the reference '" + productCollectionDto.CollectionReference + "' exists in the system."); return(validationOutput); } //6. if (!ConfiguredProductExists(productCollectionDto.ConfiguredProductReference)) { validationOutput.AddError( "Reference of configured product of a 'configured product - collection' item", "No configured product with the reference '" + productCollectionDto.ConfiguredProductReference + "' exists in the system."); return(validationOutput); } Collection currentCollection = _collectionRepository.GetByReference(productCollectionDto.CollectionReference); //7. validationOutput = new ValidationOutputBadRequest(); if (!currentCollection.ConfiguredProductIsInCollection(productCollectionDto .ConfiguredProductReference)) { validationOutput.AddError("'Configured product - collection' item", "The configured product with reference '" + productCollectionDto.ConfiguredProductReference + "' does not belong to the collection with reference '" + productCollectionDto.ConfiguredProductReference + "'."); return(validationOutput); } ProductCollection currentProdCollection = _mapper.Map <ProductCollection>(productCollectionDto); //8. if (productCollectionListToAdd.Contains(currentProdCollection)) { validationOutput.AddError("'Configured product - collection' item", "'Configured product - collection' item with configured product '" + currentProdCollection.ConfiguredProductReference + "' that is associated with the collection '" + currentProdCollection.CollectionReference + "' is duplicated in the list of selected 'configured product - collection' items!"); return(validationOutput); } productCollectionListToAdd.Add(currentProdCollection); } } Catalog catalogToRegister = _mapper.Map <Catalog>(dto); validationOutput.DesiredReturn = _mapper.Map <CatalogDto>(_catalogRepository.Add(catalogToRegister)); return(validationOutput); }
/** * Validations performed: * * 1. The received list has 1 or more elements. * FOREACH RECEIVED ConfiguredProductReference { * 2. Validation of each configured product reference (database); * 3. Validation of the existence of each configured product (represented by a reference) received, in the collection with the passed reference * 4. Validation for duplication between each configured product reference received * } */ // ============ Methods to CREATE something ============ /** * Method that will validate and create a new collection in the database. * * Validations performed: * 1. Validation of the new collection's reference (business rules); * 2. Validation of the new collection's reference (database); * 3. Validation of the received info. (name, description, configured products) (business rules) * 4. The received list has 1 or more elements. * FOREACH RECEIVED ConfiguredProductReference { * 5. Validation of each configured product reference (database); * 6. Validation for duplication between each configured product reference received * } */ public ValidationOutput Register(CollectionDto dto) { //1. ValidationOutput validationOutput = _collectionDTOValidator.DTOReferenceIsValid(dto.Reference); if (validationOutput.HasErrors()) { return(validationOutput); } //2. if (CollectionExists(dto.Reference)) { validationOutput.AddError("Reference of collection", "A collection with the reference '" + dto.Reference + "' already exists in the system!"); return(validationOutput); } //3. validationOutput = _collectionDTOValidator.DTOIsValidForRegister(dto); if (validationOutput.HasErrors()) { return(validationOutput); } //4. validationOutput = new ValidationOutputBadRequest(); /*if (dto.ProductCollectionList.Count == 0) * { * validationOutput.AddError("Selected configured products", "No configured products were selected!"); * return validationOutput; * }*/ if (dto.ProductCollectionList.Count > 0) { List <string> configuredProductReferenceListToAdd = new List <string>(); foreach (var productCollectionDto in dto.ProductCollectionList) { string configuredProductReference = productCollectionDto.ConfiguredProductReference; //Just to simplify the code //5. if (!ConfiguredProductExists(configuredProductReference)) { validationOutput.AddError("Reference of configured product", "No configured product with the reference '" + configuredProductReference + "' exists in the system."); return(validationOutput); } //6. if (configuredProductReferenceListToAdd.Contains(configuredProductReference)) { validationOutput.AddError("Configured product", "Configured product '" + configuredProductReference + "' is duplicated in the list of configured product selected!"); return(validationOutput); } configuredProductReferenceListToAdd.Add(configuredProductReference); } } Collection collectionToRegister = _mapper.Map <Collection>(dto); validationOutput.DesiredReturn = _mapper.Map <CollectionDto>(_collectionRepository.Add(collectionToRegister)); return(validationOutput); }