public bool addMuseumToDb(Museum m) { Museum inm = new Museum(); try { inm = db.museums.Add(m); } catch (Exception e) { Exception j = e; return false; //do something } if (inm is Museum) { db.SaveChanges(); return true; } return false; }
public bool updateMuseumInDb(Museum m) { db.Entry(m).State = EntityState.Modified; try { db.SaveChanges(); return true; } catch (Exception e) { // do something return false; } }
public List<Models.Museum> parseMuseums() { CsvReader csv = new CsvReader(reader, true); int fieldCount = csv.FieldCount; List<Museum> exList = new List<Museum>(); Museum exObj = null; String[] headers = csv.GetFieldHeaders(); while (csv.ReadNextRecord()) { string cityStr = null; double lat = 0, lng = 0; string theName = null, theUrl = null, add1 = null, add2 = null, theZip = null, phone = 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("NAME")) { theName = csv[i]; } else if (headers[i].Equals("TEL")) { phone = csv[i]; } else if (headers[i].Equals("URL")) { theUrl = csv[i]; } else if (headers[i].Equals("ADRESS1")) // intentionally misspelt { add1 = csv[i]; } else if (headers[i].Equals("ADDRESS2")) { add2 = csv[i]; } else if (headers[i].Equals("ZIP")) { theZip = csv[i]; } else if (headers[i].Equals("CITY")) { cityStr = csv[i]; } } exObj = new Museum(lat, lng, theName, phone, theUrl, add1, add2, theZip, cityStr); exList.Add(exObj); } return exList; //throw new NotImplementedException(); }