Ejemplo n.º 1
0
        public async Task <IActionResult> PutAirplaneType(int id, AirplaneType airplaneType)
        {
            if (id != airplaneType.AirplaneId)
            {
                return(BadRequest());
            }

            _context.Entry(airplaneType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AirplaneTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public void Post([FromBody] AirplaneType airplaneType)
 {
     if (ModelState.IsValid)
     {
         service.Create(airplaneType);
     }
 }
        private async void btnDelete_Click(object sender, EventArgs e)
        {
            // Lay may bay dang duoc chon trong bang
            AirplaneType airplaneType = GetSelectedAirplaneType();

            // Neu hien tai khong co may bay nao duoc chon thi hien thong bao
            if (airplaneType == null)
            {
                MessageBox.Show("You must choose an airplane to edit!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // Neu co may bay dang duoc chon thi sua cot IsActive lai thanh False
            airplaneType.IsActive = false;

            // Gui len server de cap nhat lai cot IsActive trong CSDL
            AirplaneTypeWrapper airplaneTypeWrapper = new AirplaneTypeWrapper();
            bool isSuccess = await airplaneTypeWrapper.Put(airplaneType.ID, airplaneType);

            // Kiem tra ket qua tra ve
            if (isSuccess)
            {
                // Neu ket qua la thanh cong, hien thong bao thanh cong
                MessageBox.Show("Airplane type was set to inactive!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

                // Load lai bang
                LoadDataGridView();
            }
            else
            {
                // Neu ket qua that bai, hien thong bao loi
                MessageBox.Show("An error has occurred!\n" + airplaneTypeWrapper.GetErrorMessage(), "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 4
0
        public static Double GetLegQuickQuote(Airfield Source, Airfield Destination, AirplaneType at)
        {
            try
            {
                Double distance   = Source.GetDistaneFrom(Destination);
                Double flyingtime = at.CalculateTimeToTravelDistance(distance);

                Double TOTAL_QUOTE;

                if (flyingtime == 0)
                {
                    TOTAL_QUOTE = 0;
                }
                else
                {
                    if (flyingtime * 2 < 2)
                    {
                        flyingtime  = 2;
                        TOTAL_QUOTE = (flyingtime * at.GetRateForCurrentSession().HourlyRate) / 2;
                    }
                    else
                    {
                        TOTAL_QUOTE = flyingtime * at.GetRateForCurrentSession().HourlyRate;
                    }
                }
                return(TOTAL_QUOTE);
            }
            catch (Exception ex)
            {
                throw new AdminException("Airfields Not Found. Use Autocomplete feature");
            }
        }
 public void Put(int id, [FromBody] AirplaneType airplaneType)
 {
     if (ModelState.IsValid)
     {
         service.Update(id, airplaneType);
     }
 }
Ejemplo n.º 6
0
        public static IList <AirplaneTypeRate> GetRateForCountryAndAirplaneType(AirplaneType at, Country c)
        {
            ICriteria cr = NHibernateHelper.GetCurrentSession().CreateCriteria(typeof(AirplaneTypeRate));

            cr.Add(Restrictions.Eq("Country", c));
            cr.Add(Restrictions.Eq("PlaneType", at));
            return(cr.List <AirplaneTypeRate>());
        }
Ejemplo n.º 7
0
        public ActionResult DeleteConfirmed(int id)
        {
            AirplaneType airplaneType = db.AirplaneTypes.Find(id);

            db.AirplaneTypes.Remove(airplaneType);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
        public FormAirplaneTypeCE(AirplaneType airplaneType = null, FormMode mode = FormMode.CREATE)
        {
            InitializeComponent();

            // Luu flightSchedule account ben FormList truyen sang
            this.airplaneType = airplaneType;

            // Luu che do (tao moi hay chinh sua)
            this.mode = mode;
        }
Ejemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "Id,Name")] AirplaneType airplaneType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(airplaneType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(airplaneType));
 }
        public AirplaneTypeView()
        {
            this.InitializeComponent();

            AirplaneTypes                 = new ObservableCollection <AirplaneType>();
            SelectedAirplaneType          = new AirplaneType();
            _service                      = new AirplaneTypesDataLoadService();
            AirplaneTypesList.ItemsSource = AirplaneTypes;
            AddButton.Visibility          = Visibility.Collapsed;
            SaveButton.Visibility         = Visibility.Collapsed;
        }
Ejemplo n.º 11
0
        public ActionResult Create([Bind(Include = "Id,Name")] AirplaneType airplaneType)
        {
            if (ModelState.IsValid)
            {
                db.AirplaneTypes.Add(airplaneType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(airplaneType));
        }
Ejemplo n.º 12
0
 public ActionResult Edit([Bind(Include = "Id,Name,AirportId")] AirplaneType airplaneType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(airplaneType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AirportId = new SelectList(db.Airports, "Id", "Name", airplaneType.AirportId);
     return(View(airplaneType));
 }
        public IHttpActionResult GetAirplaneType(int id)
        {
            AirplaneType airplaneType = db.AirplaneTypes.Find(id);

            if (airplaneType == null)
            {
                return(NotFound());
            }

            return(Ok(airplaneType));
        }
        public void OnSelectedItem(object sender, RoutedEventArgs e)
        {
            SelectedAirplaneType = GetSelected(sender, e);

            if (SelectedAirplaneType != null)
            {
                TextId.Text               = SelectedAirplaneType.Id.ToString();
                TextAirplaneModel.Text    = SelectedAirplaneType.AirplaneModel;
                TextSeatsCount.Text       = SelectedAirplaneType.SeatsCount.ToString();
                TextCarryingCapacity.Text = SelectedAirplaneType.CarryingCapacity.ToString();
            }
        }
Ejemplo n.º 15
0
 private double GetEstimatedFuelConsumptionPerFlightMeter(AirplaneType airplaneType)
 {
     if (AirplaneType.Large == airplaneType)
     {
         return(4.56);
     }
     else if (AirplaneType.Small == airplaneType)
     {
         return(1.34);
     }
     return(3.23);
 }
Ejemplo n.º 16
0
        public ActionResult Create([Bind(Include = "Id,Name,AirportId")] AirplaneType airplaneType)
        {
            if (ModelState.IsValid)
            {
                db.AirplaneTypes.Add(airplaneType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AirportId = new SelectList(db.Airports, "Id", "Name", airplaneType.AirportId);
            return(View(airplaneType));
        }
Ejemplo n.º 17
0
        public double GetEstimatedFuelNeedInMeters(double distanceInMetres,
                                                   AirplaneType airplaneType = AirplaneType.Medium, int averageEstimatedAltitude = 9000)
        {
            const double reserve             = 2000;
            var          consumptionPerMeter = GetEstimatedFuelConsumptionPerFlightMeter(airplaneType);
            var          altitudeCoeficient  = GetAltitudeCoeficient(averageEstimatedAltitude);
            double       litres = reserve
                                  + consumptionPerMeter * distanceInMetres
                                  + altitudeCoeficient * distanceInMetres;

            return(litres);
        }
Ejemplo n.º 18
0
        public async Task <StatusCode> Delete(AirplaneType entity)
        {
            var type = await AirplaneType.GetById(entity.Id);

            if (type != null)
            {
                await AirplaneType.Delete(entity.Id);

                return(StatusCode.Deleted);
            }
            return(StatusCode.DoesNotExist);
        }
Ejemplo n.º 19
0
        public async Task <StatusCode> Update(AirplaneType entity)
        {
            var type = await AirplaneType.GetById(entity.Id);

            if (type != null)
            {
                Validation(entity);
                await AirplaneType.Update(entity.ToEntity());

                return(StatusCode.Updated);
            }
            return(StatusCode.DoesNotExist);
        }
        public IHttpActionResult DeleteAirplaneType(int id)
        {
            AirplaneType airplaneType = db.AirplaneTypes.Find(id);

            if (airplaneType == null)
            {
                return(NotFound());
            }

            db.AirplaneTypes.Remove(airplaneType);
            db.SaveChanges();

            return(Ok(airplaneType));
        }
Ejemplo n.º 21
0
        // GET: AirplaneTypes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AirplaneType airplaneType = db.AirplaneTypes.Find(id);

            if (airplaneType == null)
            {
                return(HttpNotFound());
            }
            return(View(airplaneType));
        }
Ejemplo n.º 22
0
        // GET: AirplaneTypes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AirplaneType airplaneType = db.AirplaneTypes.Find(id);

            if (airplaneType == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AirportId = new SelectList(db.Airports, "Id", "Name", airplaneType.AirportId);
            return(View(airplaneType));
        }
Ejemplo n.º 23
0
        public async Task <StatusCode> Create(AirplaneType entity)
        {
            Validation(entity);
            var types = await AirplaneType.GetBy(entity.Name);

            var isExist = types != null;

            if (isExist)
            {
                return(StatusCode.AlreadyExists);
            }

            await AirplaneType.Create(entity.ToEntity());

            return(StatusCode.Created);
        }
Ejemplo n.º 24
0
        public ActionResult DeleteConfirmed(int id)
        {
            AirplaneType airplaneType = db.AirplaneTypes.Find(id);

            //foreach (var item in db.Airplanes)
            //{
            //    if (item.AirplaneType == airplaneType)
            //    {
            //        item.AirplaneType = null;
            //    }
            //}


            db.AirplaneTypes.Remove(airplaneType);

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        private AirplaneType GetSelectedAirplaneType()
        {
            // Neu khong co dong nao dang duoc chon thi tra ve null
            if (dgvAirplaneType.SelectedRows.Count != 1)
            {
                return(null);
            }

            // Neu co 1 dong dang duoc chon thi lay dong do ra
            DataGridViewRow row = dgvAirplaneType.SelectedRows[0];

            // Lay du lieu trong dong do va tao ra mot Airplane moi
            AirplaneType airplaneType = new AirplaneType()
            {
                ID             = Convert.ToInt32(row.Cells["ID"].Value),
                Name           = row.Cells["Name"].Value.ToString(),
                AirplaneInfoes = new List <AirplaneInfo>()
                {
                    new AirplaneInfo()
                    {
                        AirplaneTypeID = Convert.ToInt32(row.Cells["ID"].Value),
                        ClassID        = 1,
                        SeatCount      = Convert.ToInt32(row.Cells["FirstClassSeat"].Value),
                    },
                    new AirplaneInfo()
                    {
                        AirplaneTypeID = Convert.ToInt32(row.Cells["ID"].Value),
                        ClassID        = 2,
                        SeatCount      = Convert.ToInt32(row.Cells["BusinessClassSeat"].Value),
                    },
                    new AirplaneInfo()
                    {
                        AirplaneTypeID = Convert.ToInt32(row.Cells["ID"].Value),
                        ClassID        = 3,
                        SeatCount      = Convert.ToInt32(row.Cells["ClubClassSeat"].Value),
                    }
                },
                IsActive = Convert.ToBoolean(row.Cells["IsActive"].Value)
            };

            // Tra Airplane vua tao ve
            return(airplaneType);
        }
Ejemplo n.º 26
0
        public static IList <AirplaneTypeRate> GetAllRates(NameValueCollection pars)
        {
            ICriteria cr = NHibernateHelper.GetCurrentSession().CreateCriteria(typeof(AirplaneTypeRate));
            Country   c  = AdminDAO.GetCountryByID(pars.Get("country"));

            if (pars.Get("country") != null)
            {
                cr.Add(Restrictions.Eq("Country", c));
            }
            AirplaneType at = OperatorDAO.FindAircraftTypeByID(pars.Get("aircrafttype"));

            if (pars.Get("aircrafttype") != null)
            {
                cr.Add(Restrictions.Eq("PlaneType", at));
            }


            cr.AddOrder(new Order("Country", false));
            return(cr.List <AirplaneTypeRate>());
        }
Ejemplo n.º 27
0
        public async Task <ActionResult <AirplaneType> > PostAirplaneType(AirplaneType airplaneType)
        {
            _context.AirplaneType.Add(airplaneType);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (AirplaneTypeExists(airplaneType.AirplaneId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetAirplaneType", new { id = airplaneType.AirplaneId }, airplaneType));
        }
Ejemplo n.º 28
0
        public IAirplane Create(AirplaneType type)
        {
            switch (type)
            {
            case AirplaneType.CessnaSingleEngine:
                return(new CessnaSingleEngine());

            case AirplaneType.CessnaMultiEngine:
                return(new CessnaMultiEngine());

            case AirplaneType.PiperSingleEngine:
                return(new PiperSingleEngine());

            case AirplaneType.PiperMultiEnginePressurized:
                return(new PiperMultiEnginePressurized());

            //case AirplaneType.CessnaCitation:
            //    return new CessnaCitation();
            default:
                throw new Exception("Unknown Aircraft Type!");
            }
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            // Lay tai khoan admin dang duoc chon trong bang
            AirplaneType airplaneType = GetSelectedAirplaneType();

            // Neu hien tai khong co tai khoan nao duoc chon thi hien thong bao
            if (airplaneType == null)
            {
                MessageBox.Show("You must choose an aiplane to edit!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // Neu co tai khoan dang duoc chon thi hien form chinh sua thong tin len, truyen du lieu qua
            FormAirplaneTypeCE f = new FormAirplaneTypeCE(airplaneType, HelperClass.FormMode.EDIT);

            // f.MdiParent = this.MdiParent;

            // Hien form Edit len va doi cho den khi form bi tat di
            f.ShowDialog();

            // Load lai bang sau khi form Edit da tat
            LoadDataGridView();
        }
        public IHttpActionResult PostAirplaneType(AirplaneType airplaneType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                db.AirplaneTypes.Add(airplaneType);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                return(Content(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(CreatedAtRoute("DefaultApi", new { id = airplaneType.ID }, airplaneType));
        }