Ejemplo n.º 1
0
        public ActionResult  DelCateg(int categoneId)
        {
            Categone deletedCategone = repository.DeleteCategone(categoneId);

            if (deletedCategone != null)
            {
                TempData["message"] = string.Format("Категория '{0}' удалена", deletedCategone.Name);
            }
            return(RedirectToAction("Allsubcategone"));
        }
Ejemplo n.º 2
0
        public ActionResult Subcategone(Categone categone)
        {
            if (ModelState.IsValid)
            {
                repository.SaveCategone(categone);
                TempData["message"] = string.Format("Категория товара  '{0}' сохранена", categone.Name);
            }

            return(RedirectToAction("Subcategone"));
        }
Ejemplo n.º 3
0
        public Categone DeleteCategone(int сategoneID)
        {
            Categone dbDC = context.Categones.Find(сategoneID);

            if (dbDC != null)
            {
                context.Categones.Remove(dbDC);
                context.SaveChanges();
            }
            return(dbDC);
        }
Ejemplo n.º 4
0
 public void SaveCategone(Categone categone)
 {
     if (categone.CategoneID == 0)
     {
         context.Categones.Add(categone);//добавляет товар в хранилище, если ProductID равен 0
     }
     else //в противном случае она применяет изменения к существующей записи в базе данных.
     {
         Categone dbEntry = context.Categones.Find(categone.CategoneID);
         if (dbEntry != null)
         {
             dbEntry.CategoneID = categone.CategoneID;
             dbEntry.Name       = categone.Name;
             dbEntry.SectionID  = categone.SectionID;
         }
     }
     context.SaveChanges();
 }
Ejemplo n.º 5
0
 public ActionResult Edit(Product product, Categone categone, HttpPostedFileBase image)
 {
     logger.Error("Редактирование товара");
     if (ModelState.IsValid)
     {
         if (image != null)
         {
             product.ImageMimeType = image.ContentType;
             product.ImageData     = new byte[image.ContentLength];
             image.InputStream.Read(product.ImageData, 0, image.ContentLength);
         }
         repository.SaveProduct(product);
         TempData["message"] = string.Format("{0} has been saved", product.Name);
         return(RedirectToAction("Index"));
     }
     else
     {
         // there is something wrong with the data values
         return(View(product));
     }
 }
Ejemplo n.º 6
0
        //   [ValidateInput(false)] // чтобы  не отбрасывало  хтмл или [AllowHtml]
        public ActionResult Create(Product product, Categzer categzer, Categone categone, Categtw categtw, HttpPostedFileBase image, object sender, EventArgs e, int[] selectedApplyings, int[] selectedPropertys, int[] selectedTechcharacters)  // - создание нового товара в админке
        {
            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    product.ImageMimeType = image.ContentType;
                    product.ImageData     = new byte[image.ContentLength];
                    image.InputStream.Read(product.ImageData, 0, image.ContentLength);
                }

                TempData["message"] = string.Format("Товар '{0}' сохранен", product.Name);

                product.Applyings = new List <Applying>();
                if (selectedApplyings != null)
                {
                    foreach (var c in cont.Applyings)
                    {
                        if (selectedApplyings.Contains(c.ApplyingID))

                        {
                            product.Applyings.Add(c);
                        }
                    }
                }

                product.Propers = new List <Proper>();
                if (selectedPropertys != null)
                {
                    foreach (var c in cont.Propers)
                    {
                        if (selectedPropertys.Contains(c.ProperID))
                        {
                            product.Propers.Add(c);
                        }
                    }
                }

                if (selectedTechcharacters != null)
                {
                    foreach (var c in cont.Techcharacters)
                    {
                        if (selectedTechcharacters.Contains(c.TechcharacterID))
                        {
                            product.Techcharacters.Add(c);
                        }
                    }
                }

                ViewBag.Alldescription = product.Alldescription;
                ViewBag.Description    = product.Description;
                ViewBag.ProducerID     = new SelectList(cont.Producers, "ProducerID", "Name", product.ProducerID);
                ViewBag.CategoneID     = new SelectList(cont.Categones, "CategoneID", "Name", product.CategoneID);
                ViewBag.CategtwID      = new SelectList(cont.Categtws, "CategtwID", "Name", product.CategtwID);
                ViewBag.PackingID      = new SelectList(cont.Packings, "PackingID", "Name", product.PackingID);
                ViewBag.CategzerID     = new SelectList(cont.Categzers, "CategzerID", "Name", product.CategzerID);

                cont.Entry(product).State = EntityState.Modified;
                cont.Products.Add(product);
                cont.SaveChanges();
                TempData["message"] = string.Format("Товар '{0}' сохранен", product.Name);
            }


            ViewBag.Techcharacters = cont.Techcharacters.ToList();
            ViewBag.Applyings      = cont.Applyings.ToList();
            ViewBag.Propers        = cont.Propers.ToList();


            return(RedirectToAction("Create"));
        }