public async Task <IHttpActionResult> PutFlightForm(int id, FlightForm flightForm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != flightForm.Id)
            {
                return(BadRequest());
            }

            db.Entry(flightForm).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
 public static void AddFlight(FlightForm flight, int avioId)
 {
     using (var _context = new DiemServiceDB())
     {
         if (flight.FlightClass == 0 || flight.seats == 0 || flight.Flight_Arrival_Time == null || flight.Flight_Departure_Time == null || flight.fromLocation == null || flight.toLocation == null || flight.price == null ||
             flight.Flight_Departure_Time < DateTime.Now ||
             flight.Flight_Departure_Time.Date > flight.Flight_Arrival_Time.Date
             )
         {
             throw new Exception("BAD QEURY");
         }
         string      caller     = ((ClaimsPrincipal)HttpContext.Current.User).FindFirst("username").Value;
         User        loggedUser = _context.UserDbSet.Where(u => u.Username == caller).FirstOrDefault();
         AvioCompany found      = _context.AvioCompanyDbSet.Where(u => u.Id == avioId).Include(x => x.Owner).FirstOrDefault();
         if (loggedUser.Role != Role.Admin && loggedUser.Username != found.Owner.Username)
         {
             return;
         }
         Flight toAdd = flight.toFlight();
         toAdd.To_Location   = _context.LocationDbSet.Add(toAdd.To_Location);
         toAdd.From_Location = _context.LocationDbSet.Add(toAdd.From_Location);
         toAdd.Provider      = found;
         found.Flights.Add(_context.FlightDbSet.Add(toAdd));
         _context.SaveChanges();
     }
 }
Esempio n. 3
0
        private void ButtonAddDisplayerRequested(object sender, ReferenceEventArgs e)
        {
            var form = new FlightForm(_currentATLB, CurrentAircraft);

            if (form.ShowDialog() == DialogResult.OK)
            {
                AnimatedThreadWorker.RunWorkerAsync();
            }
        }
Esempio n. 4
0
 public static void AvioAddFlight(FlightForm flight)
 {
     using (var _context = new DiemServiceDB())
     {
         Flight toAdd = flight.toFlight();
         toAdd.To_Location   = _context.LocationDbSet.Add(toAdd.To_Location);
         toAdd.From_Location = _context.LocationDbSet.Add(toAdd.From_Location);
         _context.FlightDbSet.Add(toAdd);
         _context.SaveChanges();
     }
 }
        public async Task <IHttpActionResult> GetFlightForm(int id)
        {
            FlightForm flightForm = await db.FlightForm.FindAsync(id);

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

            return(Ok(flightForm));
        }
        public async Task <IHttpActionResult> PostFlightForm(FlightForm flightForm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.FlightForm.Add(flightForm);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = flightForm.Id }, flightForm));
        }
        public async Task <IHttpActionResult> DeleteFlightForm(int id)
        {
            FlightForm flightForm = await db.FlightForm.FindAsync(id);

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

            db.FlightForm.Remove(flightForm);
            await db.SaveChangesAsync();

            return(Ok(flightForm));
        }
Esempio n. 8
0
 public HttpResponseMessage AddFlight([FromUri] int avioCompanyId, [FromBody] FlightForm form)
 {
     FlightDbManager.AddFlight(form, avioCompanyId);
     return(Request.CreateResponse(HttpStatusCode.OK));
 }