Ejemplo n.º 1
0
        public ActionResult Create()
        {
            CategoryAndSubGategoryViewModel model = new CategoryAndSubGategoryViewModel
            {
                Categories = db.Categories.ToList(),
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            var sub = db.SubCategories.SingleOrDefault(x => x.Id == id);
            CategoryAndSubGategoryViewModel model = new CategoryAndSubGategoryViewModel
            {
                Categories  = db.Categories.ToList(),
                SubCategory = sub
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(CategoryAndSubGategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                var subExisting = db.SubCategories.Where(x => x.Name == model.SubCategory.Name && x.CategoryId == model.SubCategory.CategoryId && x.Id != model.SubCategory.Id);
                if (subExisting.Count() > 0)
                {
                    ViewBag.error = "You Already Have This Here";
                }
                else
                {
                    db.SubCategories.Update(model.SubCategory);
                    db.SaveChanges();
                    return(RedirectToAction(nameof(Index)));
                }
            }
            CategoryAndSubGategoryViewModel modelVm = new CategoryAndSubGategoryViewModel
            {
                Categories = db.Categories.ToList(),
            };

            return(View(modelVm));
        }
Ejemplo n.º 4
0
        public ActionResult Create(CategoryAndSubGategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                var subExisting = db.SubCategories.Include(x => x.Category).Where(x => x.Name == model.SubCategory.Name && x.CategoryId == model.SubCategory.CategoryId);
                if (subExisting.Count() > 0)
                {
                    ViewBag.error = "You Already Have This Existed At " + subExisting.FirstOrDefault().Category.Name + " Category";
                }
                else
                {
                    db.SubCategories.Add(model.SubCategory);
                    db.SaveChanges();
                    return(RedirectToAction(nameof(Index)));
                }
            }
            CategoryAndSubGategoryViewModel modelVm = new CategoryAndSubGategoryViewModel
            {
                Categories = db.Categories.ToList(),
            };

            return(View(modelVm));
        }
Ejemplo n.º 5
0
 public ActionResult ConfirmDelete(CategoryAndSubGategoryViewModel model)
 {
     db.SubCategories.Remove(model.SubCategory);
     db.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }