public void SaveContentSubcategory(ContentSubcategoryViewModel model) { using (var context = new ApplicationDbContext()) { var cat = context.ContentCategories .Include(c => c.Subcategories) .Single(c => c.Id == model.ContentCategoryId); if (model.ContentSubcategory.Id > 0) { var subcat = context.ContentSubcategories.Single(s => s.Id == model.ContentSubcategory.Id); subcat.Name = model.ContentSubcategory.Name; subcat.Description = model.ContentSubcategory.Description; subcat.LastModification = DateTime.Now; } else { model.ContentSubcategory.CreateDate = DateTime.Now; model.ContentSubcategory.IsActive = true; cat.Subcategories.Add(model.ContentSubcategory); } context.SaveChanges(); } }
public ActionResult NewSubcategory(int contentCategoryId) { ContentSubcategoryViewModel viewModel = new ContentSubcategoryViewModel() { ContentCategoryId = contentCategoryId, ContentSubcategory = new ContentSubcategory() }; return(PartialView("_SubcategoryForm", viewModel)); }
public ActionResult EditSubcategory(int id, int contentCategoryId) { var subcategory = _repo.GetContentSubcategory(id); ContentSubcategoryViewModel viewModel = new ContentSubcategoryViewModel() { ContentCategoryId = contentCategoryId, ContentSubcategory = subcategory }; return(PartialView("_SubcategoryForm", viewModel)); }
public ActionResult SaveSubcategory(ContentSubcategoryViewModel model) { _repo.SaveContentSubcategory(model); return(RedirectToAction("Edit", "ContentCategories", new { id = model.ContentCategoryId })); }