/// <summary>
 /// Metodo deprecato per l'aggiunta di un nuovo oggetto all'elemento EntitySet Reputation. Utilizzare il metodo .Add della proprietà associata ObjectSet&lt;T&gt;.
 /// </summary>
 public void AddToReputation(Reputation reputation)
 {
     base.AddObject("Reputation", reputation);
 }
        private void DownloadReputations(User currentUser, SocialTFSEntities db)
        {
            try
            {
                String str = FeaturesType.Reputation.ToString();
                DateTime tempoLimite = DateTime.UtcNow - _reputationSpan;
                List<ChosenFeature> chosenFeatures = db.ChosenFeature.Where(cf => cf.fk_user == currentUser.pk_id &&
                    cf.fk_feature == str).ToList();

                //cf.lastDownload < tempoLimite

                foreach (ChosenFeature item in chosenFeatures)
                {
                    /*
                    foreach (Reputation repu in item.Reputation)
                    {
                        db.Reputation.DeleteObject(repu);
                    }
                    db.SaveChanges();
                     * */

                    #region Get servizio

                    Registration registration = item.Registration;
                    IService service;
                    String currentService = registration.ServiceInstance.name;
                    if (currentService == "Coderwall" || currentService == "Ohloh")
                    {
                        service = ServiceFactory.getService(
                        registration.ServiceInstance.Service.name,
                        registration.nameOnService,
                        registration.User.password,
                        "standard-domain",
                        registration.ServiceInstance.host);
                    }
                    else
                    {
                        service = ServiceFactory.getServiceOauth(
                        registration.ServiceInstance.Service.name,
                        registration.ServiceInstance.host,
                        registration.ServiceInstance.consumerKey,
                        registration.ServiceInstance.consumerSecret,
                        registration.accessToken,
                        registration.accessSecret);
                    }

                    #endregion Get servizio

                    IReputation userReputations = (IReputation)service.Get(FeaturesType.Reputation, null);

                    #region New Reputation

                    // Controllo se la reputazione di un dato servizio e di un dato utente
                    // è presente nel DB
                    // Se esiste, la modifico, se non esiste la creo

                    Reputation testReputation = db.Reputation.FirstOrDefault<Reputation>(
                        r => r.ChosenFeature.fk_user == currentUser.pk_id);

                    //rep = db.Reputation.FirstOrDefault(e => e.pk_id == userReputations.reputationId);

                    if (testReputation == null)
                    {
                        switch (currentService)
                        {
                            case "Coderwall":
                                db.Reputation.AddObject( new Reputation()
                                {
                                    fk_chosenFeature = item.pk_id,
                                    stack_answer = null,
                                    stack_question = null,
                                    stack_bronze = null,
                                    stack_silver = null,
                                    stack_gold = null,
                                    stack_reputationValue = null,
                                    ohloh_kudorank = null,
                                    ohloh_bigCheese = null,
                                    ohloh_fosser = null,
                                    ohloh_orgMan = null,
                                    ohloh_stacker = null,
                                    ohloh_kudoscore = null,
                                    coderwall_endorsements = userReputations.coderwallEndorsements,
                                    linkedin_recommendations = null,
                                    linkedin_recommenders = null
                                });
                                break;

                            case "Ohloh":
                                db.Reputation.AddObject(new Reputation()
                            {

                                fk_chosenFeature = item.pk_id,
                                stack_answer = null,
                                stack_question = null,
                                stack_bronze = null,
                                stack_silver = null,
                                stack_gold = null,
                                stack_reputationValue = null,
                                ohloh_kudorank = userReputations.ohlohKudoRank,
                                ohloh_bigCheese = userReputations.ohlohBigcheese,
                                ohloh_fosser = userReputations.ohlohFosser,
                                ohloh_orgMan = userReputations.ohlohOrgman,
                                ohloh_stacker = userReputations.ohlohStacker,
                                ohloh_kudoscore = userReputations.ohlohKudoScore,
                                coderwall_endorsements = null,
                                linkedin_recommendations = null,
                                linkedin_recommenders = null
                            });
                            break;

                            case "StackOverflow":
                                Reputation r = new Reputation()
                                {
                                    fk_chosenFeature = item.pk_id,
                                    stack_answer = userReputations.stackAnswer,
                                    stack_question = userReputations.stackQuestion,
                                    stack_bronze = userReputations.stackBronze,
                                    stack_silver = userReputations.stackSilver,
                                    stack_gold = userReputations.stackGold,
                                    stack_reputationValue = userReputations.stackReputationValue,
                                    ohloh_kudorank = null,
                                    ohloh_bigCheese = null,
                                    ohloh_fosser = null,
                                    ohloh_orgMan = null,
                                    ohloh_stacker = null,
                                    ohloh_kudoscore = null,
                                    coderwall_endorsements = null,
                                    linkedin_recommendations = null,
                                    linkedin_recommenders = null
                                };
                                db.Reputation.AddObject(r);
                                break;
                        }

                        /*
                        db.Reputation.AddObject(new Reputation()
                        {
                            pk_id = userReputations.reputationId,
                            fk_chosenFeature = item.pk_id,
                            stack_answer = userReputations.stackAnswer,
                            stack_question = userReputations.stackQuestion,
                            stack_bronze = userReputations.stackBronze,
                            stack_silver = userReputations.stackSilver,
                            stack_gold = userReputations.stackGold,
                            stack_reputationValue = userReputations.stackReputationValue,
                            ohloh_kudorank = userReputations.ohlohKudoRank,
                            ohloh_bigCheese = userReputations.ohlohBigcheese,
                            ohloh_fosser = userReputations.ohlohFosser,
                            ohloh_orgMan = userReputations.ohlohOrgman,
                            ohloh_stacker = userReputations.ohlohStacker,
                            ohloh_kudoscore = userReputations.ohlohKudoScore,
                            coderwall_endorsements = userReputations.coderwallEndorsements,
                            linkedin_recommendations = userReputations.linkedinRecommendations,
                            linkedin_recommenders = userReputations.linkedinRecommenders
                        });
                         * */

                        db.SaveChanges();

                    }

                    #endregion New Reputation

                    else

                    #region edit reputation

                    {
                        //aggiornamento tupla
                        //var testReputation = db.Reputation.FirstOrDefault(e => e.pk_id == userReputations.reputationId);
                        if (registration.ServiceInstance.name == "Coderwall")
                        {
                            testReputation.coderwall_endorsements = userReputations.coderwallEndorsements;
                        }
                        else if (registration.ServiceInstance.name == "Ohloh")
                        {
                            testReputation.ohloh_kudorank = userReputations.ohlohKudoRank;
                            testReputation.ohloh_kudoscore = userReputations.ohlohKudoScore;
                            testReputation.ohloh_bigCheese = userReputations.ohlohBigcheese;
                            testReputation.ohloh_fosser = userReputations.ohlohFosser;
                            testReputation.ohloh_orgMan = userReputations.ohlohOrgman;
                            testReputation.ohloh_stacker = userReputations.ohlohStacker;
                        }
                        else if (registration.ServiceInstance.name == "StackOverflow")
                        {
                            testReputation.stack_answer = userReputations.stackAnswer;
                            testReputation.stack_question = userReputations.stackQuestion;
                            testReputation.stack_reputationValue = userReputations.stackReputationValue;
                            testReputation.stack_bronze = userReputations.stackBronze;
                            testReputation.stack_silver = userReputations.stackSilver;
                            testReputation.stack_gold = userReputations.stackGold;
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }

                        db.SaveChanges();

                    }

                    #endregion edit reputation

                    item.lastDownload = DateTime.UtcNow;
                }

            }
            catch (Exception e)
            {
                return;
            }
        }
 /// <summary>
 /// Crea un nuovo oggetto Reputation.
 /// </summary>
 /// <param name="pk_id">Valore iniziale della proprietà pk_id.</param>
 /// <param name="fk_chosenFeature">Valore iniziale della proprietà fk_chosenFeature.</param>
 public static Reputation CreateReputation(global::System.Int64 pk_id, global::System.Int64 fk_chosenFeature)
 {
     Reputation reputation = new Reputation();
     reputation.pk_id = pk_id;
     reputation.fk_chosenFeature = fk_chosenFeature;
     return reputation;
 }