Example #1
0
        public async Task <IActionResult> ConfirmEdit(ProductImageVM productVM)
        {
            if (ModelState.IsValid)
            {
                Product product = productVM.Product;
                Image   image   = productVM.Image;

                string wwwRootPath = _hostEnvironment.WebRootPath;
                string fileName    = Path.GetFileNameWithoutExtension(image.ImageFile.FileName);
                string extension   = Path.GetExtension(image.ImageFile.FileName);
                fileName        = fileName + DateTime.Now.ToString("yymmssff") + extension;
                image.ImageName = fileName;
                string path = Path.Combine(wwwRootPath + "/images/", fileName);

                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    await image.ImageFile.CopyToAsync(fileStream);
                }

                product.Photo = fileName;

                _context.Images.Add(image);
                _context.Attach(product).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(productVM));
        }
Example #2
0
 /// <summary>
 /// 编辑
 /// </summary>
 /// <param name="vm"></param>
 /// <returns></returns>
 public ActionResult Edit(ProductImageVM vm)
 {
     vm.ProductImage = _ProductImageService.GetById(vm.Id) ?? new ProductImage();
     vm.ImgInfo      = vm.ProductImage.BaseImage ?? new BaseImage();
     if (vm.ProductImage.ProductId == 0)
     {
         vm.ProductImage.ProductId = vm.ProductId;
     }
     return(View(vm));
 }
        public async Task <IActionResult> UploadImage(ProductImageVM model)
        {
            string avatar = await _imageWriter.UploadImageAsync(model.File);

            if (await _productService.UpdateAvatar(new Product()
            {
                Id = model.Id, Avatar = avatar
            }))
            {
                return(Ok(true));
            }
            return(BadRequest("Lo sentimos , no se ha podido agregar la imagen"));
        }
Example #4
0
        public async Task <IActionResult> Edit(int productId)
        {
            Product product = await _context.Products.FirstOrDefaultAsync(x => x.Id == productId);

            ProductImageVM productVM = new ProductImageVM();

            productVM.Product = product;

            if (product == null)
            {
                return(RedirectToAction("Index"));
            }

            return(View(productVM));
        }
 public async Task <ActionResult <ProductImageVM> > Put(ProductImageVM imageVM)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     else
     {
         var mainData = repository.Get(imageVM.ID);
         if (mainData == null)
         {
             return(NotFound());
         }
         var data = repository.Update(imageVM);
         return(data);
     }
 }
Example #6
0
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="vm"></param>
        /// <param name="pn"></param>
        /// <returns></returns>
        public ActionResult List(ProductImageVM vm, int pn = 1)
        {
            int totalCount,
                pageIndex = pn,
                pageSize  = PagingConfig.PAGE_SIZE;
            var list      = _ProductImageService.GetManagerList(vm.Id, pageIndex, pageSize, out totalCount);
            var paging    = new Paging <ProductImage>()
            {
                Items = list,
                Size  = PagingConfig.PAGE_SIZE,
                Total = totalCount,
                Index = pn,
            };

            vm.Paging = paging;
            return(View(vm));
        }
Example #7
0
        public ActionResult EditProductImage(Product product, string thumbnailFile1)
        {
            bool isLogin = false;

            if (Session["isLogin"] != null)
            {
                isLogin = (bool)Session["isLogin"];
            }
            if (!isLogin)
            {
                Session["isLogin"] = false;
                return(RedirectToAction("Login", "Home"));
            }
            ProductImageVM productImage1 = new ProductImageVM();
            ProductImageVM productImage2 = new ProductImageVM();
            ProductImageVM productImage3 = new ProductImageVM();
            ProductImageVM productImage4 = new ProductImageVM();
            ProductImageVM productImage5 = new ProductImageVM();

            if (product.file1 != null)
            {
                productImage1.id        = product.Id.ToString();
                productImage1.fileNo    = "1";
                productImage1.image     = product.file1;
                productImage1.thumbnail = thumbnailFile1;

                using (var client = new HttpClientDemo())
                {
                    var postTask = client.PostAsJsonAsync("registration/updateProductImage.php", productImage1);
                    postTask.Wait();
                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                    }

                    else
                    {
                    }
                }
            }
            if (product.file2 != null)
            {
                productImage2.id        = product.Id.ToString();
                productImage2.fileNo    = "2";
                productImage2.image     = product.file2;
                productImage2.thumbnail = "";

                using (var client = new HttpClientDemo())
                {
                    var postTask = client.PostAsJsonAsync("registration/updateProductImage.php", productImage2);
                    postTask.Wait();
                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                    }

                    else
                    {
                    }
                }
            }
            if (product.file3 != null)
            {
                productImage3.id        = product.Id.ToString();
                productImage3.fileNo    = "3";
                productImage3.image     = product.file3;
                productImage3.thumbnail = "";

                using (var client = new HttpClientDemo())
                {
                    var postTask = client.PostAsJsonAsync("registration/updateProductImage.php", productImage3);
                    postTask.Wait();
                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                    }

                    else
                    {
                    }
                }
            }
            if (product.file4 != null)
            {
                productImage4.id        = product.Id.ToString();
                productImage4.fileNo    = "4";
                productImage4.image     = product.file4;
                productImage4.thumbnail = "";

                using (var client = new HttpClientDemo())
                {
                    var postTask = client.PostAsJsonAsync("registration/updateProductImage.php", productImage4);
                    postTask.Wait();
                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                    }

                    else
                    {
                    }
                }
            }
            if (product.file5 != null)
            {
                productImage5.id        = product.Id.ToString();
                productImage5.fileNo    = "5";
                productImage5.image     = product.file5;
                productImage5.thumbnail = "";

                using (var client = new HttpClientDemo())
                {
                    var postTask = client.PostAsJsonAsync("registration/updateProductImage.php", productImage5);
                    postTask.Wait();
                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                    }

                    else
                    {
                    }
                }
            }

            return(RedirectToAction("List", "Product"));
        }
Example #8
0
        public IActionResult Create()
        {
            ProductImageVM product = new ProductImageVM();

            return(View(product));
        }
Example #9
0
        public ActionResult Detail(int Id)
        {
            using (var de = new DatisEntities())
            {
                Product currentProduct = de.Products.Where(m => m.Id == Id).FirstOrDefault();
                if (currentProduct != null)
                {
                    BrandCategory brandCat = currentProduct.BrandCategory;

                    List <string>         images        = de.Images.Where(m => m.ProductId == currentProduct.Id && m.TableId == (int)DatisEnums.TableId.Product).Select(p => p.Path).ToList();
                    Image                 mainImage     = de.Images.Where(m => m.ProductId == currentProduct.Id && m.Type == (int)DatisEnums.ImgeType.Main && m.TableId == (int)DatisEnums.TableId.Product).FirstOrDefault();
                    List <ProductImageVM> allImagesList = new List <ProductImageVM>();
                    if (images.Count > 0)
                    {
                        foreach (var image in images)
                        {
                            ProductImageVM pi = new ProductImageVM
                            {
                                Image200 = image.AddDirectoryToPath("200"),
                                Image350 = image.AddDirectoryToPath("350"),
                                Image60  = image.AddDirectoryToPath("60"),
                                ImageOrg = image
                            };
                            allImagesList.Add(pi);
                        }
                    }
                    Image bLogo = de.Images.Where(m => m.BrandId == currentProduct.BrandCategory.BrandId && m.TableId == (int)DatisEnums.TableId.Brand).FirstOrDefault();
                    List <Tuple <string, string> >        featuresKeyVal = new List <Tuple <string, string> >();
                    List <KeyValuePair <string, string> > filesKeyVal    = new List <KeyValuePair <string, string> >();
                    featuresKeyVal = de.FeatureProducts.Where(n => n.ProductId == currentProduct.Id).Select(j => new { j.Feature.Name, j.Value }).AsEnumerable().Select(p => Tuple.Create(p.Name, p.Value)).ToList();
                    filesKeyVal    =
                        de.Files.Where(
                            m => m.TableId == (int)DatisEnums.TableId.Product && m.ForeignId == currentProduct.Id)
                        .Select(x => new { Name = x.Name, Val = x.Path })
                        .ToDictionary(t => t.Name, t => t.Val)
                        .ToList();
                    ProductVM pvm = new ProductVM()
                    {
                        Model        = currentProduct.Model,
                        Id           = currentProduct.Id,
                        Description  = currentProduct.Description,
                        MainImage200 = mainImage != null?mainImage.Path.AddDirectoryToPath("200") : "",
                                           MainImage350 = mainImage != null?mainImage.Path.AddDirectoryToPath("350") : "",
                                                              MainImage60 = mainImage != null?mainImage.Path.AddDirectoryToPath("60") : "",
                                                                                MainImage = mainImage != null ? mainImage.Path : "",
                                                                                BrandName = currentProduct.BrandCategory.Brand.Name,
                                                                                BrandLogo = bLogo != null?bLogo.Path.AddDirectoryToPath("60") : "",
                                                                                                AllImages       = allImagesList,
                                                                                                CategoryName    = currentProduct.BrandCategory.Category.Name,
                                                                                                Features        = featuresKeyVal,
                                                                                                Summary         = currentProduct.Summary,
                                                                                                FeaturesSummary = currentProduct.FeaturesSummary,
                                                                                                Files           = filesKeyVal
                    };
                    List <KeyValuePair <string, string> > breadItems = new List <KeyValuePair <string, string> >();
                    KeyValuePair <string, string>         brand      = new KeyValuePair <string, string>(currentProduct.BrandCategory.Brand.Name, Url.Action("Index", "Brand", new { Id = currentProduct.BrandCategory.BrandId, BrandTitle = currentProduct.BrandCategory.Brand.Name }));
                    breadItems.Add(brand);
                    KeyValuePair <string, string> rootCat = new KeyValuePair <string, string>(currentProduct.BrandCategory.Category.Name, Url.Action("Index", "Category", new { Id = currentProduct.BrandCategory.CategoryId, CategoryTitle = currentProduct.BrandCategory.Category.Name }));
                    breadItems.Add(rootCat);
                    ViewBag.BreadCrumb = breadItems;

                    #region Related Products
                    BrandCategory    currentBrandCat = de.BrandCategories.FirstOrDefault(m => m.Id == currentProduct.BrandCategory.Id);
                    List <ProductVM> productsVm      = new List <ProductVM>();
                    if (currentBrandCat != null)
                    {
                        foreach (var product in currentBrandCat.Products.Take(10))
                        {
                            Image mLogo =
                                de.Images.FirstOrDefault(m => m.ProductId == product.Id && m.Type == (int)DatisEnums.ImgeType.Main &&
                                                         m.TableId == (int)DatisEnums.TableId.Product);
                            Image bLogo2 =
                                de.Images.FirstOrDefault(m => m.BrandId == product.BrandCategory.BrandId &&
                                                         m.TableId == (int)DatisEnums.TableId.Brand);
                            ProductVM pvm2 = new ProductVM()
                            {
                                Model        = product.Model,
                                Id           = product.Id,
                                Description  = product.Description,
                                MainImage    = mLogo != null ? mLogo.Path : "",
                                MainImage200 = mLogo != null?mLogo.Path.AddDirectoryToPath("200") : "",
                                                   MainImage350 = mLogo != null?mLogo.Path.AddDirectoryToPath("350") : "",
                                                                      MainImage60 = mLogo != null?mLogo.Path.AddDirectoryToPath("60") : "",
                                                                                        BrandName = product.BrandCategory.Brand.Name,
                                                                                        BrandLogo = bLogo2 != null?bLogo2.Path.AddDirectoryToPath("60") : ""
                            };
                            productsVm.Add(pvm2);
                        }
                        ViewBag.Related = productsVm;
                    }

                    #endregion

                    return(View(pvm));
                }
                return(null);
            }
        }