예제 #1
0
        public ActionResult Validate(string type, string value)
        {
            ValidateInput validation       = new ValidateInput();
            Validation    validationResult = validation.ValidateBarcodeValue(type, value);

            return(Json(validationResult, JsonRequestBehavior.AllowGet));
        }
예제 #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));
        }
예제 #3
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);
        }
예제 #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);
        }
예제 #5
0
        public void ValidateCode39_WithCorrectParams_ShouldReturnTrue()
        {
            // Arrange
            const string codabarType = "code39";
            const string value       = "12345A";

            // Act
            ValidateInput validateInput = new ValidateInput();
            Validation    calculated    = validateInput.ValidateBarcodeValue(codabarType, value);

            // Assert
            Assert.That(calculated.IsValid, Is.True);
        }
예제 #6
0
        public void ValidateCodaBar_WithIncorrectEndingParams_ShouldReturnFalse()
        {
            // Arrange
            const string codabarType = "codabar";
            const string value       = "D123";

            // Act
            ValidateInput validateInput = new ValidateInput();
            Validation    calculated    = validateInput.ValidateBarcodeValue(codabarType, value);

            // Assert
            Assert.That(calculated.IsValid, Is.False);
        }
예제 #7
0
        public ActionResult Validate(string type, string value)
        {
            ValidateInput validation = new ValidateInput();
            Validation validationResult = validation.ValidateBarcodeValue(type, value);

            return Json(validationResult, JsonRequestBehavior.AllowGet);
        }
예제 #8
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;
        }