Esempio n. 1
0
        public static List<TweetDTO> GetTweets(int followingId)
        {
            var oldTweet = new List<TweetDTO>();

            try
            {
                using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
                {

                    var Ucontent = (from tweets in context.Tweets
                                    where tweets.UserId == followingId
                                    select tweets).ToList();

                    Ucontent.ForEach(y =>
                    {
                        oldTweet.Add(new TweetDTO()
                        {
                            TweetContent = y.TweetContent
                        });
                    });

                    return oldTweet;

                }
            }
            catch (Exception e)
            {
                Console.Write(e);
            }
            return oldTweet;
        }
        public static IList <USERDataTransferObject.UserDetails> GetFollowers(int ucid)
        {
            var list = new List <USERDataTransferObject.UserDetails>();

            try
            {
                using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
                {
                    var list1 = (from userConnection in context.UserFollowers
                                 where userConnection.UserId == ucid
                                 select userConnection).ToList();
                    list1.ForEach(item =>
                    {
                        list.Add(new USERDataTransferObject.UserDetails()
                        {
                            UserId = item.FollowerId,
                            FName  = item.User.FName,
                            Image  = item.User.Image
                        });
                    });
                }
            }
            catch (Exception)
            {
            }
            return(list);
        }
Esempio n. 3
0
 public static TweetDTO AddTweet(TweetDTO tweetObject)
 {
     TweetDTO newTweet = null;
     try
     {
         using (CMSTweetDBEntities111  context = new CMSTweetDBEntities111())
         {
             Tweet tweet = new Tweet
             {
                 TweetContent = tweetObject.TweetContent,
                 UserId = tweetObject.UserId,
                 Date = tweetObject.Date
             };
             context.Tweets.Add(tweet);
             if (context.SaveChanges() > 0)
             {
                 newTweet = tweetObject;
             }
         }
     }
     catch (Exception e)
     {
         Console.Write(e);
     }
     return newTweet;
 }
Esempio n. 4
0
        public static Login GetUserInfo(Login login)
        {
            Login UserInfo = null;

            try
            {
                using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
                {
                    var user = (from users in context.Users
                                where users.Email == login.Email &&
                                users.Password == login.Password
                                select users).FirstOrDefault();

                    if (user != null)
                    {
                        UserInfo = new Login
                        {
                            Email    = user.Email,
                            Password = user.Password
                        };
                    }
                    else
                    {
                        UserInfo = null;
                    }
                }
            }
            catch (NullReferenceException)
            {
                UserInfo = null;
            }

            return(UserInfo);
        }
        public static USERFollowerDTO AddFollower(USERFollowerDTO userTrack)
        {
            USERFollowerDTO newFollowee = new USERFollowerDTO();

            try
            {
                using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
                {
                    UserFollower followee = new UserFollower
                    {
                        FollowerId = userTrack.FollowerId,
                        UserId     = userTrack.UserId
                    };
                    context.UserFollowers.Add(followee);
                    context.SaveChanges();

                    {
                        newFollowee.UserId     = followee.UserId;
                        newFollowee.FollowerId = followee.FollowerId;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(newFollowee);
        }
Esempio n. 6
0
        public static Register AddUser(Register register)
        {
            Register registerData = null;

            try
            {
                using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
                {
                    User user = new User
                    {
                        Email       = register.Email,
                        Password    = register.Password,
                        FName       = register.FName,
                        LName       = register.LName,
                        Image       = Enumerable.Repeat((byte)0x20, 10).ToArray(),
                        MobNumber   = register.MobNumber,
                        Country     = register.Country,
                        TotalTweets = register.TotalTweets
                    };
                    context.Users.Add(user);
                    context.SaveChanges();
                    registerData = register;
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                throw (e);
            }

            return(register);
        }
Esempio n. 7
0
        public static bool AddToHashTagList(IList <HashTagDTO> listOFHashTags)
        {
            try
            {
                using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
                {
                    foreach (HashTagDTO hashtag in listOFHashTags)
                    {
                        HashTag newHashtag = context.HashTags.FirstOrDefault(a => a.HashTagName == hashtag.HashTagName);

                        context.HashTags.Add(new HashTag
                        {
                            HashTagName = newHashtag.HashTagName,
                            TweetId     = newHashtag.TweetId
                        });
                    }
                    context.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 8
0
 public static int GetUserDetailId(string emailId)
 {
     using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
     {
         var userId = (from e in context.Users select e).Where(x => x.Email.Equals(emailId)).FirstOrDefault().UserId;
         return(userId);
     }
 }
Esempio n. 9
0
 public static IList <string> SearchUser(string searchString)
 {
     using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
     {
         var Fname = (from users in context.Users
                      where users.FName == searchString
                      select users.FName).ToList();
         if (Fname == null)
         {
             return(null);
         }
         else
         {
             return(Fname);
         }
     }
 }
Esempio n. 10
0
 public static bool IfEmailIsUnique(string email)
 {
     using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
     {
         var emailid = (from users in context.Users
                        where users.Email == email
                        select users.Email).FirstOrDefault();
         if (emailid == null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Esempio n. 11
0
 public static TweetDTO EditTweet(TweetDTO editedTweet)
 {
     TweetDTO newtweet = null;
     try
     {
         using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
         {
             var tweet = context.Tweets.Find(editedTweet.TweetId);
             tweet.TweetContent = editedTweet.TweetContent;
             tweet.Date = editedTweet.Date;
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
     }
     return newtweet;
 }
Esempio n. 12
0
        public static int NoOfDisLikes(int tweetid)
        {
            int count = 0;

            try
            {
                using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
                {
                    count = (from responses in context.UserReactions
                             where responses.UserReactionId == tweetid && responses.IsLiked == -1
                             select responses.UserReactionId).ToList().Count;
                }
            }
            catch (Exception)
            {
            }
            return(count);
        }
Esempio n. 13
0
        public static bool DeleteTweet(TweetDTO tweettoDelete)
        {
            try
            {
                using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
                {
                    var tweet = context.Tweets.Find(tweettoDelete.TweetId);
                    context.Tweets.Remove(tweet);
                    context.SaveChanges();
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }

        }
Esempio n. 14
0
 public static bool RemoveFromResponses(UserReactionDTO responseObject)
 {
     try
     {
         using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
         {
             //var react = context.Reacts.Find(reactObject.Id);
             var react = context.UserReactions.FirstOrDefault(l => l.UserReactionId == responseObject.UserReactionId && l.UserId == responseObject.UserId);
             context.UserReactions.Remove(react);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public static bool CheckUserLoggedIn(string emailId, string password)
 {
     using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
     {
         var emailCheck = (from users in context.Users
                           where users.Email == emailId
                           select users.Email).ToList();
         var passwordCheck = (from users in context.Users
                              where users.Password == password
                              select users.Password).ToList();
         if (emailCheck.Count() != 0 && passwordCheck.Count() != 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Esempio n. 16
0
 public static bool AddToLikes(UserReactionDTO responseObject)
 {
     try
     {
         using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
         {
             context.UserReactions.Add(new UserReaction
             {
                 UserReactionId = responseObject.UserReactionId,
                 UserId         = responseObject.UserId,
                 IsLiked        = 1
             });
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public static bool UnFollow(USERFollowerDTO followee)
 {
     try
     {
         using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
         {
             var following = (from followings in context.UserFollowers
                              where followings.FollowerId == followee.FollowerId &&
                              followings.UserId == followee.UserId
                              select followings).FirstOrDefault();
             if (following == null)
             {
                 return(false);
             }
             context.UserFollowers.Remove(following);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 18
0
 public static bool DeleteFromHashTagList(IList <HashTagDTO> listOFHashTags)
 {
     try
     {
         using (CMSTweetDBEntities111 context = new CMSTweetDBEntities111())
         {
             foreach (HashTagDTO hashtag in listOFHashTags)
             {
                 HashTag newHashtag = context.HashTags.FirstOrDefault(a => a.HashTagName == hashtag.HashTagName && a.TweetId == hashtag.TweetId);
                 //if a hashtag already exists
                 if (newHashtag != null)
                 {
                     context.HashTags.Remove(newHashtag);
                 }
                 context.SaveChanges();
             }
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }