Esempio n. 1
0
 public IActionResult SaveProduct(Product product)
 {
     if (product.Id != 0)
     {
         var OldProduct = ProductRepository.GetAll().Where(p => p.Id == product.Id).First();
         var NawImage   = ImageRepository.GetAll().FirstOrDefault(i => i.Id == product.ImageId);
         OldProduct.Image      = NawImage;
         OldProduct.Name       = product.Name;
         OldProduct.Dictionary = product.Dictionary;
         OldProduct.Price      = product.Price;
         ProductRepository.Save();
         return(RedirectToAction("Products"));
     }
     else
     {
         if (product.ImageId != null)
         {
             product.Image = ImageRepository.GetAll().Single(s => s.Id == product.ImageId);
             ProductRepository.Add(product);
             ProductRepository.Save();
             return(RedirectToAction("Products"));
         }
         else
         {
             ViewBag.Message = "Добавьте картинку!";
             ProductRepository.Add(product);
             ProductRepository.Save();
             return(RedirectToAction("Products"));
             // return View("EditProduct",new Product());
         }
     }
 }
Esempio n. 2
0
        public IActionResult RemoveImage(Image image)
        {   //Получаем Image по Id
            var Imag = ImageRepository.GetAll().Single(s => s.Id == image.Id);

            //Удаляем миниатюры этого Image
            foreach (Thrumbneil i in Imag.Thrumbneils)
            {
                FileInfo InfoThrumb = new FileInfo("wwwroot\\" + i.Path.Substring(1));
                InfoThrumb.Delete();
                //Удаляем из бд миниатюры
                //ImageRepository.Context.Thrumbneils.Remove(i);
            }

            //Удаляем сам Image
            FileInfo Info = new FileInfo("wwwroot\\" + Imag.Path.Substring(1));

            Info.Delete();
            //Удаляем ссылки в продуктах
            var Products        = ProductRepository.GetAll().Where(p => p.Image != null).ToList();
            var ProductsToImage = Products.Where(p => p.Image.Id == Imag.Id);

            foreach (Product i in ProductsToImage)
            {
                i.Image = null;
            }
            //Удаляем Image из БД
            ImageRepository.Remove(Imag);
            ImageRepository.Save();

            return(RedirectToAction("ImagePanel"));
        }
Esempio n. 3
0
        public IActionResult AddImageToProduct(Product Pro, int Id1)
        {
            var Image = ImageRepository.GetAll().Single(i => i.Id == Id1);

            Pro.Image = Image;
            return(View("EditProduct", Pro));
        }
Esempio n. 4
0
        public IActionResult ImagePanel(int Id = 1)
        {
            var Images = ImageRepository.GetAll().Skip((Id - 1) * 10).Take(10).ToList();
            var totalNumberInCollection = 5;
            var itemsPerPage            = 2;

            ViewBag.PaginatedMeta = _paginatedMetaService.GetMetaData(totalNumberInCollection, Id, itemsPerPage);
            return(View("DrowPictures", Images));
        }
Esempio n. 5
0
        public IActionResult DrowTrumbneils(int size, int Id = 1)
        {
            var Images = ImageRepository.GetAll().Skip((Id - 1) * 10).Take(10).ToList();
            var totalNumberInCollection = ImageRepository.Context.Images.Count();
            var itemsPerPage            = 2;

            ViewBag.PaginatedMeta = _paginatedMetaService.GetMetaData(totalNumberInCollection, Id, itemsPerPage);
            List <Thrumbneil> thrumbneils = new List <Thrumbneil>();

            foreach (Image i in Images)
            {
                thrumbneils = i.Thrumbneils.Where(t => t.ThrumbneilSizeId == size).ToList();
            }
            return(View(thrumbneils));
        }
Esempio n. 6
0
        public IActionResult ChooseImage()
        {
            int     ProductId         = int.Parse(Request.Form["Id"]);
            var     ProductName       = Request.Form["Name"];
            var     ProductDictionary = Request.Form["Dictionary"];
            var     ProductPrice      = int.Parse(Request.Form["Price"]);
            Product NewProduct        = new Product()
            {
                Id = ProductId, Name = ProductName, Dictionary = ProductDictionary, Price = ProductPrice
            };
            ProductVM productVM = new ProductVM()
            {
                ProductM = NewProduct, Images = ImageRepository.GetAll().ToList()
            };

            return(View(productVM));
        }
Esempio n. 7
0
 //Получить все картинки
 public string GetAllImageToTrumbneils()
 {
     return(JsonConvert.SerializeObject(ImageRepository.GetAll().ToList()));
 }