Esempio n. 1
0
        public ActionResult NewPost(int?id)
        {
            NewBlogViewModel model = new NewBlogViewModel();

            if (id != null)
            {
                model.Post = _postsManagement.Get(p => p.ID == id);
            }

            return(View(model));
        }
        public ActionResult Details(int?id)
        {
            if (id != null)
            {
                Posts prevPost;
                Posts nextPost;

                BlogViewModel model = new BlogViewModel
                {
                    PostsList = new List <Posts>(),
                    Post      = _postsManagement.Get(m => m.ID == id),
                    Setting   = _settingsManagement.Get(m => m.Name == "hotel.name")
                };
                if (model.Post.ID - 1 >= 1)
                {
                    prevPost = _postsManagement.Get(p => p.ID == model.Post.ID - 1);
                    model.PostsList.Add(prevPost);
                }
                else
                {
                    model.PostsList.Add(model.Post);
                }

                if (model.Post.ID + 1 <= _postsManagement.GetAll().Count())
                {
                    nextPost = _postsManagement.Get(p => p.ID == model.Post.ID + 1);
                    model.PostsList.Add(nextPost);
                }
                else
                {
                    model.PostsList.Add(model.Post);
                }

                return(View(model));
            }

            return(RedirectToAction("Index"));
        }