public ActionResult Post() { string userName = User.Identity.Name; AccountModel user = AccountRepository.GetAccount(userName); PostModel postModel = new PostModel(); postModel.UserId = user.UserId; return View(postModel); }
public PostModel GetPost(int postId) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { var post = entity.WeightMsg_Post.Include("WeightUser").Where(e => e.Post_ID == postId).FirstOrDefault(); PostModel postModel = new PostModel(); postModel.PostId = post.Post_ID; postModel.DateCreated = post.DateCreated; postModel.DateModified = post.DateModified; postModel.DisplayName = post.WeightUser.DisplayName; postModel.PostContent = post.Post_Content; postModel.Title = post.Title; postModel.UserId = post.UserID; postModel.UserName = post.WeightUser.UserName; postModel.Comments = this.GetComments(postModel.PostId); return postModel; } }
public List<PostModel> GetPosts() { List<PostModel> postList = new List<PostModel>(); using (Entities entity = new Entities(BaseBISL.ConnectionString)) { var posts = entity.WeightMsg_Post.Include("WeightUser").Select(e => e).OrderByDescending(f => f.DateCreated); foreach (WeightMsg_Post post in posts) { PostModel postModel = new PostModel(); postModel.PostId = post.Post_ID; postModel.DateCreated = post.DateCreated; postModel.DateModified = post.DateModified; postModel.DisplayName = post.WeightUser.DisplayName; postModel.PostContent = post.Post_Content; postModel.Title = post.Title; postModel.UserId = post.UserID; postModel.UserName = post.WeightUser.UserName; postModel.Comments = this.GetComments(postModel.PostId); postList.Add(postModel); } } return postList; }
public bool InsertPost(PostModel postModel) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { WeightMsg_Post post = new WeightMsg_Post(); post.DateCreated = DateTime.Now; post.DateModified = DateTime.Now; post.Post_Content = postModel.PostContent; post.Title = postModel.Title; post.UserID = postModel.UserId; entity.AddToWeightMsg_Post(post); int rows = entity.SaveChanges(); if (rows > 0) return true; else return false; } }
public ActionResult Post(PostModel postModel) { PostRepository.InsertPost(postModel); return RedirectToAction("Index"); }