private void LoadImages()
        {
            var loader = (BitmapImage)App.Current.FindResource("LoaderGif");

            foreach (var detail in OrderDetails)
            {
                for (Int32 i = 0; i < detail.ProductImages.Count; ++i)
                {
                    Models.ProductImage productImage = detail.ProductImages[i];
                }
                foreach (var x in detail.ProductImages)
                {
                    new Action(async() =>
                    {
                        x.ImageSource           = loader;
                        ProductImageMessage msg = await client.GetProductImageAsync(x.ImageID, LargeImage: false);
                        var memory    = new MemoryStream();
                        var bytesRead = 0;
                        var buffer    = new Byte[1024];
                        do
                        {
                            bytesRead = msg.ImageData.Read(buffer, 0, buffer.Length);
                            memory.Write(buffer, 0, bytesRead);
                        }while (bytesRead > 0);
                        var bitmap = new BitmapImage();
                        bitmap.BeginInit();
                        bitmap.StreamSource = memory;
                        bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                        bitmap.EndInit();
                        x.ImageSource = bitmap;
                    })();
                }
                //detail.ProductImages.ForEach(async x =>
                //{
                //    x.ImageSource = loader;
                //    ProductImageMessage msg = await client.GetProductImageAsync(x.ImageID, LargeImage: false);
                //    var memory = new MemoryStream();
                //    var bytesRead = 0;
                //    var buffer = new Byte[1024];
                //    do
                //    {
                //        bytesRead = msg.ImageData.Read(buffer, 0, buffer.Length);
                //        memory.Write(buffer, 0, bytesRead);
                //    }
                //    while (bytesRead > 0);
                //    var bitmap = new BitmapImage();
                //    bitmap.BeginInit();
                //    bitmap.StreamSource = memory;
                //    bitmap.CacheOption = BitmapCacheOption.OnLoad;
                //    bitmap.EndInit();
                //    x.ImageSource = bitmap;

                //    var moq = new Models.ProductImage();


                //});
            }
        }
Example #2
0
        public ActionResult EditImage(string productId)
        {
            if (Session["user"] == null)
            {
                return(RedirectToAction("home", "home"));
            }
            PRFancyRepository dal = new PRFancyRepository();
            PRFancyAutoMapper <productImage, Models.ProductImage> map = new PRFancyAutoMapper <productImage, Models.ProductImage>();

            try
            {
                productImage        obj    = dal.GetProductImage(productId);
                Models.ProductImage modObj = map.Translate(obj);
                return(View(map.Translate(obj)));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
Example #3
0
        public ActionResult SaveImage([Bind(Exclude = "productImage1,productImage2,productImage3,productImage4,ImageData1,ImageData2,ImageData3,ImageData4,Image1,Image2,Image3,Image4")] Models.ProductImage imageObj)
        {
            PRFancyRepository dal = new PRFancyRepository();
            PRFancyAutoMapper <Models.ProductImage, productImage> map = new PRFancyAutoMapper <Models.ProductImage, productImage>();

            try
            {
                HttpPostedFileBase file1 = Request.Files["ImageData1"];
                HttpPostedFileBase file2 = Request.Files["ImageData2"];
                HttpPostedFileBase file3 = Request.Files["ImageData3"];
                HttpPostedFileBase file4 = Request.Files["ImageData4"];
                bool result = dal.SaveImage(imageObj.productId, file1, file2, file3, file4);
                if (result)
                {
                    return(RedirectToAction("ImageHome"));
                }
                return(View("Error"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }