public ActionResult Edit(int id, FormCollection collection) { try { // TODO: Add update logic here //DataContext db = new DataContext(@"D:\KPI\Технології створення програмних продуктів\AviaMvcApp\DB\AviaDB.mdf"); var db = new DataAirportDataContext(); var airport = db.Airport.SingleOrDefault(a => a.Id == id); if (collection["Name"] == "") { return(RedirectToAction("Index")); } airport.Name = collection["Name"]; airport.Adress = collection["Adress"]; db.SubmitChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here var db = new DataAirportDataContext(); var airport = db.Airport.SingleOrDefault(a => a.Id == id); airport.Name = collection["Name"]; airport.Adress = collection["Adress"]; db.Airport.DeleteOnSubmit(airport); db.SubmitChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here var db = new DataAirportDataContext(); Airport airport = new Airport(); /*var airport = db.Airport.SingleOrDefault(a => a.Id == collection["Id"]);*/ airport.Id = db.Airport.Count() + 1; airport.Name = collection["Name"]; airport.Adress = collection["Adress"]; db.Airport.InsertOnSubmit(airport); db.SubmitChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }