Exemple #1
0
        void DatabaseRead()
        {
            // Create a utility to handle the SQL calls for this action.
            MSSqlUtility sqlUtil = new MSSqlUtility();

            //Create an empty row list to be used as the all cards holder
            List<SqlRow> allCardsRows = new List<SqlRow>();

            //Create an empty row list to be used as the all factions holder
            List<SqlRow> allFactionsRows = new List<SqlRow>();

            //Create an empty row list to be used as the all leaders holder
            List<SqlRow> allLeadersRows = new List<SqlRow>();
            try
            {

                allCardsRows = sqlUtil.ExecuteQuery(gAppOptions.SelectAllPlayerCards, connectionString, null);

                //READ LEADERS AND FACTIONS
                allFactionsRows = sqlUtil.ExecuteQuery(gAppOptions.SelectAllFactions, connectionString, null);
                allLeadersRows = sqlUtil.ExecuteQuery(gAppOptions.SelectAllLeaders, connectionString, null);
                //Build the Factions and build the list
                if (allFactionsRows != null)
                {
                    foreach (SqlRow row in allFactionsRows)
                    {
                        //Assign the returned database values into the object
                        FactionInfo faction = new FactionInfo();
                        faction.FactionName = ((string)row["factionName"]).Trim();
                        faction.FactionAbbr = ((string)row["factionAbbreviation"]).Trim();
                        faction.FactionPerk = ((string)row["factionPerk"]).Trim();
                        gAllFactions.Add(faction);
                    }
                }
                //Build the Leaders and build the list
                if (allLeadersRows != null)
                {
                    foreach (SqlRow row in allLeadersRows)
                    {
                        //Assign the returned database values into the object
                        LeaderInfo leader = new LeaderInfo();
                        leader.LeaderName = ((string)row["leaderName"]).Trim();
                        leader.LeaderAbility = ((string)row["leaderAbility"]).Trim();
                        leader.LeaderFaction = ((string)row["leaderFaction"]).Trim();
                        leader.LeaderFactionAbbr = ((string)row["leaderFactionAbbreviation"]);
                        gAllLeaders.Add(leader);
                    }
                }
                //Build the motherlode deck by assigning the attributes from the database into the object attributes.
                //The TRY/CATCH is there to handle potential null values because C# null is not the same as DBNULL
                if (allCardsRows != null)
                {
                    foreach (SqlRow row in allCardsRows)
                    {
                        Card card = new Card();
                        try
                        {
                            card.Name = ((string)row["cardName"]).Trim();
                        }
                        catch
                        { }
                        try
                        {
                            card.Power = (int)row["cardPower"];
                        }
                        catch { }
                        try
                        {
                            card.Faction = ((string)row["cardFaction"]).Trim();
                        }
                        catch { }
                        try
                        {
                            card.Quote = ((string)row["cardQuote"]).Trim();
                        }
                        catch { }
                        try
                        {
                            card.Hero = (bool)(row["cardHero"]);
                        }
                        catch { }
                        try
                        {
                            card.Range = ((string)row["cardRange"]).Trim();
                        }
                        catch { }
                        try
                        {
                            card.Ability = ((string)row["cardAbilities"]).Trim();
                        }
                        catch { }
                        try
                        {
                            card.Quote = ((string)row["cardQuote"]).Trim();
                        }
                        catch { }
                        //New logic to read image file from DB and build path. ImageFilePath
                        try
                        {
                            string cardImageFileName = (string)row["cardImageFileName"];
                            card.ImageFilePath = "~/Content/Images/" + (cardImageFileName.Trim().Replace(" ", "%20"));

                        }
                        catch { }
                        gAllCards.Add(card);
                    }
                }

            } // end of Try-No Touchy
            catch
            {
                //Do we need to perform an action on catch?
            }
        }
 public FactionInfo SelectFaction(string factionAbbr)
 {
     FactionInfo sf = new FactionInfo();
     List<FactionInfo> factionListReturn = new List<FactionInfo>();
     //Create web client to do call
     System.Net.WebClient client = new System.Net.WebClient();
     //Create the url to pull from
     string factionUriString = Url.RouteUrl("", new { action = "getfaction", controller = "Card", id = factionAbbr }, Request.Url.Scheme);
     //Get the faction and deserialize
     string factionReturn = client.DownloadString(factionUriString);
     factionListReturn = JsonConvert.DeserializeObject<List<FactionInfo>>(factionReturn);
     sf = factionListReturn[0];
     return sf;
 }