public ActionResult Edit(Owner owner) { if (ModelState.IsValid) { db.Entry(owner).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(owner); }
public ActionResult Create(Owner owner) { if (ModelState.IsValid) { db.Owners.Add(owner); db.SaveChanges(); return RedirectToAction("Index"); } return View(owner); }
public void updateOwnerDbTest() { OwnerDAL target = new OwnerDAL(); bool expected = true; bool actual; Owner check =new Owner(); check.firstname = "Alexander"; check.surname = "Carson"; check.address1 = "92 Margarenstrasse"; check.address2 = "Vienna"; check.country = "Italy"; check.email = "*****@*****.**"; check.contactno = "+353 67639287828"; check.holidayhomeno = "9876"; actual = target.updateOwnerDb(check); Assert.AreEqual(expected, actual); }
public ActionResult Create(Owner Owner) { try { if (ModelState.IsValid) { OwnerRepository.InsertOwner(Owner); OwnerRepository.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(Owner); }
public bool addOwnerDb(Owner own) { Owner owr = new Owner(); try { owr = db.Owners.Add(own); } catch (Exception exp) { Exception j = exp; return false; } if (owr is Owner) { db.SaveChanges(); return true; } return false; }
public void parseOwnersTest() { StreamReader reader = new StreamReader("d:\\nci\\owners.csv"); CSVParser target = new CSVParser(); target.setStreamSource(reader); Owner owns = new Owner(); owns.firstname="Alexander"; owns.surname="Carson"; owns.address1="92 Margarenstrasse"; owns.address2="Vienna"; owns.country = "Italy"; owns.email="*****@*****.**"; owns.contactno="+353 67639287828"; owns.holidayhomeno="9876"; List<Owner> expected = new List<Owner>(); expected.Add(owns); List<Owner> actual; actual = target.parseOwners(); 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 updateOwnerDb(Owner own) { db.Entry(own).State = EntityState.Modified; db.SaveChanges(); return true; }
public void UpdateOwner(Owner Owner) { context.Entry(Owner).State = EntityState.Modified; }
public void InsertOwner(Owner Owner) { context.Owners.Add(Owner); }
//Create List to store your CSV data public List<Models.Owner> parseOwners() { CsvReader csv = new CsvReader(reader, true); int fieldCount = csv.FieldCount; List<Owner> ownerlist = new List<Owner>(); String[] headers = csv.GetFieldHeaders(); while (csv.ReadNextRecord()) { Owner exObj = new Owner(); for (int i = 0; i < fieldCount; i++) { if (headers[i].Equals("firstname")) { exObj.firstname = csv[i]; } else if (headers[i].Equals("surname")) { exObj.surname = 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("holidayhomeno")) { exObj.holidayhomeno = csv[i]; } } ownerlist.Add(exObj); } return ownerlist; }