Exemplo n.º 1
0
        public JsonResult AddPost(PostViewModel postViewModel)
        {
            if (!ModelState.IsValid)
            {
                return Json("Model state is not valid.");
            }

            _storageService.AddPost(Session, postViewModel);

            BlogHub.RefreshPosts();

            return Json("Success");
        }
Exemplo n.º 2
0
        public void AddPost(HttpSessionStateBase session, PostViewModel postViewModel)
        {
            FillSession(session);

            var posts = (IList<PostViewModel>)session[PostsConst];

            var postsCount = (int)session[PostsCountConst];

            postsCount++;

            postViewModel.Id = postsCount;

            posts.Add(postViewModel);

            posts = posts.OrderByDescending(p => p.Date).ToList();

            session[PostsConst] = posts;
            session[PostsCountConst] = postsCount;
        }
Exemplo n.º 3
0
        public ActionResult Blog()
        {
            var viewModel = new PostViewModel { Date = DateTime.UtcNow };

            ViewBag.GendersList = new List<SelectListItem>
            {
                new SelectListItem
                {
                    Value = "0",
                    Text = "M"
                },
                new SelectListItem
                {
                    Value = "1",
                    Text = "F"
                }
            };

            return View(viewModel);
        }