Example #1
0
        //User can follow another user
        public bool FollowById(UserFollowerModel followerdata)
        {
            MicoBloggingEntities db = new MicoBloggingEntities();

            try
            {
                var data = from userfollow in db.UserFollowers
                           where userfollow.FollowerId == followerdata.UserId & userfollow.UserId == followerdata.FollowerId
                           select userfollow;
                Console.WriteLine(data);
                Console.WriteLine(data.Count());
                if (data.Count() == 0)
                {
                    UserFollower dbusrfoll = new UserFollower();
                    dbusrfoll.UserId     = followerdata.FollowerId;
                    dbusrfoll.FollowerId = followerdata.UserId;
                    db.UserFollowers.Add(dbusrfoll);
                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Sorry Some Error Occured");
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// User can unfollow another user that he was following
        /// </summary>
        /// <param name="id"></param>
        /// <param name="idToUnfollow"></param>
        public void unFollowById(int id, int idToUnfollow)
        {
            MicoBloggingEntities db = new MicoBloggingEntities();
            //get the of following user by kind of self join
            //if records exit he can unfollow else not

            var followingdata = from ftable in db.UserFollowers
                                where ftable.FollowerId == id & ftable.UserId == idToUnfollow
                                select ftable;

            if (followingdata != null)
            {
                foreach (var item in followingdata)
                {
                    db.UserFollowers.Remove(item);
                }

                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {  // Provide for exceptions.
                    Console.WriteLine(e);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Deletes the tweet
        /// </summary>
        /// <param name="id"></param>
        /// <param name="tweetId"></param>

        public void deleteTweet(int id, int tweetId)
        {
            MicoBloggingEntities db = new MicoBloggingEntities();

            try
            {
                var tweetdata = from tweet in db.Tweets
                                where tweet.UserId == id & tweet.Tid == tweetId
                                select tweet;
                //First delete from the foriegn key tABLE
                var tweetInAnother = from tweetAnother in db.TweetLikeDislikes
                                     where tweetAnother.TweetId == tweetId
                                     select tweetAnother;
                if (tweetdata != null)
                {
                    if (tweetInAnother.Count() == 0)
                    {
                        foreach (var itemdata in tweetdata)
                        {
                            db.Tweets.Remove(itemdata);
                        }
                    }
                    else
                    {
                        foreach (var tweetdataanother in tweetInAnother)
                        {
                            db.TweetLikeDislikes.Remove(tweetdataanother);
                        }
                        db.SaveChanges();
                        foreach (var itemdata in tweetdata)
                        {
                            db.Tweets.Remove(itemdata);
                        }
                    }
                }



                db.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                // Provide for exceptions.
            }
        }
Example #4
0
        /// <summary>
        /// Adds the User to the Database
        /// </summary>
        /// <param name="usermodel"></param>
        /// <returns></returns>
        public bool Signup(UserModel usermodel)
        {
            UserModel userDetails = new UserModel();

            User dbusr = new User();
            MicoBloggingEntities db = new MicoBloggingEntities();

            try
            {
                if (usermodel.Email == null)
                {
                    return(false);
                }
                if (db == null)
                {
                    throw new Exception("The dbContext has not been set");
                }
                var userobj = (from prevuser in db.Users
                               where prevuser.Email == usermodel.Email
                               select prevuser).SingleOrDefault();


                if (userobj != null)
                {
                    return(false);
                }

                else
                {
                    dbusr.Email    = usermodel.Email;
                    dbusr.Password = usermodel.Password;
                    dbusr.FName    = usermodel.FName;
                    dbusr.LName    = usermodel.LName;
                    dbusr.Contact  = usermodel.Contact;
                    dbusr.Country  = usermodel.Country;
                    dbusr.ImageUrl = usermodel.ImageUrl;
                    // Console.WriteLine(dbusr);
                    db.Users.Add(dbusr);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                        return(false);
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Sorry some  error occured");
            }

            return(true);
        }
Example #5
0
        //Update the Tweet Like dislike table when user Clicks the Like Button
        public bool tweetLikeClicked(TweetLikeDislikeModel data)
        {
            MicoBloggingEntities db = new MicoBloggingEntities();
            TweetLikeDislike     dbtweetlikedislike = new TweetLikeDislike();

            try
            {
                //finds the Previous record of that tweet
                var findPrevData = (from tweetLD in db.TweetLikeDislikes
                                    where tweetLD.TweetId == data.TweetId
                                    & tweetLD.LikedDislikedBy == data.LikedDislikedBy
                                    select tweetLD).FirstOrDefault();
                //if there is no Record it will create the tweetrecord
                if (findPrevData != null)
                {
                    Console.WriteLine(findPrevData);
                    findPrevData.LikeDislike = "true";

                    db.SaveChanges();

                    return(true);
                }
                //if record exists the data is updated
                else
                {
                    dbtweetlikedislike.TweetId         = data.TweetId;
                    dbtweetlikedislike.LikedDislikedBy = data.LikedDislikedBy;
                    dbtweetlikedislike.LikeDislike     = data.LikeDislike;

                    db.TweetLikeDislikes.Add(dbtweetlikedislike);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Sorry some Error ocuured" + ex);
                return(false);
            }
        }
Example #6
0
        /// <summary>
        /// adds data if no record exist of that tweet
        /// else updates the like or dislike value
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool tweetDisLikeClicked(TweetLikeDislikeModel data)
        {
            MicoBloggingEntities db = new MicoBloggingEntities();
            TweetLikeDislike     dbtweetlikedislike = new TweetLikeDislike();

            try
            {
                var findPrevData = (from tweetLD in db.TweetLikeDislikes
                                    where tweetLD.TweetId == data.TweetId
                                    & tweetLD.LikedDislikedBy == data.LikedDislikedBy
                                    select tweetLD).FirstOrDefault();
                if (findPrevData != null)
                {
                    Console.WriteLine(findPrevData);
                    findPrevData.LikeDislike = "false";

                    db.SaveChanges();

                    return(true);
                }
                else
                {
                    dbtweetlikedislike.TweetId         = data.TweetId;
                    dbtweetlikedislike.LikedDislikedBy = data.LikedDislikedBy;
                    dbtweetlikedislike.LikeDislike     = data.LikeDislike;
                    db.TweetLikeDislikes.Add(dbtweetlikedislike);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Sorry some Error ocuured" + ex);
                return(false);
            }
        }
Example #7
0
 /// <summary>
 /// Add new Tweet to the Database
 /// </summary>
 /// <param name="tweetmodel"></param>
 /// <returns></returns>
 public bool postTweet(TweetModel tweetmodel)
 {
     try
     {
         dbtweet.Body         = tweetmodel.Body;
         dbtweet.UserId       = Convert.ToInt32(tweetmodel.UserId);
         dbtweet.CreationTime = tweetmodel.CreationTime;
         db.Tweets.Add(dbtweet);
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         Console.WriteLine("Sorry Some Error Occurred");
         return(false);
     }
 }
Example #8
0
        /// <summary>
        /// edits the tweets
        /// </summary>
        /// <param name="id"></param>
        /// <param name="tweetdata"></param>
        /// <returns></returns>
        public bool editTweet(int id, TweetModel tweetdata)
        {
            MicoBloggingEntities db = new MicoBloggingEntities();


            try
            {
                Tweet tweetToEdit = (from tweet in db.Tweets
                                     where tweet.Tid == id & tweet.UserId == tweetdata.UserId
                                     select tweet).FirstOrDefault();
                tweetToEdit.Body = tweetdata.Body;
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }


            return(true);
        }