Exemple #1
0
        //public static int SaveUserImage(Ctx ctx, byte[] buffer, string imageName, bool isSaveInDB, int productID)
        public static string SaveUserImage(Ctx ctx, byte[] buffer, string imageName, bool isSaveInDB, int productID)
        {
            string   imageDataURL = null;
            MProduct user         = new MProduct(ctx, productID, null);
            int      imageID      = Util.GetValueOfInt(user.GetAD_Image_ID());



            //DirectoryInfo dir = new DirectoryInfo(HostingEnvironment.MapPath("~/TempFiles/ProductImages/Thumb100x100"));
            MImage mimg = new MImage(ctx, imageID, null);

            mimg.ByteArray   = buffer;
            mimg.ImageFormat = imageName.Substring(imageName.LastIndexOf('.'));
            mimg.SetName(imageName);
            if (isSaveInDB)
            {
                mimg.SetBinaryData(buffer);
                //mimg.SetImageURL(string.Empty);
            }
            mimg.SetImageURL("Images/Thumb46x46");//Image Saved in File System so instead of byteArray image Url will be set
            if (!mimg.Save())
            {
                return("");
            }
            user.SetAD_Image_ID(mimg.GetAD_Image_ID());
            if (!user.Save())
            {
                return("");
            }
            else
            {
                string filePath = Path.Combine(HostingEnvironment.MapPath("~/Images/Thumb46x46"), mimg.GetAD_Image_ID() + mimg.ImageFormat);

                if (File.Exists(filePath))
                {
                    byte[] imageByteData   = System.IO.File.ReadAllBytes(filePath);
                    string imageBase64Data = Convert.ToBase64String(imageByteData);
                    imageDataURL = string.Format("data:image/png;base64,{0}", imageBase64Data);
                }
            }
            return(imageDataURL);
            //return mimg.GetAD_Image_ID();
        }