public TweetEngagementVM PostRetweets(int tweetID, int userID)
        {
            Retweets retweet = db.Retweets.Where(x => x.TweetID == tweetID && x.UserID == userID).SingleOrDefault();

            if (retweet == null)
            {
                db.Retweets.Add(new Retweets
                {
                    TweetID     = tweetID,
                    UserID      = userID,
                    RetweetTime = DateTime.Now
                });
                db.SaveChanges();
                return(new TweetEngagementVM
                {
                    tweetID = tweetID,
                    userID = userID,
                    engaged = true
                });
            }
            else
            {
                db.Retweets.Remove(retweet);
                db.SaveChanges();
                return(new TweetEngagementVM
                {
                    tweetID = tweetID,
                    userID = userID,
                    engaged = false
                });
            }
        }
Example #2
0
        public ResponseVM Follow(int followerID, int followingID)
        {
            UsersFollowing obj = new UsersFollowing()
            {
                DateModified = DateTime.Now,
                FollowerID   = followerID,
                FollowingID  = followingID
            };

            if (obj == null)
            {
                return new ResponseVM
                       {
                           responseCode    = 400,
                           responseMessage = "An error occured."
                       }
            }
            ;

            db.UsersFollowing.Add(obj);
            db.SaveChanges();

            return(new ResponseVM
            {
                responseCode = 200,
                responseMessage = "Ok."
            });
        }
Example #3
0
        public ResponseVM PostTweets(PostTweetVM obj)
        {
            Tweets tweet = new Tweets
            {
                UserID    = obj.userID,
                Content   = obj.content,
                TweetDate = DateTime.Now,
                TweetImg  = obj.image
            };

            try
            {
                db.Tweets.Add(tweet);
                db.SaveChanges();
                return(new ResponseVM
                {
                    responseCode = 200,
                    responseMessage = "Tweet posted successfully."
                });
            }
            catch (Exception)
            {
                return(new ResponseVM
                {
                    responseCode = 400,
                    responseMessage = "An error occurred."
                });
            }
        }
Example #4
0
        public TweetEngagementVM PostFavorites(int userID, int tweetID)
        {
            Favorites favorite = db.Favorites.Where(x => x.TweetID == tweetID && x.UserID == userID).SingleOrDefault();

            if (favorite == null)
            {
                db.Favorites.Add(new Favorites
                {
                    TweetID      = tweetID,
                    UserID       = userID,
                    FavoriteTime = DateTime.Now
                });
                db.SaveChanges();
                return(new TweetEngagementVM {
                    tweetID = tweetID,
                    userID = userID,
                    engaged = true
                });
            }
            else
            {
                db.Favorites.Remove(favorite);
                db.SaveChanges();
                return(new TweetEngagementVM
                {
                    tweetID = tweetID,
                    userID = userID,
                    engaged = false
                });
            }
        }
        public ActionResult Create([Bind(Include = "user_id,password,fullName,email,joined,active")] PERSON pERSON)
        {
            if (ModelState.IsValid)
            {
                db.People.Add(pERSON);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(pERSON));
        }
        public ActionResult Create(TWEET tWEET)
        {
            if (ModelState.IsValid)
            {
                tWEET.user_id = Session["user"].ToString();
                tWEET.created = DateTime.Now;
                db.TWEETs.Add(tWEET);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.user_id = new SelectList(db.People, "user_id", "password", tWEET.user_id);
            return(View(tWEET));
        }
        public ActionResult PostTweet(PERSON pERSON)
        {
            if (ModelState.IsValid)


            {
                pERSON.TweetData.created = DateTime.Now;
                pERSON.TweetData.user_id = Session["user"].ToString();
                db.TWEETs.Add(pERSON.TweetData);
                db.SaveChanges();
            }

            return(View("Index"));
        }
        public ActionResult Create([Bind(Include = "user_id,following_id")] FOLLOWING fOLLOWING)
        {
            if (ModelState.IsValid)
            {
                fOLLOWING.user_id      = Session["user"].ToString();
                fOLLOWING.following_id = Session["clckuser"].ToString();
                db.FOLLOWINGs.Add(fOLLOWING);
                //db.Entry(fOLLOWING).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            //ViewBag.user_id = new SelectList(db.People, "user_id", fOLLOWING.user_id);
            return(View(fOLLOWING));
        }
Example #9
0
        public ResponseVM PostFavoriteTweets(FavoriteTweetsVM obj)
        {
            try
            {
                db.FavoriteTweets.Add(new FavoriteTweets
                {
                    TweetID = obj.TweetID,
                    UserID  = obj.UserID
                });

                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(new ResponseVM
                {
                    responseCode = 400,
                    responseMessage = "An error occured."
                });
            }
            return(new ResponseVM
            {
                responseCode = 200,
                responseMessage = "Ok."
            });
        }
Example #10
0
        public int PostConversation(int userID1, int userID2)
        {
            Conversations conversation = new Conversations()
            {
                User1ID = userID1,
                User2ID = userID2
            };

            try
            {
                db.Conversations.Add(conversation);
                db.SaveChanges();
                return(conversation.ConversationID);
            } catch (Exception e)
            {
                return(0);
            }
        }
        public ActionResult SignUp(FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                PERSON person = new PERSON();
                person.user_id  = collection["txtUsername"].ToString();
                person.fullName = collection["txtFullName"].ToString();
                //person.password = collection["txtPwd"].ToString();
                person.password = Convert.ToString(Helper.EncryptString(collection["txtPwd"].ToString(), collection["txtPwd"].ToString()));
                person.email    = collection["txtemail"].ToString();
                person.joined   = DateTime.Now;
                person.active   = true;
                db.People.Add(person);
                db.SaveChanges();
                return(RedirectToAction("Login", "Login"));
            }

            return(View());
        }
Example #12
0
        public UsersAuthVM Authentication(string username, string password)
        {
            UsersAuthVM userVM = db.Users.Where(x => x.Username == username && password == x.Password).Select(x => new UsersAuthVM()
            {
                username = x.Username,
                password = x.Password,
                userID   = x.UserID
            })
                                 .SingleOrDefault();

            if (userVM != null)
            {
                Users user = db.Users.Find(userVM.userID);
                if (user.Active == false)
                {
                    user.Active = true;
                    db.SaveChanges();
                }
            }

            return(userVM);
        }