// used to search people based on the search string passed
        public IList <UserDTO> GetUsers(string search)
        {
            IList <UserDTO> returnedObject;

            try
            {
                using (GlitterDBEntities context = new GlitterDBEntities())
                {
                    var users = context.Users.Where(x => x.Name.Contains(search) ||
                                                    x.Email.Contains(search)).ToList();
                    IList <UserDTO> usersDTO = new List <UserDTO>();

                    foreach (var user in users)
                    {
                        UserDTO userDTO = new UserDTO();
                        userDTO.Name           = user.Name;
                        userDTO.ContactNumber  = user.ContactNumber;
                        userDTO.Country        = user.Country;
                        userDTO.Email          = user.Email;
                        userDTO.ProfileImage   = user.ProfileImage;
                        userDTO.FollowerCount  = user.FollowerCount;
                        userDTO.FollowingCount = user.FollowingCount;
                        userDTO.UserId         = user.UserId;
                        usersDTO.Add(userDTO);
                    }
                    returnedObject = usersDTO;
                }
            }
            catch (Exception)
            {
                returnedObject = null;
            }
            return(returnedObject);
        }
Exemple #2
0
        public List <TweetHashMapper> updateTweetHashMapper(int tweetId)
        {
            //TweetDTO retVal = null;
            List <TweetHashMapper> mapperList = new List <TweetHashMapper>();

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    var tweetHashMappersList = dbContext.TweetHashMappers.Where(s => s.TweetId == tweetId).ToList();
                    mapperList.AddRange(tweetHashMappersList);
                    //tweetHashMappersList.RemoveAll(x => x.TweetId == tweetId);
                    for (int i = 0; i < tweetHashMappersList.Count; i++)
                    {
                        dbContext.TweetHashMappers.Remove(tweetHashMappersList[i]);
                    }
                    dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(mapperList);
        }
Exemple #3
0
        public List <UserDTO> GetAllUsers()
        {
            List <UserDTO> retVal = null;

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    var users = dbContext.Users.ToList();

                    retVal = users != null && users.Count > 0 ? new List <UserDTO>() : null;

                    //users.ForEach(x =>
                    //{
                    //    retVal.Add(new UserDTO()
                    //    {
                    //        EmailId = x.EmailId,
                    //        FirstName = x.FirstName,
                    //        LastName = x.LastName,
                    //        ContactNumber = x.ContactNumber,
                    //        Country = x.Country,
                    //        Password = x.Password
                    //    });
                    //});
                    retVal = this.Mapper.Map <List <UserDTO> >(users);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(retVal);
        }
        public Boolean RegisterUserToDatabase(UserDTO user)
        {
            Boolean result;

            try
            {
                using (GlitterDBEntities context = new GlitterDBEntities())
                {
                    User userDTO = new User
                    {
                        Name           = user.Name,
                        ContactNumber  = user.ContactNumber,
                        ProfileImage   = user.ProfileImage,
                        Email          = user.Email,
                        Country        = user.Country,
                        FollowerCount  = 0,
                        FollowingCount = 0
                    };
                    context.Users.Add(userDTO);
                    if (context.SaveChanges() > 0)
                    {
                        result = false;
                    }
                    result = true;
                }
            }
            catch (Exception)
            {
                result = false;
            }
            return(result);
        }
Exemple #5
0
        public int AddNewTweet(TweetDTO twt)
        {
            int currid;

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    Tweet tweet = new Tweet()
                    {
                        Content      = twt.Content,
                        PostDate     = DateTime.Now,
                        UserId       = twt.UserId, //Alert
                        LikeCount    = 0,
                        DislikeCount = 0,
                        Active       = true,
                        UpdateDate   = DateTime.Now
                    };

                    dbContext.Tweets.Add(tweet);
                    dbContext.SaveChanges();
                    currid = dbContext.Tweets.Max(s => s.TweetId);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(currid);
        }
Exemple #6
0
        public bool updateHashforedit(List <TweetHashMapper> tweetHashMappers, int tweetId)
        {
            //TweetDTO retVal = null;

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    foreach (var x in tweetHashMappers)
                    {
                        var hash = dbContext.Hashes.Where(s => s.HashId == x.HashId).FirstOrDefault();

                        hash.HashCount -= 1;
                        if (hash.HashCount <= 0)
                        {
                            dbContext.Hashes.Remove(hash);
                        }
                    }

                    dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(true);
        }
Exemple #7
0
        public List <UserDTO> GetAllFollowers(int UserId)
        {
            //List<FollowDTO> retVal = null;
            List <UserDTO> retVal = null;

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    //var following = dbContext.Follows.Where(x => x.FollowerId== i && x.Active).ToList();
                    //retVal = following != null && following.Count > 0 ? new List<FollowDTO>() : null;
                    //retVal = this.Mapper.Map<List<FollowDTO>>(following);
                    retVal = dbContext.Database.SqlQuery <UserDTO>("select u.UserId,u.FirstName,u.LastName,u.ImagePath" +
                                                                   " from Users u Join Follow f on u.UserId=f.FollowerId where f.UserID=" + UserId + "AND Active=1").ToList();

                    retVal = this.Mapper.Map <List <UserDTO> >(retVal);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(retVal);
        }
Exemple #8
0
        /// <summary>
        /// Follow User
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="followingId"></param>
        /// <returns></returns>
        public bool FollowUser(int userId, int followingId)
        {
            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    var result = dbContext.Follows.Where(p => p.UserId == followingId && p.FollowerId == userId).FirstOrDefault();
                    if (result == null)
                    {
                        Follow follow = new Follow()
                        {
                            UserId     = followingId,
                            FollowerId = userId,
                            Active     = true
                        };
                        dbContext.Follows.Add(follow);
                        dbContext.SaveChanges();
                    }
                    else
                    {
                        if (result.Active == false)
                        {
                            result.Active = true;
                            dbContext.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(true);
        }
        public UserDTO GetUser()
        {
            UserDTO returnedObject = null;

            try
            {
                using (GlitterDBEntities context = new GlitterDBEntities())
                {
                    var user = (from u in context.Users
                                select u).First();

                    UserDTO userDTO = new UserDTO
                    {
                        Name           = user.Name,
                        ContactNumber  = user.ContactNumber,
                        ProfileImage   = user.ProfileImage,
                        Email          = user.Email,
                        Country        = user.Country,
                        FollowerCount  = user.FollowerCount,
                        FollowingCount = user.FollowingCount
                    };
                    returnedObject = userDTO;
                }
            }
            catch (Exception)
            {
                returnedObject = null;
            }
            return(returnedObject);
        }
        // used to retrieve the follwers of the logged in user
        public IList <UserDTO> GetUserFollowers(string email)
        {
            IList <UserDTO> returnedObject;

            try
            {
                using (GlitterDBEntities context = new GlitterDBEntities())
                {
                    int userId = context.Users.Where(x => x.Email == email)
                                 .Select(x => x.UserId).FirstOrDefault();
                    var users = context.Follows.Where(x => x.FollowingId == userId)
                                .Include(x => x.User).Select(y => y.User).ToList();
                    IList <UserDTO> usersDTO = new List <UserDTO>();
                    foreach (var user in users)
                    {
                        UserDTO userDTO = new UserDTO();
                        userDTO.UserId         = user.UserId;
                        userDTO.Name           = user.Name;
                        userDTO.ContactNumber  = user.ContactNumber;
                        userDTO.Country        = user.Country;
                        userDTO.Email          = user.Email;
                        userDTO.ProfileImage   = user.ProfileImage;
                        userDTO.FollowerCount  = user.FollowerCount;
                        userDTO.FollowingCount = user.FollowingCount;
                        usersDTO.Add(userDTO);
                    }
                    returnedObject = usersDTO;
                }
            }
            catch (Exception)
            {
                returnedObject = null;
            }
            return(returnedObject);
        }
Exemple #11
0
 public string gettweet(int tweetId)
 {
     using (GlitterDBEntities dbContext = new GlitterDBEntities())
     {
         Tweet temp = dbContext.Tweets.Where((s) => s.TweetId == tweetId).FirstOrDefault();
         return(temp.Content);
     }
 }
Exemple #12
0
        /// <summary>
        /// Getting tweet of the
        /// user and it's followers
        /// </summary>
        /// <returns></returns>

        public List <TweetDTO> GetAllTweets(int userId)
        {
            List <TweetDTO> retVal = new List <TweetDTO>();

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    // var followingUsersId = dbContext.Follows.Where(x => x.UserId == userId && x.Active == true).Select(x => x.FollowerId).ToList();
                    var followingUsersId = dbContext.Follows.Where(x => x.FollowerId == userId && x.Active == true).Select(x => x.UserId).ToList();

                    followingUsersId.Add(userId);

                    // var userTweetList = dbContext.Tweets.Where(x => followingUsersId.Contains(userId) && x.Active == true).ToList();

                    var userTweetList = dbContext.Tweets.Where(x => followingUsersId.Contains(x.UserId) && x.Active == true).ToList();

                    //var tweetsLikedDisliked = dbContext.LikeDislikeMappers.Where(x => x.UserId == userId).ToDictionary(x => x.TweetId, y => y.Like);
                    var tweetsLikedDisliked           = dbContext.LikeDislikeMappers.Where(x => x.UserId == userId).ToList();          //.ToDictionary(x => x.TweetId, y => y.Like);
                    Dictionary <int, bool> tweetLiked = new Dictionary <int, bool>();
                    for (int i = 0; i < tweetsLikedDisliked.Count(); i++)
                    {
                        tweetLiked[tweetsLikedDisliked[i].TweetId] = true;
                    }
                    retVal = this.Mapper.Map <List <TweetDTO> >(userTweetList.OrderByDescending(x => x.UpdateDate).ToList());

                    retVal.ForEach(x =>
                    {
                        try
                        {
                            if (tweetLiked[x.TweetId] == true)
                            {
                                x.IsTweetLikedByUser    = true;
                                x.IsTweetDislikedByUser = false;
                            }
                            else
                            {
                                x.IsTweetLikedByUser    = false;
                                x.IsTweetDislikedByUser = true;
                            }
                        }
                        catch
                        {
                            x.IsTweetLikedByUser    = false;
                            x.IsTweetDislikedByUser = false;
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(retVal);
        }
Exemple #13
0
 public int FollowingsCount(int userId)
 {
     //List<UserDTO> retVal = null;
     using (GlitterDBEntities dbContext = new GlitterDBEntities())
     {
         return(dbContext.Follows.Where(x => x.FollowerId == userId && x.Active).ToList().Count());
         //retVal = follow != null && follow.Count > 0 ? new List<UserDTO>() : null;
     }
     //return (retVal.Count);
 }
Exemple #14
0
        public void addhash(List <string> hashes, int cid)
        {
            for (int i = 0; i < hashes.Count; i++)
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    String str = hashes[i];

                    var hsh   = dbContext.Hashes.Where(s => s.Content == str).FirstOrDefault();
                    var maxid = 0;
                    if (hsh == null)
                    {
                        Hash hash = new Hash()
                        {
                            Content = hashes[i],
                            //PostDate = DateTime.Now,
                            HashCount   = 1,                          //Alert
                            SearchCount = 0
                        };
                        dbContext.Hashes.Add(hash);
                        dbContext.SaveChanges();
                        //var maxid=dbContext.Hashes.SqlQuery<Int32>("Select Max(HashId) From Hash");
                        maxid = dbContext.Hashes.Max(s => s.HashId);
                        var             x  = dbContext.Hashes.Where(s => s.Content == hashes[i]);
                        TweetHashMapper mp = new TweetHashMapper()
                        {
                            TweetId = cid,
                            HashId  = (int)maxid
                        };
                        dbContext.TweetHashMappers.Add(mp);
                    }
                    else
                    {
                        String st   = hashes[i];
                        Hash   hash = dbContext.Hashes.Where(s => s.Content == st).FirstOrDefault();
                        hash.HashCount += 1;
                        TweetHashMapper mp = new TweetHashMapper()
                        {
                            TweetId = cid,
                            HashId  = hash.HashId
                        };
                        dbContext.TweetHashMappers.Add(mp);
                        //dbContext.Database.SqlQuery<Hash>("Update hash set hashcount=hashcount+1 where Content=" + hashes[i]);
                    }
                    //dbContext.Tweets.Add(tweet);
                    dbContext.SaveChanges();
                }
            }
            return;
        }
Exemple #15
0
        public List <TweetDTO> GetAllSearchedTweets(string searchHash)
        {
            List <TweetDTO> retVal = null;

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    var hashBySearchId = (from h in dbContext.Hashes
                                          where h.Content.ToLower().Contains(searchHash.ToLower())
                                          select h.HashId).ToList();

                    //var tweets = dbContext.Database.SqlQuery<TweetDTO>("select t.Content, t.PostDate, t.UserId, t.LikeCount, t.DislikeCount from TweetHashMapper m join Tweets t on m.TweetId=t.TweetId where m.HashId=" + hashBySearchId).ToList();

                    var tweets = (from t in dbContext.Tweets
                                  join mp in dbContext.TweetHashMappers on t.TweetId equals mp.TweetId
                                  join h in dbContext.Hashes on mp.HashId equals h.HashId
                                  where h.Content.ToLower().Contains(searchHash.ToLower()) && t.Active == true
                                  select t).ToList();

                    foreach (var hash in hashBySearchId)
                    {
                        var hashObj = dbContext.Hashes.Where(h => h.HashId == hash).FirstOrDefault();
                        hashObj.SearchCount += 1;
                    }
                    dbContext.SaveChanges();

                    retVal = this.Mapper.Map <List <TweetDTO> >(tweets);
                    //foreach (var item in tweets)
                    //{
                    //    TweetDTO twt = new TweetDTO
                    //    {
                    //        Content = item.Content,
                    //        PostDate = item.PostDate,
                    //        UserId = item.UserId,
                    //        LikeCount = (int)item.LikeCount,
                    //        DislikeCount = (int)item.DislikeCount,
                    //    };
                    //    retVal.Add(twt);
                    //}
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(retVal);
        }
        // get all tweets
        public IList <TweetDTO> GetUserTweets(string email)
        {
            IList <TweetDTO> returnedObject = null;

            try
            {
                using (GlitterDBEntities context = new GlitterDBEntities())
                {
                    int id = context.Users.Where(x => x.Email == email).FirstOrDefault().UserId;
                    IList <TweetDTO> tweets = new List <TweetDTO>();
                    var followersIds        = context.Follows.Where(x => x.FollowerId == id)
                                              .Select(x => x.FollowingId).ToList();
                    followersIds.Add(id);
                    foreach (var i in followersIds)
                    {
                        var result = context.Tweets.Where(x => x.UserId == i).ToList();
                        foreach (var item in result)
                        {
                            var likeFlag = context.Reactions
                                           .Where(x => x.TweetId == item.TweetId && x.UserId == id)
                                           .Select(x => x.LikeFlag).FirstOrDefault();
                            TweetDTO tweet = new TweetDTO();
                            tweet.TweetId      = item.TweetId;
                            tweet.TweetContent = item.TweetContent;
                            tweet.UserId       = item.UserId;
                            tweet.Time         = item.Time;
                            if (i == id)
                            {
                                tweet.Email = email;
                            }
                            else
                            {
                                tweet.Email = "*****@*****.**";
                            }
                            tweet.LikeFlag = likeFlag;
                            tweets.Add(tweet);
                        }
                    }
                    IList <TweetDTO> sortedTweets = tweets.OrderByDescending(o => o.Time).ToList();
                    returnedObject = sortedTweets;
                }
            }
            catch (Exception)
            {
            }
            return(returnedObject);
        }
Exemple #17
0
        public void AddNewTweetHash(List <string> hashes, int tweetId)
        {
            for (int i = 0; i < hashes.Count; i++)
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    String str = hashes[i];

                    var hsh   = dbContext.Hashes.Where(s => s.Content == str).FirstOrDefault();
                    var maxid = 0;
                    if (hsh == null)
                    {
                        Hash hash = new Hash()
                        {
                            Content     = hashes[i],
                            HashCount   = 1,//Alert
                            SearchCount = 0
                        };
                        dbContext.Hashes.Add(hash);
                        dbContext.SaveChanges();//
                        maxid = dbContext.Hashes.Max(s => s.HashId);
                        var             x       = dbContext.Hashes.Where(s => s.Content == hashes[i]);
                        TweetHashMapper mpEntry = new TweetHashMapper()
                        {
                            TweetId = tweetId,
                            HashId  = (int)maxid
                        };
                        dbContext.TweetHashMappers.Add(mpEntry);
                        dbContext.SaveChanges();//
                    }
                    else
                    {
                        String st   = hashes[i];
                        Hash   hash = dbContext.Hashes.Where(s => s.Content == st).FirstOrDefault();
                        hash.HashCount += 1;
                        TweetHashMapper mp = new TweetHashMapper()
                        {
                            TweetId = tweetId,
                            HashId  = hash.HashId
                        };
                        dbContext.TweetHashMappers.Add(mp);
                    }
                    dbContext.SaveChanges();//
                }
            }
            return;
        }
Exemple #18
0
        public string GetMostTrendingHashtag()
        {
            string hashContent = null;

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    hashContent = dbContext.Database.SqlQuery <string>("select Content from Hash h1 join (select top(1) MAX(HashCount+SearchCount) as maxcount, HashId from Hash group by HashId order by maxcount desc) as h2 on h1.hashid = h2.hashid").FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(hashContent);
        }
Exemple #19
0
        public void RegisterUser(UserDTO newUser)
        {
            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    //dbContext.Users.Add(this.Mapper.Map<User>(newUser));


                    dbContext.Users.Add(this.Mapper.Map <User>(newUser));
                    dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #20
0
        public string GetMostTweetingUser()
        {
            string retVal;

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    var mostTweetingUser = dbContext.Database.SqlQuery <string>("select FirstName+LastName from users u join (select top(1) count(tweetId) as cnt, userId from Tweets group by userId order by cnt desc) as x on x.userId = u.userId ").FirstOrDefault();
                    retVal = mostTweetingUser.ToString();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(retVal);
        }
        // get user's follwings count
        public int?GetUserFollowingsCount(string email)
        {
            int?returnedObject = null;

            try
            {
                using (GlitterDBEntities context = new GlitterDBEntities())
                {
                    int?result = context.Users.Where(x => x.Email == email).FirstOrDefault().FollowingCount;
                    returnedObject = result;
                }
            }
            catch (Exception)
            {
                returnedObject = null;
            }
            return(returnedObject);
        }
Exemple #22
0
        public List <SearchUserDTO> GetAllSearchUsers(string searchHash)
        {
            List <SearchUserDTO> retVal = new List <SearchUserDTO>();

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    var users = dbContext.Users.Where(c => c.FirstName.Contains(searchHash) || c.LastName.Contains(searchHash) || c.EmailId.Contains(searchHash)).ToList();
                    //retVal = users != null && users.Count > 0 ? new List<UserDTO>() : null;

                    int           curUserId           = 1;
                    SearchUserDTO searchHashPeopleDTO = null;
                    foreach (var user in users)
                    {
                        var alreadyFollowing = dbContext.Follows.Where(f => f.FollowerId == curUserId && f.UserId == user.UserId && f.Active == true).FirstOrDefault();
                        if (alreadyFollowing != null)
                        {
                            searchHashPeopleDTO = new SearchUserDTO
                            {
                                UserDTO          = this.Mapper.Map <UserDTO>(user),
                                AlreadyFollowing = true
                            };
                        }
                        else
                        {
                            searchHashPeopleDTO = new SearchUserDTO
                            {
                                UserDTO          = this.Mapper.Map <UserDTO>(user),
                                AlreadyFollowing = false
                            };
                        }
                        retVal.Add(searchHashPeopleDTO);
                    }

                    //retVal = this.Mapper.Map<List<UserDTO>>(users);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(retVal);
        }
Exemple #23
0
        public UserDTO Login(string email, string password)
        {
            UserDTO retVal = null;

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    var user = dbContext.Users.Where(u => u.EmailId == email && u.Password == password).FirstOrDefault();

                    retVal = this.Mapper.Map <UserDTO>(user);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(retVal);
        }
Exemple #24
0
        public bool ValidateUser(string emailId, string password)
        {
            bool isValid = false;

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    var user = dbContext.Users.Single(x => x.EmailId.ToLower().Equals(emailId.ToLower()) && x.Password.Equals(password));
                    isValid = user != null;
                }
            }
            catch
            {
                isValid = false;
            }

            return(isValid);
        }
Exemple #25
0
        /// <summary>
        /// Return Tweet that's have max likes
        /// </summary>
        /// <returns></returns>
        public TweetDTO GetMostLikedTweet()
        {
            TweetDTO resTweet;

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    int maxLikeCount = (int)dbContext.Tweets.Max(p => p.LikeCount);
                    var tweet        = dbContext.Tweets.First(x => x.LikeCount == maxLikeCount);
                    resTweet = this.Mapper.Map <TweetDTO>(tweet);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(resTweet);
        }
Exemple #26
0
 public bool updateTweet(int tweetId, string Content)
 {
     //TweetDTO retVal = null;
     try
     {
         using (GlitterDBEntities dbContext = new GlitterDBEntities())
         {
             var tweet = dbContext.Tweets.Where(s => s.TweetId == tweetId).FirstOrDefault();
             tweet.Content    = Content;
             tweet.UpdateDate = DateTime.Now;
             dbContext.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(true);
 }
Exemple #27
0
        public UserDTO GetUserByEmailId(string email)
        {
            UserDTO retVal = new UserDTO();

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    var user = dbContext.Users.Where(x => x.EmailId == email).FirstOrDefault();
                    //retVal = users != null && users.Count > 0 ? new List<UserDTO>() : null;

                    retVal = this.Mapper.Map <UserDTO>(user);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(retVal);
        }
Exemple #28
0
        public bool deleteTweet(int tweetId)
        {
            //TweetDTO retVal = null;

            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    var tweet = dbContext.Tweets.Where(s => s.TweetId == tweetId).FirstOrDefault();
                    tweet.Active = false;
                    dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(true);
        }
Exemple #29
0
        /// <summary>
        /// Unfollow User
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="followingId"></param>
        /// <returns></returns>
        public bool UnfollowUser(int userId, int followingId)
        {
            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    var follow = dbContext.Follows.Where(p => p.UserId == followingId && p.FollowerId == userId).FirstOrDefault();
                    if (follow != null)
                    {
                        follow.Active = false;
                        dbContext.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(true);
        }
Exemple #30
0
        public bool DislikeTweet(int userId, int tweetId)
        {
            try
            {
                using (GlitterDBEntities dbContext = new GlitterDBEntities())
                {
                    var likeDislikeMapper = dbContext.LikeDislikeMappers.Where(y => y.UserId == userId && y.TweetId == tweetId).FirstOrDefault();
                    var tweet             = dbContext.Tweets.Where(y => y.TweetId == tweetId).FirstOrDefault();

                    if (likeDislikeMapper == null)
                    {
                        LikeDislikeMapper likeDislikeMapperObj = new LikeDislikeMapper()
                        {
                            UserId  = userId,
                            TweetId = tweetId,
                            Like    = false
                        };

                        dbContext.LikeDislikeMappers.Add(likeDislikeMapperObj);
                        tweet.DislikeCount += 1;
                        dbContext.SaveChanges();
                    }
                    else
                    {
                        if (likeDislikeMapper.Like == true)
                        {
                            likeDislikeMapper.Like = false;
                            tweet.LikeCount       -= 1;
                            tweet.DislikeCount    += 1;
                            dbContext.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(true);
        }