public void parseHolidayhomesTest1() { StreamReader reader = new StreamReader("d:\\nci\\holidayhomes.csv"); CSVParser target = new CSVParser(); target.setStreamSource(reader); Holidayhome hse = new Holidayhome(); hse.holidayhomeno = "Spain"; hse.address1 = "San Costa"; hse.address2 = "Valencia"; hse.country = "Spain"; hse.email = "*****@*****.**"; hse.contactno = "+353 18767352"; hse.amenities = "Swimming Pool| Gym | Sauna"; hse.price = "445"; List <Holidayhome> expected = new List <Holidayhome>(); expected.Add(hse); List <Holidayhome> actual = target.parseHolidayhomes(); Assert.AreEqual(expected[0].address1, actual[0].address1); Assert.AreEqual(expected[0].country, actual[0].country); Assert.AreEqual(expected[0].contactno, actual[0].contactno); }
public bool updateHolidayhomeDb(Holidayhome hse) { db.Entry(hse).State = EntityState.Modified; db.SaveChanges(); return(true); }
public ActionResult DeleteConfirmed(int id) { Holidayhome holidayhome = db.Holidayhomes.Find(id); db.Holidayhomes.Remove(holidayhome); db.SaveChanges(); return(RedirectToAction("Index")); }
//Create List to store your CSV data public List <Models.Holidayhome> parseHolidayhomes() { CsvReader csv = new CsvReader(reader, true); int fieldCount = csv.FieldCount; List <Holidayhome> holidaylist = new List <Holidayhome>(); String[] headers = csv.GetFieldHeaders(); while (csv.ReadNextRecord()) { Holidayhome exObj = new Holidayhome(); for (int i = 0; i < fieldCount; i++) { if (headers[i].Equals("holidayhomeno")) { exObj.holidayhomeno = csv[i]; } else if (headers[i].Equals("address1")) { exObj.address1 = csv[i]; } else if (headers[i].Equals("address2")) { exObj.address2 = csv[i]; } else if (headers[i].Equals("country")) { exObj.country = csv[i]; } else if (headers[i].Equals("email")) { exObj.email = csv[i]; } else if (headers[i].Equals("contactno")) { exObj.contactno = csv[i]; } else if (headers[i].Equals("amenities")) { exObj.amenities = csv[i]; } else if (headers[i].Equals("price")) { exObj.price = csv[i]; } } holidaylist.Add(exObj); } return(holidaylist); }
public ActionResult Edit(Holidayhome holidayhome) { if (ModelState.IsValid) { db.Entry(holidayhome).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(holidayhome)); }
// // GET: /Holidayhome/Delete/5 public ActionResult Delete(int id, bool?saveChangesError) { if (saveChangesError.GetValueOrDefault()) { ViewBag.ErrorMessage = "Unable to save changes. Try again, and if the problem persists see your system administrator."; } Holidayhome Holidayhome = HolidayhomeRepository.GetHolidayhomeByID(id); return(View(Holidayhome)); }
public ActionResult Create(Holidayhome holidayhome) { if (ModelState.IsValid) { db.Holidayhomes.Add(holidayhome); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(holidayhome)); }
//Create List to store your CSV data List <Models.Holidayhome> IDataParser.parseHolidayhomes() { CsvReader csv = new CsvReader(reader, true); int fieldCount = csv.FieldCount; List <Holidayhome> holidayhomes = new List <Holidayhome>(); String[] headers = csv.GetFieldHeaders(); Holidayhome exObj = new Holidayhome(); while (csv.ReadNextRecord()) { for (int i = 0; i < fieldCount; i++) { if (headers[i].Equals("location")) { exObj.location = csv[i]; } else if (headers[i].Equals("address1")) { exObj.address1 = csv[i]; } else if (headers[i].Equals("address2")) { exObj.address2 = csv[i]; } else if (headers[i].Equals("country")) { exObj.country = csv[i]; } else if (headers[i].Equals("email")) { exObj.email = csv[i]; } else if (headers[i].Equals("contactno")) { exObj.contactno = csv[i]; } else if (headers[i].Equals("amenities")) { exObj.amenities = csv[i]; } } holidayhomes.Add(exObj); } return(holidayhomes); }
public bool updateHolidayhomeDb(Holidayhome hse) { db.Entry(hse).State = EntityState.Modified; try { db.SaveChanges(); return(true); } catch (Exception exp) { // do something return(false); } }
public bool addHolidayhomeDb(Holidayhome hse) { Holidayhome home = new Holidayhome(); home = db.Holidayhomes.Add(hse); if (home is Holidayhome) { db.SaveChanges(); return(true); } return(false); }
public ActionResult Create(Holidayhome Holidayhome) { try { if (ModelState.IsValid) { HolidayhomeRepository.InsertHolidayhome(Holidayhome); HolidayhomeRepository.Save(); return(RedirectToAction("Index")); } } catch (DataException) { //Log the error (add a variable name after DataException) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(Holidayhome)); }
public ActionResult DeleteConfirmed(int id) { try { Holidayhome Holidayhome = HolidayhomeRepository.GetHolidayhomeByID(id); HolidayhomeRepository.DeleteHolidayhome(id); HolidayhomeRepository.Save(); } catch (DataException) { //Log the error (add a variable name after DataException) return(RedirectToAction("Delete", new System.Web.Routing.RouteValueDictionary { { "id", id }, { "saveChangesError", true } })); } return(RedirectToAction("Index")); }
public bool addHolidayhomeDb(Holidayhome hse) { Holidayhome home = new Holidayhome(); try { home = db.Holidayhomes.Add(hse); } catch (Exception exp) { Exception j = exp; return(false); //do something } if (home is Holidayhome) { db.SaveChanges(); return(true); } return(false); }
public void DeleteHolidayhome(int HolidayhomeID) { Holidayhome Holidayhome = context.Holidayhomes.Find(HolidayhomeID); context.Holidayhomes.Remove(Holidayhome); }
public void UpdateHolidayhome(Holidayhome Holidayhome) { context.Entry(Holidayhome).State = EntityState.Modified; }
public void InsertHolidayhome(Holidayhome Holidayhome) { context.Holidayhomes.Add(Holidayhome); }
// // GET: /Holidayhome/Details/5 public ViewResult Details(int id) { Holidayhome Holidayhome = HolidayhomeRepository.GetHolidayhomeByID(id); return(View(Holidayhome)); }
// // GET: /Holidayhome/Delete/5 public ActionResult Delete(int id) { Holidayhome holidayhome = db.Holidayhomes.Find(id); return(View(holidayhome)); }
} // public ActionResult Edit(int id) { Holidayhome Holidayhome = HolidayhomeRepository.GetHolidayhomeByID(id); return(View(Holidayhome)); }
// // GET: /Holidayhome/Details/5 public ViewResult Details(int id) { Holidayhome holidayhome = db.Holidayhomes.Find(id); return(View(holidayhome)); }