public HttpResponseMessage Post(HttpRequestMessage request, int ProductId)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;


                if (!Request.Content.IsMimeMultipartContent("form-data"))
                {
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                }
                else
                {
                    IEnumerable <HttpContent> parts = Request.Content.ReadAsMultipartAsync().Result.Contents;

                    byte[] FileBytes = parts.ToArray()[0].ReadAsByteArrayAsync().Result;
                    string imagefilename = "";
                    int filesize = 0;

                    string conl = parts.ToArray()[0].Headers.ContentLength.ToString();
                    filesize = Convert.ToInt32(conl);

                    foreach (var par in parts.ToArray()[0].Headers.ContentDisposition.Parameters)
                    {
                        if (par.Name == "filename")
                        {
                            string ght = par.Value.ToString();
                            string cutght = ght.Replace("\"", "");
                            imagefilename = cutght;
                        }
                    }

                    ProductImagesViewModel newproductimageVM = new ProductImagesViewModel();

                    ProductImage newproductimage = new ProductImage()
                    {
                        ProductId = ProductId,

                        Filesize = filesize,

                        LogFilename = imagefilename,

                        Filebytes = FileBytes
                    };



                    _productImagesRepository.Add(newproductimage);

                    _unitOfWork.Commit();

                    //*************** Update view model  not neccassery here. ANYWAY....
                    newproductimageVM = Mapper.Map <ProductImage, ProductImagesViewModel>(newproductimage);
                    //response = request.CreateResponse<ProductImagesViewModel>(HttpStatusCode.Created, newproductimageVM);

                    response = request.CreateResponse(HttpStatusCode.OK, newproductimageVM);
                }
                return response;
            }));
        }
        public ProductDetailsViewModel GetProductDetail(Guid?productId)
        {
            ProductDetailsViewModel viewModel = new ProductDetailsViewModel();

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                List <ProductImagesViewModel> productImagesViewModelList = new List <ProductImagesViewModel>();
                Product product = db.Products.Where(p => p.Id == productId).FirstOrDefault();
                viewModel.Id                 = product.Id;
                viewModel.Discription        = product.Discription;
                viewModel.Specifications     = product.Specifications;
                viewModel.Code               = product.Code;
                viewModel.ModelNumber        = product.ModelNumber;
                viewModel.Title              = product.Title;
                viewModel.ThumbMainImageName = product.ThumbMainImageName;
                viewModel.Discount           = product.DiscountPerUnitInPercent;
                viewModel.SalePrice          = product.SalePrice;
                // ThumbMainImagePath = "Images/" + p.Product.ProductCategory.Name + "/" + p.Product.ThumbMainImageName,
                //  viewModel.MRPPerUnit = p.m,
                foreach (var image in product.ProductImages.ToList())
                {
                    ProductImagesViewModel productImagesViewModel = new ProductImagesViewModel();
                    productImagesViewModel.Id        = image.Id;
                    productImagesViewModel.FullName  = image.FullName;
                    productImagesViewModel.Extention = image.Extention;
                    productImagesViewModelList.Add(productImagesViewModel);
                }
                viewModel.ProductImagesViewModelList = productImagesViewModelList;
            }
            return(viewModel);
        }
        public ProductImagesViewModel CreateProductImagesViewModel()
        {
            ProductImagesViewModel productImagesViewModel = new ProductImagesViewModel();

            productImagesViewModel.ProductImageLists = getAllProductImageQuery.ExecuteGetAllProductImage();

            return(productImagesViewModel);
        }
        public IActionResult ProductImages(int id)
        {
            var model = new ProductImagesViewModel()
            {
                ProductId = id,
                Images    = this.productService.GetProductImages <ImageViewModel>(id) ?? new List <ImageViewModel>(),
            };

            return(this.View(model));
        }
Exemple #5
0
        private List <ProductImagesViewModel> GetImages(int ProductID)
        {
            var _listImages    = _Imagesrepository.GetProductImages(ProductID);
            var _productImages = new List <ProductImagesViewModel>();
            var _count         = 0;
            var _Path          = "";

            foreach (var _item in _listImages)
            {
                _count += 1;
                var _Newitem = new ProductImagesViewModel();
                _Newitem.ImageID    = _count;
                _Newitem.FileName   = _item.ImagePath;
                _Path               = System.Web.Hosting.HostingEnvironment.MapPath("~/ProductImages/") + _item.ImagePath;
                _Newitem.bytestring = System.IO.File.ReadAllBytes(_Path);
                _Newitem.ID         = _item.Id;
                _productImages.Add(_Newitem);
            }

            return(_productImages);
        }
Exemple #6
0
 public ActionResult GetDataImages(int ProductID)
 {
     try
     {
         var _db = new ApplicationDbContext();
         var _ProductQuantityIds = _db.ProductAttributeWithQuantity.Where(x => x.ProductId == ProductID).Select(x => x.Id);
         var _listImages         = _db.ProductImages.Where(x => _ProductQuantityIds.Contains(x.ProductQuantityId)).ToList();
         var _productImages      = new List <ProductImagesViewModel>();
         var _count = 0;
         foreach (var _item in _listImages)
         {
             _count += 1;
             var _Newitem = new ProductImagesViewModel();
             _Newitem.ImageID  = _count;
             _Newitem.FileName = _item.ImagePath;
             _productImages.Add(_Newitem);
         }
         return(Json(new { Success = true, ex = "", data = _productImages }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { Success = false, ex = ex.Message.ToString(), data = "" }, JsonRequestBehavior.AllowGet));
     }
 }