Exemplo n.º 1
0
        public HttpResponseMessage Create(string apiKey, string type, string value, string format = "png", bool returnAsBase64 = false)
        {
            // Validate the api key
            ValidateApi validateApi    = new ValidateApi();
            Validation  validateApiKey = validateApi.ValidateApiKey(apiKey);

            // Api key is invalid.
            if (!validateApiKey.IsValid)
            {
                return(BuildErrorResponse(validateApiKey));
            }

            // Validate the values first
            ValidateInput validation      = new ValidateInput();
            Validation    validationInput = validation.ValidateBarcodeValue(type, value);

            // Result is Valid
            if (validationInput.IsValid)
            {
                return(CreateBarcode(type, value, format, returnAsBase64));
            }

            // Result is not valid
            return(BuildErrorResponse(validationInput));
        }
Exemplo n.º 2
0
        public HttpResponseMessage Create(string apiKey, string type, string value, string format = "png", bool returnAsBase64 = false)
        {
            // Validate the api key
            ValidateApi validateApi = new ValidateApi();
            Validation validateApiKey = validateApi.ValidateApiKey(apiKey);

            // Api key is invalid.
            if (!validateApiKey.IsValid)
            {
                return BuildErrorResponse(validateApiKey);    
            }

            // Validate the values first
            ValidateInput validation = new ValidateInput();
            Validation validationInput = validation.ValidateBarcodeValue(type, value);
            
            // Result is Valid
            if (validationInput.IsValid)
            {
                return CreateBarcode(type, value, format, returnAsBase64);
            }

            // Result is not valid
            return BuildErrorResponse(validationInput);
        }
Exemplo n.º 3
0
        public HttpResponseMessage CreateBatch(ImageBatch imageBatch)
        {
            // Our response object
            ImageBatchResponse batchResult = new ImageBatchResponse();

            // Validate the api key
            ValidateApi validateApi    = new ValidateApi();
            Validation  validateApiKey = validateApi.ValidateApiKey(imageBatch.ApiKey);

            // Api key is invalid.
            if (!validateApiKey.IsValid)
            {
                return(BuildErrorResponse(validateApiKey));
            }

            // Loop through the values
            List <ImageResponse> imageList = new List <ImageResponse>();

            foreach (ImageDetails detail in imageBatch.ImageDetails)
            {
                // Validate the values first
                ValidateInput validation      = new ValidateInput();
                Validation    validationInput = validation.ValidateBarcodeValue(detail.Type, detail.Value);

                // Result is Valid
                ImageResponse imageResponse = new ImageResponse();
                if (validationInput.IsValid)
                {
                    imageResponse.ImageUrl = string.Format(
                        "http://www.codegenerate.me/Code/Barcode?type={0}&value={1}", detail.Type, detail.Value);
                    imageResponse.Result = "Success";
                    batchResult.SuccessfulCount++;
                }
                else
                {
                    imageResponse.Result = validationInput.ErrorMessage;
                }

                imageList.Add(imageResponse);
            }

            // Add the images
            batchResult.Images = imageList.ToArray();

            // Build the object to return
            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(batchResult.ToJSON())
            };

            return(result);
        }
Exemplo n.º 4
0
        public HttpResponseMessage CreateBatch(ImageBatch imageBatch)
        {
            // Our response object
            ImageBatchResponse batchResult = new ImageBatchResponse();

            // Validate the api key
            ValidateApi validateApi = new ValidateApi();
            Validation validateApiKey = validateApi.ValidateApiKey(imageBatch.ApiKey);

            // Api key is invalid.
            if (!validateApiKey.IsValid)
            {
                return BuildErrorResponse(validateApiKey);
            }

            // Loop through the values
            List<ImageResponse> imageList = new List<ImageResponse>();
            foreach (ImageDetails detail in imageBatch.ImageDetails)
            {
                // Validate the values first
                ValidateInput validation = new ValidateInput();
                Validation validationInput = validation.ValidateBarcodeValue(detail.Type, detail.Value);

                // Result is Valid
                ImageResponse imageResponse = new ImageResponse();
                if (validationInput.IsValid)
                {
                    imageResponse.ImageUrl = string.Format(
                        "http://www.codegenerate.me/Code/Barcode?type={0}&value={1}", detail.Type, detail.Value);
                    imageResponse.Result = "Success";
                    batchResult.SuccessfulCount++;
                }
                else
                {
                    imageResponse.Result = validationInput.ErrorMessage;
                }

                imageList.Add(imageResponse);
            }

            // Add the images
            batchResult.Images = imageList.ToArray();

            // Build the object to return
            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK)
                                             {Content = new StringContent(batchResult.ToJSON())};

            return result;
        }