Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 public PieceContent GetPiece(int id)
 {
     using (var context = new MyContext())
     {
         return context.Pieces.Include("Post").SingleOrDefault(p => p.PieceContentId == id);
     }
 }
Exemplo n.º 3
0
 public User GetUser(string email)
 {
     using (var context = new MyContext())
     {
         return context.Users.FirstOrDefault(p => string.Compare(p.Email, email, true) == 0); 
     }
 }
Exemplo n.º 4
0
 public User GetUser(int id)
 {
     using (var context = new MyContext())
     {
         return context.Users.SingleOrDefault(p => p.UserId == id); 
     }
 }
Exemplo n.º 5
0
 public IEnumerable<Comment> GetComments(int postId)
 {
     using (var context = new MyContext())
     {
         return context.Comments.Where(x => x.Post.PostId == postId).ToList();
     }
 }
Exemplo n.º 6
0
 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); 
     }
 }
Exemplo n.º 7
0
 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();
         }
     }
 }
Exemplo n.º 8
0
 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();
         }
     }
 }
Exemplo n.º 9
0
 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();
         } 
     }
 }
Exemplo n.º 10
0
 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();
     }
 }
Exemplo n.º 11
0
 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();
     }
 }
Exemplo n.º 12
0
 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(); 
     }
 }
Exemplo n.º 13
0
 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();
     }
 }
Exemplo n.º 14
0
 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();
         }
     }
 }
Exemplo n.º 15
0
 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;
     }
 }