Example #1
0
        public void deleteRelationshipByID(string idRela)
        {
            var deleteRela = dbContext.Relationships.SingleOrDefault(x => x.id == idRela);

            dbContext.Relationships.Remove(deleteRela);
            dbContext.SaveChanges();
        }
Example #2
0
        public bool toggleLikeAPost(string userId, string postId)
        {
            try
            {
                bool isLiked = isLikeByUser(userId, postId);
                if (isLiked)
                {
                    dbContext.Favorites.RemoveRange(dbContext.Favorites.Where(x => x.uId == userId && x.pId == postId));
                }
                else
                {
                    Favorite newLike = new Favorite()
                    {
                        id = DateTimeUtils.getKeyTimeStamp(), uId = userId, pId = postId
                    };
                    dbContext.Favorites.Add(newLike);
                }

                dbContext.SaveChanges();

                return(!isLiked);
            }catch (Exception e)
            {
                return(false);
            }
        }
Example #3
0
        // return user id
        public string insert(User user)
        {
            dbContext.Users.Add(user);

            dbContext.SaveChanges();

            return(user.id);
        }
Example #4
0
 public bool insertComment(Comment comment)
 {
     try
     {
         dbContext.Comments.Add(comment);
         dbContext.SaveChanges();
         return(true);
     }catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
Example #5
0
 public bool insert(Post post)
 {
     try
     {
         dbContext.Posts.Add(post);
         dbContext.SaveChanges();
         return(true);
     }catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }