public void DeleteMessage(long? messageId,long? belongId,long? childrenBelongId,string type) { using (UtopiaEntities db = new UtopiaEntities()) { if (messageId.HasValue) { Uto_Message message = db.Uto_Message.First(n=>n.MessageId==messageId.Value&&n.Type==type); db.Uto_Message.DeleteObject(message); } if (belongId.HasValue) { IEnumerable<Uto_Message> messages = db.Uto_Message.Where(n => n.BelongId == belongId.Value && n.Type == type); foreach (var message in messages) { db.Uto_Message.DeleteObject(message); } } if (childrenBelongId.HasValue) { Uto_Message message = db.Uto_Message.First(n => n.ChildrenBelongId == childrenBelongId.Value && n.Type == type); db.Uto_Message.DeleteObject(message); } db.SaveChanges(); } }
public void AddComment(Uto_Comment comment) { using (UtopiaEntities db = new UtopiaEntities()) { db.Uto_Comment.AddObject(comment); db.SaveChanges(); } }
public void DeleteComment(long commentId) { using (UtopiaEntities db = new UtopiaEntities()) { Uto_Comment comment = db.Uto_Comment.First(n => n.CommentId == commentId); db.Uto_Comment.DeleteObject(comment); db.SaveChanges(); } }
public void AddAttachment(Uto_Attachment attachment) { using (UtopiaEntities db = new UtopiaEntities()) { attachment.DateCreated = DateTime.Now; db.Uto_Attachment.AddObject(attachment); db.SaveChanges(); } }
public int DeleteMicroBlog(long microblogId) { using (UtopiaEntities db = new UtopiaEntities()) { Uto_Microblog microblog = db.Uto_Microblog.Single(n => n.MicroblogId == microblogId); if (UserContext.CurrentUser.UserId == microblog.UserId && microblog != null) { db.Uto_Microblog.DeleteObject(microblog); //删除旗下的图片附件记录及附件本身 IEnumerable<Uto_Attachment> attachments = db.Uto_Attachment.Where(n => n.BelongId == microblogId); foreach (var attachment in attachments) { db.Uto_Attachment.DeleteObject(attachment); string path = HttpContext.Current.Server.MapPath(attachment.Url.Replace("../../", "~/")); File.Delete(path); } //删除旗下所有微博回复 IEnumerable<Uto_Comment> comments = db.Uto_Comment.Where(n => n.BelongId == microblogId && n.Type == "microblogComment"); foreach (var comment in comments) { db.Uto_Comment.DeleteObject(comment); } //删除旗下所有微博消息(@用户、回复) IEnumerable<Uto_Message> messages = db.Uto_Message.Where(n => n.BelongId == microblogId && (n.Type == "microblogAtUser" || n.Type == "microblogComment")); foreach (var message in messages) { db.Uto_Message.DeleteObject(message); } db.SaveChanges(); return 1; } else { return 0; } } }
/// <summary> /// 更新用户 /// </summary> /// <param name="user"></param> /// <returns></returns> public void UpdateUser(Uto_User user) { using (UtopiaEntities db = new UtopiaEntities()) { Uto_User userDb = db.Uto_User.Single(n => n.UserId == user.UserId); userDb.Username = user.Username; userDb.Password = user.Password; userDb.Sex = user.Sex; userDb.IsActivity = user.IsActivity; db.SaveChanges(); } }
public void UpdateMicroBlog(Uto_Microblog microblog) { using (UtopiaEntities db = new UtopiaEntities()) { Uto_Microblog microblogDb = db.Uto_Microblog.Single(n => n.MicroblogId == microblog.MicroblogId); microblogDb.AttachmentId = microblog.AttachmentId; microblogDb.Body = microblog.Body; microblogDb.DateCreated = microblog.DateCreated; microblogDb.RepeatId = microblog.RepeatId; microblogDb.RepeatContent = microblog.RepeatContent; microblogDb.UserId = microblog.UserId; microblogDb.CommentCount = microblog.CommentCount; db.SaveChanges(); } }
public void UpdateAttachment(Uto_Attachment attachment) { using (UtopiaEntities db = new UtopiaEntities()) { Uto_Attachment attachmentDb = db.Uto_Attachment.Single(n => n.AttachmentId == attachment.AttachmentId); attachmentDb.BelongId = attachment.BelongId; attachmentDb.DateCreated = DateTime.Now; attachmentDb.Url = attachment.Url; attachmentDb.UserId = attachment.UserId; attachmentDb.Type = attachment.Type; attachmentDb.Width = attachment.Width; attachmentDb.Height = attachment.Height; db.SaveChanges(); } }
public void SendMessage(Uto_Message message) { using (UtopiaEntities db = new UtopiaEntities()) { db.Uto_Message.AddObject(message); db.SaveChanges(); } }
/// <summary> /// 注册用户 /// </summary> /// <param name="user"></param> public void RegisterUser(Uto_User user) { using (UtopiaEntities db = new UtopiaEntities()) { db.Uto_User.AddObject(user); db.SaveChanges(); } }
public void PublishMicroBlog(Uto_Microblog microblog) { using (UtopiaEntities db = new UtopiaEntities()) { db.Uto_Microblog.AddObject(microblog); db.SaveChanges(); } }