Пример #1
0
        public ActionResult ChatList()
        {
            if (!User.Identity.IsAuthenticated)
                return RedirectToAction("Index", "FoursquareLogin");
            IMessageRepository repository = new MessageRepository(new FoursquareUserContext());
            int uId = Convert.ToInt32(User.Identity.Name);
            IEnumerable<MessageModel> messages =
                repository.GetMessages().Where(model => model.From == uId || model.To == uId);
            List<int> res = new List<int>();
            foreach (MessageModel messageModel in messages)
            {
                if (messageModel.From != uId)
                    res.Add(messageModel.From);
                else
                    res.Add(messageModel.To);
            }
            ViewBag.Chats = res.Distinct();
            List<string> names = new List<string>();
            foreach (int id in ViewBag.Chats)
            {
                NameValueCollection tmp;

                tmp = GetProfileInfo(id);
                names.Add(tmp["firstname"]);
            }
            ViewBag.Names = names;
            return View();
        }
Пример #2
0
        public Profile GetProfile(string userId, string token, string targetId)
        {
            int uId = Convert.ToInt32(userId);
            int tId = Convert.ToInt32(targetId);

            if (AuthService.ValidateAuthData(uId, token))
            {
                FoursquareUserContext dbContext = new FoursquareUserContext();
                IMessageRepository repository = new MessageRepository(dbContext);
                FoursquareOAuth fsqOAuth = new FoursquareOAuth(token);
                if (fsqOAuth.CheckForFriendship(tId))
                {
                    Profile res = fsqOAuth.GetProfileInfo(tId);
                    return res;
                }

            }
            return null;
        }
Пример #3
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 });
        }
Пример #4
0
        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;
        }