Example #1
0
        public ActionResult Edit(ProgramCategories category)
        {
            if (category.Name == "Без категории")
            {
                return(RedirectToAction("Index", "Admin"));
            }
            ApplicationDbContext context = new ApplicationDbContext();

            if (category.CategoryId != 0)
            {
                context = new ApplicationDbContext();
                var UpdatePrograms = context.Categories.Where(c => c.CategoryId == category.CategoryId).FirstOrDefault();
                if (ModelState.IsValid)
                {
                    return(View(UpdatePrograms));
                }
                UpdatePrograms.Name = category.Name;
                context.Entry(UpdatePrograms).State = EntityState.Modified;
                context.SaveChanges();
                TempData["message"] = string.Format("Изменения в категории \"{0}\" были сохранены", category.Name);
                return(RedirectToAction("GetCategoryList", "Admin"));
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(category));
                }
                context.Entry(category).State = EntityState.Added;
                context.SaveChanges();
                TempData["message"] = string.Format("Категория \"{0}\" была создана", category.Name);
                return(RedirectToAction("GetCategoryList", "Admin"));
            }
        }
Example #2
0
        public ActionResult Edit(int id = 0)
        {
            if (id == 0)
            {
                return(RedirectToAction("Index", "Admin"));
            }
            ProgramCategories category = (new ApplicationDbContext()).Categories.First(x => x.CategoryId == id);

            return(View(category));
        }
Example #3
0
 public ActionResult Create(ProgramCategories category)
 {
     return(View("Edit", new ProgramCategories()));
 }