Пример #1
0
        /// <summary>
        /// Gets a single DLC item
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        internal Dlc GetDlc(int id)
        {
            Dlc game = new Dlc();

            using (NpgsqlConnection conn = GetConnection())
            {
                conn.Open();

                // Insert some data
                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "select * from dlc where id = @p";
                    cmd.Parameters.AddWithValue("p", id);

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            game = new Dlc()
                            {
                                Id           = (int)reader["id"],
                                ParentGameId = (long)reader["parentgameid"],
                                Name         = reader["name"].ToString(),
                                Store        = reader["store"].ToString(),
                                Price        = (decimal)reader["price"],
                                Owned        = (bool)reader["owned"],
                                Notes        = reader["notes"].ToString(),
                                Ranking      = reader["ranking"] == DBNull.Value ? (short)-1 : (short)reader["ranking"],
                                Rating       = reader["rating"] == DBNull.Value ? (short)-1 : (short)reader["rating"]
                            };
                        }
                    }
                }
            }

            return(game);
        }
Пример #2
0
        /// <summary>
        /// Edits a DLC entry to match the supplied object
        /// </summary>
        /// <param name="dlc"></param>
        /// <param name="adjustRankings"></param>
        /// <returns></returns>
        internal bool EditDlc(Dlc dlc, bool adjustRankings = false)
        {
            //If the game is owned, adjust rankings accordingly
            if (dlc.Owned == true)
            {
                dlc.Ranking = 0;
            }

            using (NpgsqlConnection conn = GetConnection())
            {
                conn.Open();

                try
                {
                    // Insert some data
                    using (var cmd = new NpgsqlCommand())
                    {
                        cmd.Connection   = conn;
                        cmd.CommandText  = "UPDATE dlc SET name = @p, parentgameid = @p2, owned = @p3,";
                        cmd.CommandText += " price = @p4, notes = @p5, ranking = @p6, rating = @p7, store = @p9 ";
                        cmd.CommandText += " WHERE id = @p8";

                        if (dlc.Id == 0)
                        {
                            throw new Exception("Id cannot be 0!");
                        }

                        if (dlc.ParentGameId == 0)
                        {
                            throw new Exception("Parent ID cannot be 0!");
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("p2", dlc.ParentGameId);
                        }

                        if (dlc.Store != null)
                        {
                            cmd.Parameters.AddWithValue("p9", dlc.Store);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("p9", DBNull.Value);
                        }

                        if (dlc.Name != null)
                        {
                            cmd.Parameters.AddWithValue("p", dlc.Name);
                        }
                        else
                        {
                            throw new Exception("Name cannot be null!");
                        }

                        if (dlc.Notes != null)
                        {
                            cmd.Parameters.AddWithValue("p5", dlc.Notes);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("p5", DBNull.Value);
                        }

                        cmd.Parameters.AddWithValue("p3", dlc.Owned);
                        cmd.Parameters.AddWithValue("p4", dlc.Price);
                        cmd.Parameters.AddWithValue("p6", dlc.Ranking);
                        cmd.Parameters.AddWithValue("p7", dlc.Rating);
                        cmd.Parameters.AddWithValue("p8", dlc.Id);

                        cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("There was an error trying to update the row", ex);
                }
            }

            //Ensure rankings consistent
            if (adjustRankings)
            {
                AdjustRankings(ItemType.Dlc);
            }

            return(true);
        }
Пример #3
0
        public int GetDlcAppId(string name)
        {
            Dlc          game      = new Dlc();
            StoreDataDlc storeData = new StoreDataDlc();

            using (NpgsqlConnection conn = GetConnection())
            {
                conn.Open();

                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "select * from dlc where name = @p";
                    cmd.Parameters.AddWithValue("p", name);

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            game = new Dlc()
                            {
                                Id           = (int)reader["id"],
                                ParentGameId = (long)reader["parentgameid"],
                                Name         = reader["name"].ToString(),
                                Store        = reader["store"].ToString(),
                                Price        = (decimal)reader["price"],
                                Owned        = (bool)reader["owned"],
                                Notes        = reader["notes"].ToString(),
                                Ranking      = reader["ranking"] == DBNull.Value ? (short)-1 : (short)reader["ranking"],
                                Rating       = reader["rating"] == DBNull.Value ? (short)-1 : (short)reader["rating"]
                            };
                        }
                    }
                }

                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "select * from storedatadlc where parentid = @p";
                    cmd.Parameters.AddWithValue("p", game.Id);

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            storeData = new StoreDataDlc()
                            {
                                Id        = (long)reader["id"],
                                StoreName = reader["storename"].ToString(),
                                StoreUrl  = reader["storeurl"].ToString(),
                                AppId     = (int)reader["appid"],
                                ParentId  = (int)reader["parentid"]
                            };
                        }
                    }
                }

                if (storeData != null)
                {
                    return(storeData.AppId);
                }
                else
                {
                    return(0);
                }
            }
        }