示例#1
0
        public ActionResult MakeFriends(int id)
        {
            if (!User.Identity.IsAuthenticated)
                return RedirectToAction("Index", "FoursquareLogin");

            FoursquareOAuth foursquareOAuth = new FoursquareOAuth(GetCurrentUserToken());
            foursquareOAuth.MakeFriendship(id);
            MessageModel messageModel = new MessageModel()
                {
                    From = Convert.ToInt32(User.Identity.Name),
                    Message = "Accept",
                    time = DateTime.Now,
                    To = id,
                    type = "Invite"
                };
            IMessageRepository repository = new MessageRepository(new FoursquareUserContext());
            repository.InsertMessage(messageModel);
            repository.Save();
            return RedirectToAction("Chat", "Foursquare", new { id = id });
        }
        public bool GetMakeFriends(string token, string userId, string targetId)
        {
            int uId = Convert.ToInt32(userId);
            int tId = Convert.ToInt32(targetId);
            if (AuthService.ValidateAuthData(uId, token))
            {
                FoursquareOAuth foursquareOAuth = new FoursquareOAuth(token);

                MessageModel messageModel = new MessageModel()
                {
                    From = uId,
                    Message = "Accept",
                    time = DateTime.Now,
                    To = tId,
                    type = "Invite"
                };
                IMessageRepository repository = new MessageRepository(new FoursquareUserContext());
                repository.InsertMessage(messageModel);
                repository.Save();
                return foursquareOAuth.MakeFriendship(tId);
            }
            return false;
        }