/// <summary>
        /// Reads property details about each property from a csv
        /// </summary>
        /// <returns>A list of PropertyDetails objects, each representing a specific property to be added to the board</returns>
        public List<PropertyDetails> ReadPropertyDetailsFromCSV()
        {
            try
            {
                var reader = new StreamReader(File.OpenRead("propertydetails.csv"));
                var propertyDetailsFromCSV = new List<PropertyDetails>();

                while (!reader.EndOfStream)
                {
                    var propertyDetailsRow = new PropertyDetails();

                    var line = reader.ReadLine();
                    if (line.Contains("Type")) continue;// Ignore the column headings

                    var values = line.Split(',');

                    // Each type of property will not have a value for every field so
                    // we must check that before assigning it
                    if (!string.IsNullOrEmpty(values[0])) propertyDetailsRow.Type = values[0];
                    if (!string.IsNullOrEmpty(values[1])) propertyDetailsRow.Name = values[1];
                    if (!string.IsNullOrEmpty(values[2])) propertyDetailsRow.Price = Convert.ToDecimal(values[2]);
                    if (!string.IsNullOrEmpty(values[3])) propertyDetailsRow.Rent = Convert.ToDecimal(values[3]);
                    if (!string.IsNullOrEmpty(values[4])) propertyDetailsRow.HouseCost = Convert.ToDecimal(values[4]);
                    if (!string.IsNullOrEmpty(values[5])) propertyDetailsRow.IsPenalty = Convert.ToBoolean(values[5]);
                    if (!string.IsNullOrEmpty(values[6])) propertyDetailsRow.Amount = Convert.ToDecimal(values[6]);
                    if (!string.IsNullOrEmpty(values[7])) propertyDetailsRow.HouseColour = values[7];

                    propertyDetailsFromCSV.Add(propertyDetailsRow);

                }

                return propertyDetailsFromCSV;
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads property details about each property from a csv
        /// </summary>
        /// <returns>A list of PropertyDetails objects, each representing a specific property to be added to the board</returns>
        public List <PropertyDetails> ReadPropertyDetailsFromCSV()
        {
            try
            {
                var reader = new StreamReader(File.OpenRead("propertydetails.csv"));
                var propertyDetailsFromCSV = new List <PropertyDetails>();

                while (!reader.EndOfStream)
                {
                    var propertyDetailsRow = new PropertyDetails();

                    var line = reader.ReadLine();
                    if (line.Contains("Type"))
                    {
                        continue;                       // Ignore the column headings
                    }
                    var values = line.Split(',');

                    // Each type of property will not have a value for every field so
                    // we must check that before assigning it
                    if (!string.IsNullOrEmpty(values[0]))
                    {
                        propertyDetailsRow.Type = values[0];
                    }
                    if (!string.IsNullOrEmpty(values[1]))
                    {
                        propertyDetailsRow.Name = values[1];
                    }
                    if (!string.IsNullOrEmpty(values[2]))
                    {
                        propertyDetailsRow.Price = Convert.ToDecimal(values[2]);
                    }
                    if (!string.IsNullOrEmpty(values[3]))
                    {
                        propertyDetailsRow.Rent = Convert.ToDecimal(values[3]);
                    }
                    if (!string.IsNullOrEmpty(values[4]))
                    {
                        propertyDetailsRow.HouseCost = Convert.ToDecimal(values[4]);
                    }
                    if (!string.IsNullOrEmpty(values[5]))
                    {
                        propertyDetailsRow.IsPenalty = Convert.ToBoolean(values[5]);
                    }
                    if (!string.IsNullOrEmpty(values[6]))
                    {
                        propertyDetailsRow.Amount = Convert.ToDecimal(values[6]);
                    }
                    if (!string.IsNullOrEmpty(values[7]))
                    {
                        propertyDetailsRow.HouseColour = values[7];
                    }

                    propertyDetailsFromCSV.Add(propertyDetailsRow);
                }

                return(propertyDetailsFromCSV);
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }
        }