コード例 #1
0
ファイル: MeleeUserRepository.cs プロジェクト: twdean/MeleeMe
        public UserModel Get(string id)
        {
            UserModel meleeUser = null;
            var       dbContext = new MeleeMeEntities();

            using (dbContext)
            {
                var mUser = (from c in dbContext.m_Credentials
                             where c.m_User.TwitterUserId == id
                             select new { c.AccessToken, c.UserId, c.m_User.ProfileImageUrl, c.m_User.ScreenName }).FirstOrDefault();

                if (mUser != null)
                {
                    meleeUser = new UserModel
                    {
                        TwitterUserId = id,
                        UserId        = mUser.UserId,
                        ImageUrl      = mUser.ProfileImageUrl,
                        ScreenName    = mUser.ScreenName,
                        AccessToken   = mUser.AccessToken,
                        Stats         = MeleeRepository.GetMeleeStats(id, UserType.Challenger),
                        Connections   = new ConnectionRepository().Get(mUser.UserId)
                    };
                }
            }

            return(meleeUser);
        }
コード例 #2
0
ファイル: MeleeUserRepository.cs プロジェクト: twdean/MeleeMe
        public UserModel Add(string id, string profileImageUrl, string screenName, string token, string OAuthToken)
        {
            var newUser   = null as UserModel;
            var dbContext = new MeleeMeEntities();


            using (dbContext)
            {
                var mUser = dbContext.m_User.FirstOrDefault(mu => mu.TwitterUserId == id);

                if (mUser != null)
                {
                    var um = new UserModel
                    {
                        TwitterUserId = id,
                        UserId        = mUser.UserId,
                        ImageUrl      = profileImageUrl,
                        AccessToken   = mUser.m_Credentials.Select(at => at.AccessToken).ToString(),
                        Stats         = MeleeRepository.GetMeleeStats(id, UserType.Challenger),
                        Connections   = new ConnectionRepository().Get(mUser.UserId)
                    };

                    mUser.ProfileImageUrl = profileImageUrl;
                    mUser.ScreenName      = screenName;


                    dbContext.SaveChanges();
                    return(um);
                }

                var u = new m_User
                {
                    TwitterUserId   = id,
                    ProfileImageUrl = profileImageUrl,
                    ScreenName      = screenName
                };


                dbContext.m_User.Add(u);
                AddUserCredentials(dbContext, u, token);
                AddConnection(dbContext, u, token, OAuthToken);

                newUser = new UserModel
                {
                    TwitterUserId = id,
                    ImageUrl      = profileImageUrl,
                    ScreenName    = screenName,
                    AccessToken   = token,
                    UserId        = u.UserId,
                    Stats         = new MeleeStatisticsModel()
                };

                dbContext.SaveChanges();
                newUser.Connections = new ConnectionRepository().Get(u.UserId);
            }

            return(newUser);
        }