コード例 #1
0
        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());
            }
        }
コード例 #2
0
        //
        // GET: /Airport/Edit/5

        public ActionResult Edit(int id)
        {
            var db      = new DataAirportDataContext();
            var airport = db.Airport.SingleOrDefault(a => a.Id == id);

            ViewData.Model = airport;

            return(View());
        }
コード例 #3
0
        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());
            }
        }
コード例 #4
0
        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());
            }
        }