public ManualGame GetManualGame(long gameId)
        {
            try
            {
                var dc = new ManagementContext();
                DateTime hours = DateTime.UtcNow.AddDays(-16);
                DateTime endDate = DateTime.UtcNow.AddDays(-16);
                var games = dc.RNScores.Where(x => x.ScoreId == gameId).FirstOrDefault();

                var game = new ManualGame()
                              {
                                  Team1Name = games.Team1Name,
                                  Team1Score = games.Team1Score,

                                  Team2Name = games.Team2Name,
                                  Team2Score = games.Team2Score,
                                  ScoreId = games.ScoreId,
                                  EmailWhenBoutIsPosted = games.EmailWhenBoutIsPosted,
                                  Notes = games.Notes,
                                  RuleSetEnum = (RuleSetsUsedEnum)games.RuleSetEnum,
                                  SanctionedByFederationEnum = (FederationsEnum)games.SanctionedByFederationEnum,
                                  TimeEntered = games.GameDateTime,
                                  IsPublished = games.IsPublished,
                                  IsApproved = games.IsApproved,
                                  PublishDateTime = games.PublishDateTime,
                                  Team1Id = games.League1 == null ? "" : games.League1.LeagueId.ToString(),
                                  Team2Id = games.League2 == null ? "" : games.League2.LeagueId.ToString()
                              };
                game.RuleSetEnumDisplay = game.RuleSetEnum.ToString();
                game.SanctionedByFederationEnumDisplay = game.SanctionedByFederationEnum.ToString();
                return game;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType(), ErrorGroupEnum.Database);
            }
            return new ManualGame();
        }
 public GameFactory AddRNScore(ManualGame score)
 {
     this.rnScore = score;
     return this;
 }
    public HttpResponseMessage Put([FromBody]FacebookMessage message, string action)
    {
        try
        {

            if (action == "updateLongTermToken")
            {
                var token = FacebookFactory.Initialize(message.UserAccessToken)
                           .GetLongTermAccessToken(ConfigurationManager.AppSettings["FacebookAppId"].ToString(), ConfigurationManager.AppSettings["FacebookAppIdSecret"].ToString());

                if (!String.IsNullOrEmpty(token.LongTermAccessToken))
                {
                    message.UserAccessToken = token.LongTermAccessToken;
                    //the access token will time to time not have an expire listed on it.  So we only insert when we know it expires.
                    //if (token.LongTermAccessTokenExpires > DateTime.UtcNow)
                    FacebookData.InsertNewAccessToken(token.LongTermAccessToken, token.LongTermAccessTokenExpires);
                }
            }
            else if (action == "postToFacebook")
            {
                FacebookFactory.Initialize(message.UserAccessToken)
                    .GetPageAuthorization(ConfigurationManager.AppSettings["FacebookPageName"].ToString(), ConfigurationManager.AppSettings["FacebookPageId"].ToString())
                    .PostToFanPage(message.Message, message.Link, message.PictureUrl, message.Name, message.Caption, message.DateForMessage);



            }
            //bitcoinWithdraw
            else if (action == "saveAndPostToFacebook")
            {
                ManualGame score = new ManualGame();
                score.Team1Name = message.Team1Name;
                if (!String.IsNullOrEmpty(message.Team1Score))
                    score.Team1Score = Convert.ToInt32(message.Team1Score);
                score.Team2Name = message.Team2Name;
                if (!String.IsNullOrEmpty(message.Team2Score))
                    score.Team2Score = Convert.ToInt32(message.Team2Score);
                if (!String.IsNullOrEmpty(message.DateOfGame))
                    score.TimeEntered = Convert.ToDateTime(message.DateOfGame);
                else
                    score.TimeEntered = DateTime.UtcNow;
                GameFactory.Initialize().AddRNScore(score).SaveChanges();

                SiteCache.ClearPastGames();
                if (!String.IsNullOrEmpty(message.UserAccessToken))
                {
                    FacebookFactory.Initialize(message.UserAccessToken)
                        .GetPageAuthorization(ConfigurationManager.AppSettings["FacebookPageName"].ToString(), ConfigurationManager.AppSettings["FacebookPageId"].ToString())
                            .AddScores(message.Team1Name, message.Team1Score, message.Team2Name, message.Team2Score)
                            .PostToFanPage(message.Message, message.Link, message.PictureUrl, message.Name, message.Caption, message.DateForMessage);
                }
            }
            else if (action == "postScoreToFacebook")
            {

                FacebookFactory.Initialize(message.UserAccessToken)
                    .GetPageAuthorization(ConfigurationManager.AppSettings["FacebookPageName"].ToString(), ConfigurationManager.AppSettings["FacebookPageId"].ToString())
                    .AddScores(message.Team1Name, message.Team1Score, message.Team2Name, message.Team2Score)
                    .PostToFanPage(message.Message, message.Link, message.PictureUrl, message.Name, message.Caption, message.DateForMessage);



            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
        catch (UnauthorizedAccessException)
        {
            return Request.CreateResponse(HttpStatusCode.Unauthorized);
        }
        catch (Exception exception)
        {
            ErrorDatabaseManager.AddException(exception, GetType(), additionalInformation: JsonConvert.SerializeObject(message));
            return Request.CreateResponse(HttpStatusCode.InternalServerError);
        }
    }