private void PreparePublisher(PesawatModel model)
 {
     model.Maskapais = context.Maskapais.AsQueryable <Maskapai>().Select
                       (
         x => new SelectListItem()
     {
         Text  = x.NamaMaskapai,
         Value = x.Id.ToString()
     }
                       );
     model.Tipes = context.Tipes.AsQueryable <Tipe>().Select
                   (
         x => new SelectListItem()
     {
         Text  = x.TipePesawat,
         Value = x.Id.ToString()
     }
                   );
     model.Pilots = context.Pilots.AsQueryable <Pilot>().Select
                    (
         x => new SelectListItem()
     {
         Text  = x.NamaPilot,
         Value = x.Id.ToString()
     }
                    );
 }
        public ActionResult Create()
        {
            PesawatModel model = new PesawatModel();

            PreparePublisher(model);
            return(View(model));
        }
        public ActionResult Delete(PesawatModel model)
        {
            Pesawat pesawat = context.Pesawats.Where(e => e.Id == model.Id).
                              SingleOrDefault();

            context.Pesawats.DeleteOnSubmit(pesawat);
            context.SubmitChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult Details(int Id)
        {
            PesawatModel model = context.Pesawats.Where(c => c.Id == Id).Select(
                c => new PesawatModel()
            {
                NamaMaskapai = c.Maskapai.NamaMaskapai,
                Jadwal       = c.Jadwal,
                TipePesawat  = c.Tipe.TipePesawat,
                NamaPilot    = c.Pilot.NamaPilot
            }).SingleOrDefault();

            return(View(model));
        }
        public ActionResult Create(PesawatModel model)
        {
            Pesawat pesawat = new Pesawat()
            {
                MaskapaiId = model.MaskapaiId,
                Jadwal     = model.Jadwal,
                TipeId     = model.TipeId,
                PilotId    = model.PilotId
            };

            context.Pesawats.InsertOnSubmit(pesawat);
            context.SubmitChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(PesawatModel model)
        {
            Pesawat pesawat = context.Pesawats.Where(e => e.Id == model.Id).
                              SingleOrDefault();

            pesawat.MaskapaiId = model.MaskapaiId;
            pesawat.Jadwal     = model.Jadwal;
            pesawat.TipeId     = model.TipeId;
            pesawat.PilotId    = model.PilotId;

            context.SubmitChanges();

            return(RedirectToAction("Index"));
        }