public ActionResult QueryPerson(QueryPerson model) { if (!IsLogin) { return(View()); } using (blogEntities en = new blogEntities()) { var result = from user in en.Users where !Passport.AccountID.Equals(user.UserID) && user.UserID.Contains(model.Keyword) || user.FirstName.Contains(model.Keyword) || user.LastName.Equals(model.Keyword) || user.FirstNamePy.Equals(model.Keyword) || user.LastNamePy.Equals(model.Keyword) select new PersonInfo() { Age = 20, DisplayName = user.FirstName + user.LastName, Name = user.UserID, Sex = user.Sex }; model.Persons = result.ToList(); } return(View(model)); }
public int CheckAuthor(string login, string password) { using (var context = new blogEntities()) { return(context.Author.Count(x => x.Login == login && x.Password == password)); } }
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 bool IsAuthorInDB(string login) { using (var context = new blogEntities()) { var tmp = context.Author.SingleOrDefault(x => x.Login == login); if (tmp == null) { return(false); } return(true); } }
public ActionResult GetMessages() { using (blogEntities ct = new blogEntities()) { var lists = ct.Messages.Where(m => m.Owner.Equals(Passport.AccountID)).ToList(); Models.Messages model = new Models.Messages(); model.Store = lists; return(View(model)); } }
public ActionResult LogOn(LogOnModel model, string returnUrl) { try { using (blogEntities ct = new blogEntities()) { var result = ct.Users.Find(model.UserName); if (result != null && result.Passwrod.Equals(model.Password)) { //登录成功。 Passport pp = new Passport(); pp.AccountID = model.UserName; pp.LoginTime = System.DateTime.Now; pp.IP = Request.UserHostAddress; Session.Add("passport", pp); return(RedirectToAction("Index", "Home")); } else { //用户名或者密码错误。 ModelState.AddModelError("", "提供的用户名或密码不正确。"); } } // 如果我们进行到这一步时某个地方出错,则重新显示表单 return(RedirectToAction("LogOn")); } catch (Exception ex) { string path = AppDomain.CurrentDomain.BaseDirectory + "log.txt"; StreamWriter sw = null; if (!System.IO.File.Exists(path)) { sw = System.IO.File.CreateText(path); } else { sw = System.IO.File.AppendText(path); } sw.WriteLine(ex.Message); sw.Close(); } return(View()); }
public int GetAuthorId(string login) { using (var context = new blogEntities()) { var tmp = context.Author.SingleOrDefault(x => x.Login == login); if (tmp != null) { return(tmp.Id); } else { throw new Exception("Invalid user"); } } }
public string GetAuthorName(int authorId) { using (var context = new blogEntities()) { var tmp = context.Author.SingleOrDefault(x => x.Id == authorId); if (tmp != null) { return(tmp.Name); } else { throw new Exception("Invalid user"); } } }
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 Index1(string userid) { ViewBag.Message = "欢迎使用 ASP.NET MVC!"; IndexModel model = new IndexModel(); model.Passport = base.Passport; using (blogEntities en = new blogEntities()) { model.Topics = en.Topics.Where(t => t.Author.Equals(userid)) .OrderByDescending(t => t.CreateTime).ToList(); if (en.Users.Count(u => u.UserID.Equals(userid)) > 0) { model.Author = en.Users.Where(u => u.UserID.Equals(userid)).First(); //model.Firends = model.Author.Friends.Select<Friend,User>() } } return(View(model)); }
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"); }
public ActionResult GetTopicsView(int?id) { if (!IsLogin) { return(View()); } TopicsPartial model = new TopicsPartial(); if (id != null) { model.BeginIndex = id; } using (blogEntities ct = new blogEntities()) { var users = ct.Friends.Where(f => f.Self.Equals(Passport.AccountID)).Select(f => f.FriendID).ToList(); var lists = from t in ct.Topics.Include("Comments") where t.Author.Equals(Passport.AccountID) || users.Contains(t.Author) orderby t.CreateTime descending select t; model.Topics = lists.Skip(model.BeginIndex.Value).Take(model.Count).ToList(); model.BeginIndex += model.Count; if (lists.Count() > model.BeginIndex) { model.HaveNextRecord = true; } else { model.HaveNextRecord = false; } } return(View(model)); }
public ActionResult QueryPerson() { base.ValidationLogin(); QueryPerson model = new QueryPerson(); using (blogEntities en = new blogEntities()) { var result = from user in en.Users select new PersonInfo() { Age = 20, DisplayName = user.FirstName + user.LastName, Name = user.UserID, Sex = user.Sex }; model.LoginUser = base.Passport; model.Persons = result.ToList(); } return(View(model)); }
public UserRepository(blogEntities context) : base(context) { }
public RoleRepository(blogEntities entity) : base(entity) { }
public OurBlogRepository(blogEntities context) { Guard.ArgumentNotNull(context, "context"); this.DbContext = context; this.DbSet = this.DbContext.Set <TEntity>(); }