public JsonResult AddPost(PostViewModel postViewModel) { if (!ModelState.IsValid) { return Json("Model state is not valid."); } _storageService.AddPost(Session, postViewModel); BlogHub.RefreshPosts(); return Json("Success"); }
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; }
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); }