public void Create(Comments coment)
 {
     if (coment.Id == 0)
     {
         coment.CreateTime = DateTime.Now;
         data.Comments.Add(coment);
     }
     data.SaveChanges();
 }
 public bool Create(Users user)
 {
     if (user.Id == 0)
     {
         _blogDb.Users.Add(user);
     }
     _blogDb.SaveChanges();
     return(false);
 }
        public bool Create(Post post)
        {
            if (post.Id != 0)
            {
                return(false);
            }

            post.CreateTime = DateTime.Now;
            data.Posts.Add(post);
            data.SaveChanges();
            return(true);
        }
        public void AddOrRemove(int idPost, int idUser)
        {
            var likeofUser = (from like in data.Likes where like.IdPost == idPost where like.IdUser == idUser select like).ToList();

            if (!likeofUser.Any())
            {
                var likes = new Likes()
                {
                    IdPost = idPost,
                    IdUser = idUser
                };
                data.Likes.Add(likes);
            }
            else
            {
                var likeForDelete = data.Likes.FirstOrDefault(p => p.IdPost == idPost && p.IdUser == idUser);
                data.Likes.Remove(likeForDelete);
            }
            data.SaveChanges();
        }