Пример #1
0
        public static double GetValue(string scoringIdName, CityInfo city, DatabaseContext db)
        {
            ScoringIdentifier scoringId = db.ScoringIdentifiers.First(s => s.Name.Equals(scoringIdName) || s.ShortName.Equals(scoringIdName));

            object objVal = city.GetType().GetProperty(scoringId.PropertyName).GetValue(city);
            double value;

            if (objVal.GetType() == typeof(int))
            {
                value = (double)(int)objVal;
            }
            else
            {
                // Identifier validity should have already been checked, so this should be a double.
                value = (double)objVal;
            }

            return value;
        }
Пример #2
0
        private static void storeCity(City parserCity, string username, string filepath, Stream cityFileStream)
        {
            // Fetch relevant data from parserCity.
            var city = new CityInfo(parserCity, username, filepath, DateTime.Now);

            // Save .sc2 file on the server.
            cityFileStream.Position = 0;
            using (Stream outputStream = File.OpenWrite(filepath))
            {
                cityFileStream.CopyTo(outputStream);
            }

            // Save parsed city data to database.
            using (var db = new DatabaseContext())
            {
                db.CityInfoes.Add(city);
                db.SaveChanges();
            }
        }