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

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

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

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

            return View(viewModel);
        }
예제 #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);
            }
        }
예제 #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);
            }
        }