public ActionResult AddFriend(AddFriend model) { //if (!IsLogin) { // return View(); //} using (blogEntities ct = new blogEntities()) { //SunMoon.Blog.DataAccess.EntityFramework.Friend f = new DataAccess.EntityFramework.Friend(); //f.CreateTime = DateTime.Now; //f.FriendID = model.Friend; //f.Self = base.Passport.AccountID; //ct.Friends.Add(f); SunMoon.Blog.DataAccess.EntityFramework.Message msg = new Message(); msg.ID = Guid.NewGuid(); msg.Author = Passport.AccountID; msg.CreateTime = DateTime.Now; msg.Description = "{'type':'addfriend'}"; msg.Owner = model.Friend; ct.Messages.Add(msg); ct.SaveChanges(); return(RedirectToAction("queryperson")); } }
public ActionResult Create(string topicID, string commentID, string description) { try { // TODO: Add insert logic here using (blogEntities ct = new blogEntities()) { Comment c = new Comment(); c.Author = base.Passport.AccountID; c.CreateTime = DateTime.Now; c.Description = description; c.ID = Guid.NewGuid(); c.IP = Request.UserHostAddress; if (!string.IsNullOrWhiteSpace(commentID)) { c.ParentId = Guid.Parse(commentID); } c.TopicID = Guid.Parse(topicID); ct.Comments.Add(c); ct.SaveChanges(); } return(RedirectToAction("Index", "Home")); } catch { return(View()); } }
public void AddAuthor(Author author) { using (var context = new blogEntities()) { context.Author.Add(author); context.SaveChanges(); } }
public void AddComment(Comment comment) { using (var context = new blogEntities()) { context.Comment.Add(comment); context.SaveChanges(); } }
public void AddArticle(Article article) { using (var context = new blogEntities()) { context.Article.Add(article); context.SaveChanges(); } }
public ActionResult Index() { using (blogEntities ct = new blogEntities()) { History h = new History(); h.CreateTime = DateTime.Now; h.Guest = "guest"; h.Url = "/"; h.IP = Request.UserHostAddress; ct.Histories.Add(h); ct.SaveChanges(); } IndexModel model = new IndexModel(); if (IsLogin) { model.Passport = base.Passport; using (blogEntities en = new blogEntities()) { var users = en.Friends.Where(f => f.Self.Equals(Passport.AccountID)).Select(f => f.FriendID).ToList(); model.Topics = (from t in en.Topics.Include("Comments") where t.Author.Equals(Passport.AccountID) || users.Contains(t.Author) orderby t.CreateTime descending select t ).ToList(); //en.Topics //.Where( // t => // t.Author.Equals(Passport.AccountID) // || users.Contains(t.Author) //) //.OrderByDescending(t => t.CreateTime) //.ToList(); if (en.Users.Count(u => u.UserID.Equals(Passport.AccountID)) > 0) { model.Author = en.Users.Where(u => u.UserID.Equals(Passport.AccountID)).First(); } } } else { return(Redirect("~/Account/LogOn")); } return(View(model)); //return Json(model, JsonRequestBehavior.AllowGet); }
public ActionResult UpdatePost(int?id, string title, DateTime?time, string body) { if (!IsAdmin) { return(RedirectToAction("Index")); } Post post = GetPost(id); post.Title = title; post.Time = DateTime.Now; post.Body = body; ViewBag.isAdmin = IsAdmin; if (!id.HasValue) { _modelEntities.Posts.Add(post); } _modelEntities.SaveChanges(); return(View("details", post)); }
public ActionResult Register(RegisterModel model) { using (blogEntities en = new blogEntities()) { User user = new User(); user.UserID = model.UserName; user.Passwrod = model.Password; user.Mail = model.Email; en.Users.Add(user); en.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public ActionResult AddTopic(string title, string desc) { using (blogEntities en = new blogEntities()) { Topic t = new Topic(); t.Title = title; t.Description = desc; t.CreateTime = t.UpdateTime = DateTime.Now; t.Author = base.Passport.AccountID; t.ID = Guid.NewGuid(); en.Topics.Add(t); en.SaveChanges(); return(View(t)); } }
public ActionResult AddComment(string description, Guid topicId) { using (blogEntities ct = new blogEntities()) { Comment comment = new Comment(); comment.ID = Guid.NewGuid(); comment.CreateTime = DateTime.Now; comment.Author = base.Passport.AccountID; comment.IP = Request.UserHostAddress; comment.Description = description; comment.TopicID = topicId; ct.Comments.Add(comment); ct.SaveChanges(); return(View(comment)); } //return RedirectToAction("index", "home"); }