public ActionResult Create() { Blogs blog = new Blogs(); CreateBlogViewModel viewModel = new CreateBlogViewModel ( blog, UnitOfWork_.CategoryRepo.GetCategories() ); return View(viewModel); }
public ActionResult Edit(int id) { Blogs blog = UnitOfWork_.BlogRepo.GetBlogById(id); CreateBlogViewModel viewModel = new CreateBlogViewModel ( blog, UnitOfWork_.CategoryRepo.GetCategories() ); return View(viewModel); }
public ActionResult Edit(int id, FormCollection collection) { Blogs blog = UnitOfWork_.BlogRepo.GetBlogById(id); try { if (blog != null && TryUpdateModel(blog, "Blog")) { blog.PostedBy = User.Identity.Name; blog.DatePosted = DateTime.Now; UnitOfWork_.BlogRepo.Save(); return RedirectToAction("Index"); } else { CreateBlogViewModel viewModel = new CreateBlogViewModel ( blog, UnitOfWork_.CategoryRepo.GetCategories() ); return View(viewModel); } } catch { CreateBlogViewModel viewModel = new CreateBlogViewModel ( blog, UnitOfWork_.CategoryRepo.GetCategories() ); return View(viewModel); } }
public ActionResult Create(Blogs blog) { try { if (ModelState.IsValid) { blog.PostedBy = User.Identity.Name; blog.DatePosted = DateTime.Now; UnitOfWork_.BlogRepo.AddBlog(blog); UnitOfWork_.BlogRepo.Save(); return RedirectToAction("Index"); } else { CreateBlogViewModel viewModel = new CreateBlogViewModel ( blog, UnitOfWork_.CategoryRepo.GetCategories() ); return View(viewModel); } } catch { CreateBlogViewModel viewModel = new CreateBlogViewModel ( blog, UnitOfWork_.CategoryRepo.GetCategories() ); return View(viewModel); } }