Пример #1
0
        public bool addParkToDb(Park p)
        {
            Park inp = new Park();
            try
            {
                inp = db.parks.Add(p);
            }

            catch (Exception e)
            {
                Exception j = e;
                return false;
                //do something
            }

            if (inp is Park)
            {
                db.SaveChanges();
                return true;
            }
            return false;
        }
Пример #2
0
        public List<Models.Park> parseParks()
        {
            CsvReader csv = new CsvReader(reader, true);
            int fieldCount = csv.FieldCount;
            List<Park> exList = new List<Park>();
            Park exObj = null;

            String[] headers = csv.GetFieldHeaders();

            while (csv.ReadNextRecord())
            {
                double lat = 0, lng = 0, theAcres = 0;
                string thePlace = null, theName = null;

                for (int i = 0; i < fieldCount; i++)
                {
                    // this is where you actually create your dB object
                    if (headers[i].Equals("Shape"))
                    {
                        parseShape(csv[i], ref lat, ref lng);
                    }
                    else if (headers[i].Equals("LOCATION"))
                    {
                        thePlace = csv[i];
                    }
                    else if (headers[i].Equals("SIGNNAME"))
                    {
                        theName = csv[i];
                    }
                    else if (headers[i].Equals("ACRES"))
                    {
                        theAcres = Convert.ToDouble(csv[i]);
                    }
                }

                exObj = new Park(lat, lng, theName, "New York", theAcres, thePlace);
                exList.Add(exObj);
            }

            return exList;

            //throw new NotImplementedException();
        }
Пример #3
0
 public bool updateParkInDb(Park p)
 {
     db.Entry(p).State = EntityState.Modified;
     try
     {
         db.SaveChanges();
         return true;
     }
     catch (Exception e)
     {
         // do something
         return false;
     }
 }