/*****************************************************************************/

        public Types.Comment getComment(int commentId)
        {
            using (var ctx = new Models.Model())
            {
                Models.Comment c  = ctx.comments.FirstOrDefault(x => x.commentId == commentId);
                Types.Comment  c1 = new Types.Comment();
                c1.commentId           = c.commentId;
                c1.time                = c.time;
                c1.description         = c.description;
                c1.upvotes             = c.upvotes;
                c1.user                = new Types.User();
                c1.user.userId         = c.user.userId;
                c1.user.username       = c.user.username;
                c1.user.firstName      = c.user.firstName;
                c1.user.lastName       = c.user.lastName;
                c1.user.password       = c.user.password;
                c1.post                = new Types.Post();
                c1.post.postId         = c.post.postId;
                c1.post.headline       = c.post.headline;
                c1.post.time           = c.post.time;
                c1.post.description    = c.post.description;
                c1.post.upvotes        = c.post.upvotes;
                c1.post.user           = new Types.User();
                c1.post.user.userId    = c.post.user.userId;
                c1.post.user.username  = c.post.user.username;
                c1.post.user.firstName = c.post.user.firstName;
                c1.post.user.lastName  = c.post.user.lastName;
                c1.post.user.password  = c.post.user.password;
                c1.replyOfComment      = c.replyOfComment == null ? -1 : c.replyOfComment.commentId;
                return(c1);
            }
        }
 public Types.Comment updateComment(Types.Comment c)
 {
     using (var ctx = new Models.Model())
     {
         Models.Comment c1 = ctx.comments.FirstOrDefault(x => x.commentId == c.commentId);
         c1.time        = c.time;
         c1.description = c.description;
         c1.upvotes     = c.upvotes;
         ctx.SaveChanges();
         return(c);
     }
 }
 public int addComment(Types.Comment c)
 {
     using (var ctx = new Models.Model())
     {
         Models.Comment c1 = new Models.Comment();
         c1.time        = c.time;
         c1.description = c.description;
         c1.upvotes     = c.upvotes;
         if (c.replyOfComment != -1)
         {
             c1.replyOfComment = ctx.comments.FirstOrDefault(x => x.commentId == c.replyOfComment);
         }
         Models.User u = ctx.users.FirstOrDefault(x => x.userId == c.user.userId);
         c1.user = u;
         Models.Post p = ctx.posts.FirstOrDefault(x => x.postId == c.post.postId);
         c1.post = p;
         ctx.comments.Add(c1);
         ctx.SaveChanges();
         return(c1.commentId);
     }
 }
        public List <Types.Comment> filterComments(
            int?userId    = null,
            int?postId    = null,
            DateTime?date = null)
        {
            using (var ctx = new Models.Model())
            {
                var comments = ctx.comments.AsQueryable();
                List <Types.Comment> result = new List <Types.Comment>();
                try
                {
                    if (userId != null)
                    {
                        comments = comments.Where(x => x.user.userId == userId);
                    }
                    if (postId != null)
                    {
                        comments = comments.Where(x => x.post.postId == postId);
                    }
                    if (date != null)
                    {
                        comments = comments.Where(x => (DateTime.Compare((DateTime)date, x.time) <= 0));
                    }
                    comments = comments.OrderBy(c => c.time);

                    foreach (var c in comments.ToList())
                    {
                        Types.Comment c1 = new Types.Comment();
                        c1.commentId           = c.commentId;
                        c1.time                = c.time;
                        c1.description         = c.description;
                        c1.upvotes             = c.upvotes;
                        c1.user                = new Types.User();
                        c1.user.userId         = c.user.userId;
                        c1.user.username       = c.user.username;
                        c1.user.firstName      = c.user.firstName;
                        c1.user.lastName       = c.user.lastName;
                        c1.user.password       = c.user.password;
                        c1.post                = new Types.Post();
                        c1.post.postId         = c.post.postId;
                        c1.post.headline       = c.post.headline;
                        c1.post.time           = c.post.time;
                        c1.post.description    = c.post.description;
                        c1.post.upvotes        = c.post.upvotes;
                        c1.post.user           = new Types.User();
                        c1.post.user.userId    = c.post.user.userId;
                        c1.post.user.username  = c.post.user.username;
                        c1.post.user.firstName = c.post.user.firstName;
                        c1.post.user.lastName  = c.post.user.lastName;
                        c1.post.user.password  = c.post.user.password;
                        c1.replyOfComment      = c.replyOfComment == null ? -1 : c.replyOfComment.commentId;
                        result.Add(c1);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("he");
                    Debug.WriteLine(ex);
                    Debug.WriteLine("he");
                }
                return(result);
            }
        }