// GET: Category/Details/5 public async Task <ActionResult> Details(int?id, int?page = 1) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tbcategory tbcategory = await db.tbcategories.FindAsync(id); if (tbcategory == null) { return(HttpNotFound()); } int pageNumber = page ?? 1; ViewBag.poetrylist = tbcategory.tbpoetries.OrderByDescending(m => m.title).ToPagedList <tbpoetry>(pageNumber, 10); return(View(tbcategory)); }
public void AddCategoryAsync(int catid, string name, string desc) { ExitIsNotAdmin(); string returnUrl = "/Admin/Category/Index/"; try { tbcategory cat = null; if (catid != 0) { cat = db.tbcategories.FirstOrDefault(x => x.categoryID == catid); cat.name = name; cat.description = desc; db.SaveChanges(); } else { cat = new tbcategory() { name = name, description = desc }; db.tbcategories.Add(cat); db.SaveChanges(); } returnUrl += cat.categoryID.ToString() + "/"; Response.Redirect(returnUrl); } catch (Exception ex) { Response.Redirect(returnUrl + "?error=ex"); } }