public ActionResult ReTweet(int id)
        {
            var user = SessionSet <User> .Get("Login").ID;

            Tweet tweet  = _br.Query <Tweet>().Where(k => k.ID == id).FirstOrDefault();
            var   rtList = _db.Retweets.ToList();
            var   result = _br.Query <Retweet>().Where(k => k.TweetID == id && k.UserID == user).Any();

            if (!result)
            {
                Retweet rt = new Retweet()
                {
                    UserID      = user,
                    TweetID     = id,
                    CreatedDate = DateTime.Now
                };
                _db.Retweets.Add(rt);
                _db.SaveChanges();
            }
            else
            {
                var retwDel = rtList.Where(k => k.TweetID == id && k.UserID == user).FirstOrDefault();
                _db.Retweets.Remove(retwDel);
                _db.SaveChanges();
            }



            return(RedirectToAction("Home", "Home"));
        }
Exemple #2
0
        public ActionResult Create([Bind(Include = "Id,Name")] Tag tag)
        {
            if (ModelState.IsValid)
            {
                db.Tags.Add(tag);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tag));
        }
Exemple #3
0
        public ActionResult Create([Bind(Include = "Id,Message,UserId,CreatedOn")] Tweet tweet)
        {
            if (ModelState.IsValid)
            {
                db.Tweets.Add(tweet);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.Users, "Id", "Email", tweet.UserId);
            return(View(tweet));
        }
Exemple #4
0
        public static void LoadNews(string filename)
        {

            using (TwitterDbContext db = new TwitterDbContext())
            {
                long? minId = (from t in db.Tweets where t.ProfileId == -1 select (long?)t.Id).Min();

                if (!minId.HasValue)
                    minId = 0;

                using (StreamReader sr = new StreamReader(filename))
                {
                    while (!sr.EndOfStream)
                    {
                        string title = sr.ReadLine();
                        string[] tokens = title.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                        if (tokens.Length != 3)
                            continue;

                        TwitterTweet tweet = new TwitterTweet { Id = (--minId).Value, ProfileId = -2, CreatedBy = tokens[0], CreatedAt = DateTime.Parse(tokens[1]), Text = tokens[2] };
                        db.Entry<TwitterTweet>(tweet).State = System.Data.Entity.EntityState.Added;
                    }


                }

                db.SaveChanges();
            }


        }
Exemple #5
0
        public bool RegisterUser(Person person)
        {
            using (TwitterDbContext dbContext = new TwitterDbContext())
            {
                try
                {
                    dbContext.person.Add(person);
                    dbContext.SaveChanges();
                    return(true);
                }
                catch (DbEntityValidationException ex)
                {
                    // Retrieve the error messages as a list of strings.
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
            }
        }
        public IActionResult Tweet(string content)
        {
            Tweet tweet = new Tweet();

            tweet.Content   = content;
            tweet.TimeStamp = DateTime.Now;

            IEnumerable <User> userList = _db.User;

            string loggedUser = getUserCookie();

            foreach (User us in userList)
            {
                if (us.Username == loggedUser)
                {
                    tweet.UserId   = us.Id;
                    tweet.Username = us.Username;
                }
            }

            _db.Tweet.Add(tweet);

            if (!ModelState.IsValid)
            {
                TempData["TweetMessage"] = "You tweet could not be added.";
            }

            _db.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Exemple #7
0
        private void SeedTags(TwitterDbContext context)
        {
            if (!context.Tags.Any())
            {
                context.Tags.Add(new Tag()
                {
                    Name = "code"
                });

                context.Tags.Add(new Tag()
                {
                    Name = "programming"
                });

                context.Tags.Add(new Tag()
                {
                    Name = "fun"
                });

                context.Tags.Add(new Tag()
                {
                    Name = "helloworld"
                });

                context.SaveChanges();
            }
        }
Exemple #8
0
        public IActionResult SubmitChange(string oldPass, string Password1, string Password2)
        {
            string userCookie = getUserCookie();

            if (userCookie == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            string correctPass = "";

            User user = _db.User.First(x => x.Username == userCookie);

            correctPass = user.Password;


            if (correctPass != oldPass)
            {
                ViewBag.cssClass = "";
                ViewBag.msg      = "Old password isn't correct.";
                return(RedirectToAction("ChangePass", "Profile"));
            }

            if (Password1 == Password2)
            {
                user.Password = Password1;
                _db.SaveChanges();
                return(RedirectToAction("Index", "Profile"));
            }

            ViewBag.cssClass = "";
            ViewBag.msg      = "New passwords don't match.";
            return(RedirectToAction("ChangePass", "Profile"));
        }
        public override void Download(string user)
        {
            // get user profiles

            var api_path = "https://api.twitter.com/1.1/users/show.json?screen_name={0}&include_entities={1}";

            using (TwitterDbContext db = new TwitterDbContext())
            {


                string query = string.Format(api_path, user, true);
                var jsonObject = TwitterAccessor.GetQueryableJsonObjectFromGETQuery(query);
                var twitterUser = db.Users.Where(tu => tu.ScreenName.Equals(user)).SingleOrDefault();

                if (twitterUser == null)
                {
                    twitterUser = new TwitterProfile();
                    db.Users.Add(twitterUser);
                }

                twitterUser.Id = (long)jsonObject["id"];
                twitterUser.Name = (string)jsonObject["name"];
                twitterUser.ScreenName = (string)jsonObject["screen_name"];
                twitterUser.CreatedAt = DateTime.ParseExact((string)jsonObject["created_at"], "ddd MMM dd HH:mm:ss zzzz yyyy", CultureInfo.InvariantCulture);
                twitterUser.StatusesCount = (long)jsonObject["statuses_count"];
                twitterUser.FavouritesCount = (long)jsonObject["favourites_count"];
                twitterUser.FollowersCount = (long)jsonObject["followers_count"];
                twitterUser.FriendsCount = (long)jsonObject["friends_count"];
                twitterUser.ListedCount = (long)jsonObject["listed_count"];
                //twitterUser.Json = jsonObject.ToString();


                db.SaveChanges();
            }
        }
        public IActionResult Register(UserViewModel usrvm)
        {
            if (ModelState.IsValid)
            {
                if (context.Users.Any(x => x.Username == usrvm.Username && x.Password == usrvm.Password || x.Email == usrvm.Email))  // Any istenen kayıt varsa true yoksa false döndürür
                {
                    return(Json(new { message = "Bu kullanıcı zaten kayıtlı" }));
                }
                else
                {
                    string uniqueFileName = "default_profile.png";
                    User   usr            = new User
                    {
                        Username     = usrvm.Username,
                        Name         = usrvm.Name,
                        Password     = usrvm.Password,
                        Phone        = usrvm.Phone,
                        Email        = usrvm.Email,
                        ProfileImage = uniqueFileName,
                    };


                    context.Add(usr);
                    context.SaveChanges();
                    return(Json(new { message = "Kayıt başarılı" }));
                }
            }
            else
            {
                ModelState.AddModelError("", "Hatalı giriş");
                return(Json(new { message = "Verilerde hata var." }));
            }
        }
 public void Add(List <Status> results)
 {
     using (TwitterDbContext db = new TwitterDbContext())
     {
         db.t_TwitterResults.AddRange(results);
         db.SaveChanges();
     }
 }
Exemple #12
0
        public ActionResult Follow()
        {
            FriendShip friend   = new FriendShip();
            var        FriendId = RouteData.Values["id"];
            var        user     = SessionSet <User> .Get("Login");

            friend.UserID   = user.ID;
            friend.FriendID = Convert.ToInt32(FriendId);

            var result = _br.Query <FriendShip>().Where(k => (k.UserID.Equals(friend.UserID)) && (k.FriendID.Equals(friend.FriendID))).FirstOrDefault();

            if (result == null)
            {
                _db.FriendShips.Add(friend);
                _db.SaveChanges();
            }
            return(RedirectToAction("Home", "Home"));
        }
 public ActionResult SignUp(Person model)
 {
     using (var context = new TwitterDbContext())
     {
         context.Person.Add(model);
         context.SaveChanges();
     }
     return(RedirectToAction("login"));
 }
Exemple #14
0
        public ActionResult EditTweet(int id, string userId, TWEET tweet)
        {
            var p = db.Person.FirstOrDefault(t => t.user_id == userId);

            var tw = db.TWEETs.FirstOrDefault(a => a.tweet_id == id);

            tw.message = tweet.message;
            db.SaveChanges();

            return(RedirectToAction("Index", "Home", p));
        }
Exemple #15
0
        public IActionResult Follow(User user)
        {
            Follower follower = new Follower();

            follower.UserId   = (int)HttpContext.Session.GetInt32("UserId");
            follower.FollowId = user.UserId;
            context.Followers.Add(follower);
            context.SaveChanges();


            return(RedirectToAction("HomePage", "Home"));
        }
        public override void Download(string screenname)
        {
            using (TwitterDbContext db = new TwitterDbContext())
            {
                foreach (var user in db.Users)
                {
                    var queryResult = (from t in db.Tweets where t.ProfileId == user.Id  select t).OrderByDescending(i => i.Id);

                    foreach (TwitterTweet tweet in queryResult)
                    {
                        //int numberOfObjectsPerPage = 10;
                        //var queryResultPage = queryResult.Skip(numberOfObjectsPerPage * 1).Take(numberOfObjectsPerPage);

                        var cursor = -1;
                        //var count = 100;
                        var api_path = "https://api.twitter.com/1.1/statuses/retweeters/ids.json?id={0}&cursor={1}&stringify_ids=true";

                        while (cursor != 0)
                        {
                            //int page = i / pagesize + 1;
                            //var results = TwitterAccessor.ExecuteCursorGETCursorQueryResult<IIdsCursorQueryResultDTO>(query, 100, page );
                            //var userIds = results.SelectMany(x => x.Ids);
                            //var retweeters = TwitterAccessor.ExecuteCursorGETQuery<long, IIdsCursorQueryResultDTO>(query, 100);
                            string query = string.Format(api_path, tweet.Id, cursor);
                            var jsonObject = TwitterAccessor.GetQueryableJsonObjectFromGETQuery(query);

                            if (jsonObject != null)
                            {
                                cursor = (int)jsonObject["next_cursor"];
                                var ids = jsonObject["ids"];

                                //tweet.RetweetersIds += ids.ToString();
                            }
                        }

                        db.SaveChanges();
                    }
                }
            }
        }
        public IActionResult Register(User user)
        {
            var    msg        = "";
            var    passMsg    = "";
            var    hashedPass = "";
            string salt       = getSalt();

            if (ModelState.IsValid)
            {
                if (!CheckUsernameAvailability(user))
                {
                    msg         = "Username is already taken";
                    ViewBag.msg = msg;
                    ViewBag.err = "";
                    return(View());
                }

                if (!CheckPasswordLength(user))
                {
                    passMsg         = "Password is too long! Can't be longer then 20 characters.";
                    ViewBag.passMsg = passMsg;
                    ViewBag.passErr = "";
                    return(View());
                }

                hashedPass    = passHash(salt + user.Password);
                user.Password = hashedPass;
                _db.User.Add(user);

                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            msg         = "Unvalid data";
            ViewBag.msg = msg;
            ViewBag.err = "";
            return(View());
        }
        private static void AddNotifications(TwitterDbContext twitterDb)
        {
            var users = twitterDb.Users.ToList();

            users[0].Notifications.Add(new Notification { Content = "Notification 1"});
            users[0].Notifications.Add(new Notification { Content = "Notification 2"});
            users[0].Notifications.Add(new Notification { Content = "Notification 3"});

            twitterDb.SaveChanges();
        }
        private static void InsertFollwersAndFollwingUsers(TwitterDbContext twitterDb)
        {
            var users = twitterDb.Users.ToList();

            users[3].Followings.Add(users[0]);
            users[0].Followers.Add(users[3]);
            users[3].Followings.Add(users[1]);
            users[1].Followers.Add(users[3]);
            users[3].Followings.Add(users[2]);
            users[2].Followers.Add(users[3]);

            twitterDb.SaveChanges();
        }
        private static void InsertTweets(TwitterDbContext twitterDb)
        {
            var users = twitterDb.Users.ToList();

            users[0].Tweets.Add(new Twiit());
            users[0].Tweets.Add(new Twiit());
            users[0].Tweets.Add(new Twiit());

            twitterDb.SaveChanges();
        }
        private static void EditProfile(TwitterDbContext twitterDb)
        {
            var users = twitterDb.Users.ToList();
            users[0].Profile.Content = "Changed";

            twitterDb.SaveChanges();
        }
        private static void SendMessages(TwitterDbContext twitterDb)
        {
            var users = twitterDb.Users.ToList();

            users[0].Messages.Add(new Message
            {
                Title = "Parfume",
                Content = "Farenhaint my favorite parfume",
                SentDate = DateTime.Now,
            });

            twitterDb.SaveChanges();
        }
        private static void ReportManyTweetsToFacebook(TwitterDbContext twitterDb)
        {
            var users = twitterDb.Users.ToList();
            var tweets = twitterDb.Tweets.ToList();

            users[0].ReportedTweetsToFacebook.Add(tweets[0]);
            users[0].ReportedTweetsToFacebook.Add(tweets[1]);
            users[0].ReportedTweetsToFacebook.Add(tweets[2]);

            twitterDb.SaveChanges();
        }
        private static void ReplyManyTweets(TwitterDbContext twitterDb)
        {
            var users = twitterDb.Users.ToList();
            var tweets = twitterDb.Tweets.ToList();

            users[0].ReplyTweets.Add(tweets[0]);
            users[0].ReplyTweets.Add(tweets[1]);
            users[0].ReplyTweets.Add(tweets[2]);

            twitterDb.SaveChanges();    
        }
Exemple #25
0
        public void SetMessage(TWEET obj)
        {
            db.TWEETs.Add(obj);

            db.SaveChanges();
        }
 public void AddModel(T model)
 {
     Entity.Add(model);
     _db.SaveChanges();
 }
        private static void InsertUsersInBase(TwitterDbContext twitterDb)
        {
            twitterDb.Users.Add(new User
            {
                Name = "Dimitar",
                Profile = new Profile
                {
                    Content = "Profile 1"
                }
            });
                
            twitterDb.Users.Add(new User
            {
                Name = "Angel",
                Profile = new Profile
                {
                    Content = "Profile 2"
                }
            });

            twitterDb.Users.Add(new User
            {
                Name = "Kiro",
                Profile = new Profile
                {
                    Content = "Profile 3"
                }
            });

            twitterDb.Users.Add(new User
            {
                Name = "Biliana",
                Profile = new Profile
                {
                    Content = "Profile 4"
                }
            });

            twitterDb.Users.Add(new User
            {
                Name = "Ivan",
                Profile = new Profile
                {
                    Content = "Profile 5"
                }
            });

            twitterDb.SaveChanges();
        }