Пример #1
0
        public async Task <IActionResult> AddProducts(ProductVM model)
        {
            string upload   = string.Empty;
            string fileName = string.Empty;
            string type     = string.Empty;
            //long size = 0;
            string fullPath = string.Empty;



            var vmodel = new Product
            {
                ArabicName  = model.ArabicName,
                EnglishName = model.EnglishName,
                FrenchName  = model.FrenchName,
                Price       = model.Price,
                Quantity    = model.Quantity,
                Disaccunt   = model.Disaccunt,
                InsertUser  = model.InsertUser,
                IPAdress    = model.IPAdress,
                //ProductImageLink = upload,
                //ProductImageName = fileName,
                InsertDate = DateTime.Now,
                category   = categoryService.Find(model.CategoryId)
            };

            var result = await productService.AddAsync(vmodel);

            if (model.File != null && model.File.Count > 0)
            {
                foreach (IFormFile item in model.File)
                {
                    type = item.ContentType;
                    // size=item.Length;
                    upload   = Path.Combine(hosting.WebRootPath, "ProductImage");
                    fileName = Guid.NewGuid().ToString() + "_" + item.FileName;
                    fullPath = Path.Combine(upload, fileName);
                    item.CopyTo(new FileStream(fullPath, FileMode.Create));
                    var productImage = new ProductImage
                    {
                        Name = fileName,
                        Type = type,
                        // Size=Convert.ToInt32(size),
                        Path      = fullPath,
                        productId = vmodel.Id
                    };
                    await productImageService.AddAsync(productImage);
                }
            }

            return(Json(new
            {
                status = JsonStatus.Success,
                link = "جيد",
                color = NotificationColor.success.ToString().ToLower(),
                msg = "تم الحفظ نجاح"
            }));
        }
Пример #2
0
        public async Task <IActionResult> ProductImageAdd(ProductImageAddDto productImageAddDto, IFormFile[] file)
        {
            if (file == null)
            {
                return(View().ShowMessage(Status.Error, "Hata", "Lütfen resim seçiniz!"));
            }



            //try
            //{
            foreach (var image in file)
            {
                //    image = new Bitmap(image, 1080, 1300);
                //using (Graphics g = Graphics.FromImage((System.Drawing.Image)yeniimg))
                //    g.DrawImage(img, 0, 0, genislik, yukseklik);

                //yeniimg.Save(Server.MapPath("resimler/") + "yontem1.jpeg");


                string imageExtension = Path.GetExtension(image.FileName);
                string imageName      = Guid.NewGuid() + imageExtension;

                string path = Path.Combine(Directory.GetCurrentDirectory(), $"wwwroot/img/{imageName}");

                using var stream = new FileStream(path, FileMode.Create);


                await image.CopyToAsync(stream);


                productImageAddDto.ImageTitle = image.FileName;
                productImageAddDto.ImageUrl   = imageName;

                var productImage = _mapper.Map <ProductImage>(productImageAddDto);
                await _productImageService.AddAsync(productImage);
            }
            //}
            //catch (Exception)
            //{

            //    return View().ShowMessage(Status.Error, "Hata", "Resimler yüklenirken hata oluştu lütfen yeniden deneyiniz!");
            //}



            return(RedirectToAction("ProductImageList", new { id = productImageAddDto.ProductId }).ShowMessage(Status.Ok, "Başarılı", "Resimler başarıyla yüklendi."));
        }
Пример #3
0
        public async Task <IActionResult> UpImages(long id, string[] imgFiles)
        {
            if (imgFiles.Count() <= 0)
            {
                return(Json(new AjaxResult {
                    Status = 0, Msg = "请选择上传的图片"
                }));
            }
            List <string> lists = new List <string>();

            foreach (string imgFile in imgFiles)
            {
                if (imgFile.Contains("upload/"))
                {
                    lists.Add(imgFile);
                }
                else
                {
                    var res = await ImageHelper.Base64SaveAsync(imgFile);

                    if (!res.Key)
                    {
                        return(Json(new AjaxResult {
                            Status = 0, Msg = res.Value
                        }));
                    }
                    lists.Add(res.Value);
                }
            }
            List <string> imgUrls = lists.Distinct().ToList();
            long          resid   = await productImageService.AddAsync(id, imgUrls);

            if (resid <= 0)
            {
                return(Json(new AjaxResult {
                    Status = 0, Msg = "上传失败"
                }));
            }
            return(Json(new AjaxResult {
                Status = 1, Msg = "上传成功"
            }));
        }
Пример #4
0
        public async Task <IActionResult> UploadImage(IFormFile file)
        {
            ProductImage img = new ProductImage();

            img.Name = file.FileName;

            MemoryStream ms = new MemoryStream();

            file.CopyTo(ms);
            img.Image = ms.ToArray();

            ms.Close();
            ms.Dispose();
            img.ProductId = new Guid("00a5b282-d5de-47d5-ac8f-75b5b032808a");
            img.Url       = file.FileName;


            await _productImageService.AddAsync(img);

            return(Ok(file.Length));
        }