Ejemplo n.º 1
0
        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 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));
            }
        }