Пример #1
0
        public ActionResult AddPost(string body, string topic)
        {
            Post post = new Post(){
                Body = body,
                Topic = topic,
                Votes = 0,
            };
            if (Request.IsAuthenticated)
            {
                post.Name = User.Identity.Name;
                post.UserId = 0;
            }
            else
            {
                post.Name = Session["Name"].ToString();
                int id = Convert.ToInt32(Session["UserId"]);
                post.UserId = id;
            }

            post.DateCreated = DateTime.Now;

            blogRepository.Add(post);
            blogRepository.Save();

            return Json(true);
        }
Пример #2
0
        public ActionResult Create(Post post)
        {
            if(ModelState.IsValid)
            {
                post.Name = Session["Name"].ToString();
                post.DateCreated = DateTime.Now;
                int id = Convert.ToInt32(Session["UserId"]);
                post.UserId = id;

                blogRepository.Add(post);
                blogRepository.Save();

                return RedirectToAction("Page");
            }
            return View(post);
        }
Пример #3
0
        public ActionResult AddPostTopic(string body, string topic)
        {
            Post post = new Post()
            {
                Body = body,
                Topic = topic,
                Votes = 0
            };
            post.DateCreated = DateTime.Now;
            post.Name = User.Identity.Name;
            post.UserId = 0;

            blogRepository.Add(post);
            blogRepository.Save();

            return Json(true);
        }
Пример #4
0
 public void Delete(Post post)
 {
     db.Posts.Remove(post);
 }
Пример #5
0
 //Insert/Delete Methods
 public void Add(Post post)
 {
     db.Posts.Add(post);
 }