Example #1
0
        public ActionResult Create()
        {
            Blogs blog = new Blogs();

            CreateBlogViewModel viewModel = new CreateBlogViewModel
            (
                blog,
                UnitOfWork_.CategoryRepo.GetCategories()
            );

            return View(viewModel);
        }
Example #2
0
        public ActionResult Edit(int id)
        {
            Blogs blog = UnitOfWork_.BlogRepo.GetBlogById(id);

            CreateBlogViewModel viewModel = new CreateBlogViewModel
            (
                blog,
                UnitOfWork_.CategoryRepo.GetCategories()
            );

            return View(viewModel);
        }
Example #3
0
        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);
            }
        }
Example #4
0
        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);
            }
        }