Ejemplo n.º 1
0
        public async Task <IActionResult> CreateCategory([FromHeader(Name = "Authorization")] string authorization, [FromBody] CategoryDto categoryDto)
        {
            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}", categoryDto.Reference);

            ValidationOutput validationOutput = _categoryService.Register(categoryDto);

            if (validationOutput.HasErrors())
            {
                if (validationOutput is ValidationOutputBadRequest)
                {
                    _logger.logCritical(userRef, LoggingEvents.PostBadRequest, "Creating Category Failed: {0}", ((ValidationOutputBadRequest)validationOutput).ToString());
                    return(BadRequest(validationOutput.FoundErrors));
                }

                if (validationOutput is ValidationOutputNotFound)
                {
                    _logger.logCritical(userRef, LoggingEvents.PostNotFound, "Creating Category 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
            {
                CategoryDto newCategoryDto = (CategoryDto)validationOutput.DesiredReturn;
                _logger.logInformation(userRef, LoggingEvents.PostOk, "Creating Category Succeeded: {0}", newCategoryDto.ToString());
                return(CreatedAtRoute("GetCategory", new { reference = newCategoryDto.Reference }, newCategoryDto));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> GetByReference([FromHeader(Name = "Authorization")] string authorization, [FromRoute] string reference)
        {
            if (!_userValidationService.CheckAuthorizationToken(authorization))
            {
                return(Unauthorized());
            }
            var userRef = await _userValidationService.GetUserRef(authorization.Split(" ")[1]);

            ValidationOutput validationOutput;

            if (await _userValidationService.ValidateContentManager(authorization.Split(" ")[1]))
            {
                _logger.logInformation(userRef, LoggingEvents.GetItem, "Getting By Reference: {0}", reference);
                validationOutput = _configuredProductService.GetByReference(reference);
            }
            else if (await _userValidationService.Validate(authorization.Split(" ")[1]))
            {
                _logger.logInformation(userRef, LoggingEvents.GetItem, "Getting By Reference: {0}", reference);
                validationOutput = _configuredProductService.ClientGetByReference(reference);
            }
            else
            {
                return(Unauthorized());
            }

            if (validationOutput.HasErrors())
            {
                if (validationOutput is ValidationOutputBadRequest)
                {
                    _logger.logCritical(userRef, LoggingEvents.GetItemBadRequest, "Getting Configured Product Failed: {0}", ((ValidationOutputBadRequest)validationOutput).ToString());
                    return(BadRequest(validationOutput.FoundErrors));
                }

                if (validationOutput is ValidationOutputNotFound)
                {
                    _logger.logCritical(userRef, LoggingEvents.GetItemNotFound, "Getting Configured Product 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 Configured Product: {0}", ((ConfiguredProductDto)validationOutput.DesiredReturn).ToString());
                return(Ok((ConfiguredProductDto)validationOutput.DesiredReturn));
            }
        }