public Post GetPost(int id) { using (var context = new MyContext()) { return context.Posts.Include("AudioContent").Include("Pieces").Include("Comments.UserPosted").SingleOrDefault(p => p.PostId == id); } }
public PieceContent GetPiece(int id) { using (var context = new MyContext()) { return context.Pieces.Include("Post").SingleOrDefault(p => p.PieceContentId == id); } }
public User GetUser(string email) { using (var context = new MyContext()) { return context.Users.FirstOrDefault(p => string.Compare(p.Email, email, true) == 0); } }
public User GetUser(int id) { using (var context = new MyContext()) { return context.Users.SingleOrDefault(p => p.UserId == id); } }
public IEnumerable<Comment> GetComments(int postId) { using (var context = new MyContext()) { return context.Comments.Where(x => x.Post.PostId == postId).ToList(); } }
public User Login(string email, string password) { using (var context = new MyContext()) { return context.Users.FirstOrDefault(p => string.Compare(p.Email, email, true) == 0 && p.Password == password); } }
public void DeletePost(int id) { using (var context = new MyContext()) { var post = context.Posts.FirstOrDefault(t => t.PostId == id); if (post != null) { context.Posts.Remove(post); context.SaveChanges(); } } }
public void DeleteComment(int commentId) { using (var context = new MyContext()) { var comment = context.Comments.FirstOrDefault(t => t.CommentId == commentId); if (comment != null) { context.Comments.Remove(comment); context.SaveChanges(); } } }
public void DeleteUser(int id) { using (var context = new MyContext()) { var user = context.Users.FirstOrDefault(t => t.UserId == id); if (user != null) { context.Users.Remove(user); context.SaveChanges(); } } }
public void SavePieceContent(PieceContent piece) { using (var context = new MyContext()) { if (piece.PieceContentId == 0) { context.Posts.Attach(piece.Post); context.Pieces.Add(piece); } else { context.Pieces.Attach(piece); context.Entry(piece).State = EntityState.Modified; } context.SaveChanges(); } }
public void SavePost(Post post) { using (var context = new MyContext()) { if (post.PostId == 0) { context.Users.Attach(post.UserPosted); context.Posts.Add(post); } else { context.Posts.Attach(post); context.Entry(post).State = EntityState.Modified; } context.SaveChanges(); } }
public void SaveUser(User user) { using (var context = new MyContext()) { if (user.UserId == 0) { user.RegisterDate = DateTime.Now; context.Users.Add(user); } else { context.Users.Attach(user); context.Entry(user).State = EntityState.Modified; } context.SaveChanges(); } }
public void SaveComment(Comment comment) { using (var context = new MyContext()) { if (comment.CommentId == 0) { context.Users.Attach(comment.UserPosted); context.Posts.Attach(comment.Post); context.Comments.Add(comment); } else { context.Comments.Attach(comment); context.Entry(comment).State = EntityState.Modified; } context.SaveChanges(); } }
public void RemovePieceContent(int pieceId) { using (var context = new MyContext()) { var piece = context.Pieces.FirstOrDefault(t => t.PieceContentId == pieceId); if (piece != null) { context.Pieces.Remove(piece); context.SaveChanges(); } } }
public ActionResult AudioStream(int audioId) { using (var context = new MyContext()) { var audio = context.AudioContents.Find(audioId); if (audio != null) return File(audio.AudioStream, "audio/mpeg"); return null; } }