Exemple #1
0
        public async Task <IActionResult> PutFlight(string id, Flight flight)
        {
            if (id != flight.FlightId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemple #2
0
        public ActionResult Edit(Pilot pilot)
        {
            if (!User.IsManager())
            {
                return(RedirectToAction("Restricted", "Error", new { message = "Restricted to your own club" }));
            }

            if (Request.IsClub())
            {
                // There is a bug where the club from the request is bound into the resolving of the club on the pilot modelstate validation, we force this through
                // HACK: This probably means there is an evil bug hidden when we are going to save more information on club level.
                ModelState.Remove("Club");
            }

            if (!string.IsNullOrWhiteSpace(pilot.MobilNumber))
            {
                if (!MobilNumberValidator.IsValid(pilot.MobilNumber, false))
                {
                    ModelState.AddModelError("MobilNumber", "Invalid format, please use the format " + Request.PhoneNumberInternationalPrefix() + "12345678");
                }
                else
                {
                    pilot.MobilNumber = MobilNumberValidator.ParseMobilNumber(pilot.MobilNumber);
                }
            }

            if (ModelState.IsValid)
            {
                db.Entry(pilot).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.ClubId = new SelectList(db.Clubs, "ClubId", "ShortName", pilot.ClubId);
            return(View(pilot));
        }
Exemple #3
0
 public void PassEdit(Passenger passenger)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Entry(passenger).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
 public void FlightUpdate(Flight flight)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Entry(flight).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Exemple #5
0
 public void PassDelete(Passenger passenger)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Passengers.Attach(passenger);
         db.Entry(passenger).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
 public ActionResult Edit(Club club)
 {
     if (ModelState.IsValid)
     {
         db.Entry(club).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(club));
 }
Exemple #7
0
 public ActionResult Edit([Bind(Include = "ID,Description,TakeOff,Weather,Duration")] Flight flight)
 {
     if (ModelState.IsValid)
     {
         db.Entry(flight).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(flight));
 }
 public ActionResult Edit([Bind(Include = "IdFlight,IdDepartureAirport,IdDestinationAirport,FlightTime")] Flight flight)
 {
     if (ModelState.IsValid)
     {
         db.Entry(flight).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(flight));
 }
 public void FlightDelete(Flight flight)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Flights.Attach(flight);
         db.Passengers.RemoveRange(flight.Passengers);
         db.Entry(flight).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
Exemple #10
0
 public ActionResult Edit(StartType starttype)
 {
     if (ModelState.IsValid)
     {
         db.Entry(starttype).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ClubId = new SelectList(db.Clubs, "ClubId", "ShortName", starttype.ClubId);
     return(View(starttype));
 }
 public ActionResult Edit(Club club)
 {
     if (ModelState.IsValid)
     {
         db.Entry(club).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     this.ViewBag.LocationId = new SelectList(this.db.Locations.OrderBy(p => p.Name), "LocationId", "Name", (club == null) ? (object)null : club.LocationId);
     return(View(club));
 }
Exemple #12
0
 public ActionResult Edit(Plane plane)
 {
     // Created might be lost ?
     plane.LastUpdatedTimestamp = DateTime.Now;
     plane.LastUpdatedBy        = User.Pilot().ToString();
     if (ModelState.IsValid)
     {
         db.Entry(plane).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StartTypeId = new SelectList(db.StartTypes, "StartTypeId", "ShortName", plane.StartTypeId);
     return(View(plane));
 }
        public ActionResult Edit(FormCollection collection, [Bind(Include = "Date1,Email,Source,Dest,Number,Adults,Child")] Flight sbo)
        {
            // TODO: Add update logic here

            if (ModelState.IsValid)
            {
                Fdb.Entry(sbo).State = System.Data.Entity.EntityState.Modified;

                //fc.SaveChanges();
                Fdb.SaveChanges();
                return(RedirectToAction("ListOfBookings"));
            }
            return(View(sbo));
        }
 public ActionResult Edit(Location location)
 {
     location.LastUpdatedTimestamp = DateTime.Now;
     location.LastUpdatedBy        = User.Pilot().ToString();
     if (!location.ICAO.IsNullOrWhiteSpace())
     {
         location.ICAO = location.ICAO.ToUpperInvariant();
     }
     if (ModelState.IsValid)
     {
         db.Entry(location).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(location));
 }
Exemple #15
0
        private static ManagePilotBindingViewModel ManagePilotBindingViewModel(ApplicationUser user)
        {
            Pilot        userPilotBinding = null;
            List <Pilot> otherPilots      = new List <Pilot>();

            using (var context = new FlightContext())
            {
                if (user.BoundToPilotId != null)
                {
                    userPilotBinding = context.Pilots.Find(Convert.ToInt32(user.BoundToPilotId));
                    // Load club reference information
                    if (userPilotBinding != null)
                    {
                        context.Entry(userPilotBinding).Reference(p => p.Club).Load();
                    }
                }

                if (user.EmailConfirmed)
                {
                    otherPilots.AddRange(context.Pilots.Where(p => p.Email == user.Email).Include(c => c.Club).ToList());
                }

                if (user.PhoneNumberConfirmed)
                {
                    foreach (var pilot in context.Pilots.Where(p => p.MobilNumber == user.PhoneNumber).Include(c => c.Club).ToList())
                    {
                        if (!otherPilots.Exists(o => o.PilotId == pilot.PilotId))
                        {
                            otherPilots.Add(pilot);
                        }
                    }
                }

                // Remove the existing pilot
                if (userPilotBinding != null && otherPilots.Any())
                {
                    otherPilots = otherPilots.Where(p => p.PilotId != userPilotBinding.PilotId).ToList();
                }

                // Auto set primary pilot binding information
                if (string.IsNullOrEmpty(user.BoundToPilotId) && otherPilots.Count == 1)
                {
                    user.BoundToPilotId = otherPilots.First().PilotId.ToString();
                    // Save to database
                    using (var appcontext = new ApplicationDbContext())
                    {
                        var appUser = appcontext.Users.Find(user.Id);
                        if (appUser != null)
                        {
                            appUser.BoundToPilotId = user.BoundToPilotId;
                            appcontext.SaveChanges();
                        }
                    }
                    userPilotBinding = otherPilots.First();
                    otherPilots      = new List <Pilot>();
                }
            }

            var result = new ManagePilotBindingViewModel
            {
                CurrentPilotBinding    = userPilotBinding,
                PotentialPilotBindings = otherPilots
            };

            return(result);
        }
Exemple #16
0
 public void UpdateFlight(Flight flight)
 {
     context.Entry(flight).State = EntityState.Modified;
 }