示例#1
0
        public ActionResult Createsubcategory(int id = -1)
        {
            using (_dbContext = new karrykartEntities())
            {

            var category = _dbContext.Categories.Find(id);
                if(category!=null)
                {
                var subcategoryModel =  new SubcategoryModel();
                    subcategoryModel.CategoryName = category.Name;
                    subcategoryModel.CategoryID = category.CategoryID;

                    return View(subcategoryModel);
                }

            }
            return View();
        }
示例#2
0
        public ActionResult Createsubcategory(SubcategoryModel model)
        {
            if (ModelState.IsValid)
            {
                using (_dbContext = new karrykartEntities())
                {
                    var Subcategory = new Subcategory();
                    Subcategory.CategoryID = model.CategoryID;
                    Subcategory.Name = model.Name;

                    _dbContext.Subcategories.Add(Subcategory);
                    _dbContext.SaveChanges();
                    _logger.WriteLog(CommonHelper.MessageType.Success,"New sub category added successfully with id="+Subcategory.SCategoryID,"CreateSubcategory","CategoryController",User.Identity.Name);
                    Success("Subcategory added successfully");
                    return RedirectToAction("Subcategory", "Category", new { id = model.CategoryID });
                }
            }
            return View(model);
        }