// GET: Categories public async Task <ActionResult> Index() { var categories = await db.Categories.ToListAsync(); var categoriesIndexViewModel = ClassCategoryConverter.ConvertListCategorysToListCategoryIndexViewModel(categories); return(View(categoriesIndexViewModel)); }
public async Task <ActionResult> LoadCategoriesJSON() { var result = await db.Categories.ToListAsync(); var categoriesIndexViewModel = ClassCategoryConverter.ConvertListCategorysToListCategoryIndexViewModel(result); return(Json(categoriesIndexViewModel, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,SlugUrl")] CategoryEditViewModel categoryEditViewModel) { if (ModelState.IsValid) { Category category = ClassCategoryConverter.ConvertCategoryEditViewModelToCategory(categoryEditViewModel); db.Entry(category).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(categoryEditViewModel)); }
public async Task <ActionResult> Create([Bind(Include = "Name,SlugUrl")] CategoryCreateViewModel categoryCreateViewModel) { if (ModelState.IsValid) { Category category = ClassCategoryConverter.ConvertCategoryCreateViewModelToCategory(categoryCreateViewModel); db.Categories.Add(category); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(categoryCreateViewModel)); }
// GET: Categories/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Category category = await db.Categories.FindAsync(id); if (category == null) { return(HttpNotFound()); } CategoryEditViewModel categoryEditViewModel = ClassCategoryConverter.ConvertCategoryToCategoryEditViewModel(category); return(View(categoryEditViewModel)); }