Beispiel #1
0
        public void ProcessRequest(HttpContext context)
        {
            SubBrandManager subBrandManager = new SubBrandManager();
            SubBrandImage   subBrandImage   = new SubBrandImage();

            //get querystring from client request

            if (string.IsNullOrEmpty(context.Request.QueryString["id"]))
            {
                context.Response.Write("No Image found!");
            }
            else
            {
                string collectedSubBrandImageID = context.Request.QueryString["id"];

                //get 1 subBrandImage
                subBrandImage = subBrandManager.getOneSubBrandImage(collectedSubBrandImageID);

                //convert byte to memorystream
                //store in image so i can scale the image
                ////binary write to response
                MemoryStream ms          = new MemoryStream(subBrandImage.SubBrandImageData);
                Image        returnImage = Image.FromStream(ms);

                //set image height to 50
                ScaleImage(returnImage, 50);


                //after that convert it back to byte again and do binarywrite() to sent it to response
                ImageConverter imageConverter = new ImageConverter();
                byte[]         imageByte      = (byte[])imageConverter.ConvertTo(returnImage, typeof(byte[]));

                context.Response.BinaryWrite(imageByte);
            }
        }
Beispiel #2
0
        public static object DeleteOneSubBrand(string inSubBrandId)
        {
            SubBrandManager sbm    = new SubBrandManager();
            bool            status = sbm.DeleteOneSubBrand(inSubBrandId);

            return(status);
        }
        public void ProcessRequest(HttpContext context)
        {
            string subBrandImageID = context.Request.Form["key"].ToString();

            SubBrandManager subBrandManager = new SubBrandManager();

            if (subBrandManager.DeleteOneImage(subBrandImageID))
            {
                var Response = new
                {
                    status  = "Success!",
                    message = "Deleted one SubBrand Image."
                };
                context.Response.ContentType = "application/json";
                context.Response.Write(JsonConvert.SerializeObject(Response));
            }
            else
            {
                var Response = new
                {
                    status  = "Fail!",
                    message = "Unable to delete SubBrand Image."
                };
                context.Response.ContentType = "application/json";
                context.Response.Write(JsonConvert.SerializeObject(Response));
            }
        }
Beispiel #4
0
        //addOneSubBrand(string inSubBrandName, string inDescription, string inBrandID)
        public static object addOneSubBrand(string WebFormDataParameter)
        {
            var             webFormData     = JsonConvert.DeserializeObject <dynamic>(WebFormDataParameter);
            SubBrandManager subBrandManager = new SubBrandManager();
            object          collectedSubBrandIDAndValidationMsg = subBrandManager.addOneSubBrand(webFormData.subBrandName.Value, webFormData.description.Value, webFormData.subBrandVideoLink.Value, webFormData.getSubBrandID.Value);

            //need to convert object to type in order to get the properties
            Type         type = collectedSubBrandIDAndValidationMsg.GetType();
            PropertyInfo info = type.GetProperty("uniqueConstraint");
            string       collectedUniqueConstraint = info.GetValue(collectedSubBrandIDAndValidationMsg).ToString();

            //collect subbrandID from OUTPUT inserted.SubBrandID from sql Command
            PropertyInfo subBrandID          = type.GetProperty("collectedSubBrandID");
            string       collectedSubBrandID = subBrandID.GetValue(collectedSubBrandIDAndValidationMsg).ToString();


            object response = new
            {
                uniqueConstraint = collectedUniqueConstraint,
                subBrandID       = collectedSubBrandID
            };


            return(response);
        }
Beispiel #5
0
        public static object GetAllSubBrand()
        {
            SubBrandManager subbrandManager = new SubBrandManager();

            object response = subbrandManager.GetAllSubBrand();

            return(response);
        }
Beispiel #6
0
        public static object GetAllSubBrandbyBrandId(string BrandID)
        {
            SubBrandManager subBrandManager = new SubBrandManager();
            //string subBrandId = HttpContext.Current.Session["subBrandID"].ToString();
            //string subBrandID = "2";
            object response = subBrandManager.GetAllSubBrandbyBrandId(BrandID);

            return(response);
        }
Beispiel #7
0
        public static object getAllImagesBySubBrandID(string inSubBrandID)
        {
            SubBrandManager subbrandManager = new SubBrandManager();
            object          response        = new object();

            //sent response of object that include byte[] of image produced error.....
            //error : during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
            //there is a limitation of string that can be sent via json to client?
            //resolved : dont send byte of imagedata to client,no point. ashx will handle the image processing
            response = subbrandManager.getAllImagesBySubBrandID(inSubBrandID);
            return(response);
        }
Beispiel #8
0
 public static object GetOneSubBrandWVideoLinkByRecordId(string subBrandID)
 {
     try
     {
         SubBrandManager subBrandManager = new SubBrandManager();
         object          response        = subBrandManager.GetOneSubBrandWVideoLinkByRecordId(subBrandID);
         return(response);
     }
     catch
     {            //for client-side jQuery's ajax().fail()
         throw new HttpException((int)HttpStatusCode.InternalServerError,
                                 "Fail to get SubBrand Record");
     }
 }
Beispiel #9
0
        public static object UpdateOneSubBrandByRecordId(string WebFormDataParameter)
        {
            SubBrandManager subBrandManager = new SubBrandManager();
            dynamic         clientsideData  = JsonConvert.DeserializeObject <dynamic>(WebFormDataParameter);
            object          response        = new object();

            //function WebFormData(inSubBrandId, inSubBrandName, inDescription, inSubBrandVideoLink) {
            //this.subBrandId = inSubBrandId;
            //this.subBrandName = inSubBrandName;
            //this.description = inDescription;
            //this.subBrandVideoLink = inSubBrandVideoLink;
            //}
            try
            {
                bool status = subBrandManager.UpdateOneSubBrandByRecordId(clientsideData.subBrandId.Value.ToString(), clientsideData.subBrandName.Value, clientsideData.description.Value, clientsideData.subBrandVideoLink.Value);
                if (status == true)
                {
                    response = new
                    {
                        status  = "success",
                        message = "SubBrand Record Saved"
                    }
                }
                ;
                else
                {
                    response = new
                    {
                        status  = "fail",
                        message = "Unable to save SubBrand Record"
                    }
                };
            }//end try

            catch (Exception ex)
            {
                response = new
                {
                    status  = "fail",
                    message = ex.Message
                };
            }



            return(response);
        }
        //HttpContext request = client sent to server
        //HttpContext response = server send to client
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                //check if there is file from client in httpRequest
                if (HttpContext.Current.Request.Files.AllKeys.Any())
                {
                    int numOfFiles = HttpContext.Current.Request.Files.Count;
                    // Get the uploaded image from the Files collection
                    //for each loop get file uploaded by client from httpRequest object, explicity convert to HttpPostedFile
                    for (int index = 0; index < numOfFiles; index++)
                    {
                        //use HttpPostedFile to get individual file uploaded by client

                        HttpPostedFile httpPostedFile = HttpContext.Current.Request.Files[index] as HttpPostedFile;

                        //if there is file in httpRequest object
                        if (httpPostedFile != null)
                        {
                            SubBrandManager subBrandManager = new SubBrandManager();
                            //convert file to byte array
                            using (var binaryReader = new BinaryReader(httpPostedFile.InputStream))
                            {
                                string collectedsubBrandID = HttpContext.Current.Request.Form["subBrandID"].ToString();
                                //size of file : httpPostedFile.ContentLength
                                //write file to byte array with correct size
                                Byte[] imageByte = binaryReader.ReadBytes(httpPostedFile.ContentLength);
                                try //check adding image
                                {
                                    subBrandManager.AddOneSubBrandOfImageBySubBrandIDWImageNameValidation(httpPostedFile.FileName, imageByte, collectedsubBrandID);
                                }
                                catch (Exception ex) //if there is error,return failResponse
                                {
                                    var failResponse = new
                                    {
                                        status  = "error",
                                        message = "Unable to add photo. " +
                                                  "If problem persist, contact administrator"
                                    };
                                    context.Response.ContentType = "application/json"; //send to client in json format
                                    context.Response.Write(JsonConvert.SerializeObject(failResponse));
                                    return;
                                } //end try catch
                            }
                        }         //end if (httpPostedFile != null)
                    }             //end for
                    var successResponse = new
                    {
                        status  = "success",
                        message = "Created " + numOfFiles + " photos."
                    };
                    context.Response.ContentType = "application/json";
                    context.Response.Write(JsonConvert.SerializeObject(successResponse));
                }//end if (HttpContext.Current.Request.Files.AllKeys.Any())
            }
            //if get file from client side surfaced error,execute catch
            catch (Exception ex)
            {
                context.Response.Write(new KeyValuePair <bool, string>(false, "An error occurred while uploading the file. Error Message: " + ex.Message));
            }
        }