示例#1
0
        // POST
        public void Add(Employee NewEmployee)
        {
            // define function for generating a random number
            const string chars  = "0123456789";
            Random       random = new Random();

            string RandomString(int length)
            {
                return(new string(Enumerable.Repeat(chars, length)
                                  .Select(s => s[random.Next(s.Length)]).ToArray()));
            }

            bool noMatch = true;
            // Fetch all emplyee numbers
            var employeeNumbers = _context.Employees.Select(employee => employee.EmployeeNumber).ToList();

            while (noMatch)
            {
                // If random number doesnt exist in database, bind it and persist newEmployee
                string randomNumber = RandomString(5);
                if (!employeeNumbers.Contains(randomNumber))
                {
                    NewEmployee.EmployeeNumber = randomNumber;
                    noMatch = false;
                }
            }

            _context.Add(NewEmployee);
            _context.SaveChanges();
        }
示例#2
0
        public ActionResult Create(Pilot model)
        {
            if (!User.IsManager())
            {
                return(RedirectToAction("Restricted", "Error", new { message = "Restricted to your own club" }));
            }

            // Create the pilot on the managers club if not it is invalid
            if (!User.IsAdministrator() &&
                model.ClubId != User.Pilot().ClubId)
            {
                return(RedirectToAction("Restricted", "Error", new { message = "Trying to create pilot in club where you are not a manager... " }));
            }

            // Resolve club information manually to avoid conflict with club route
            //model.Club = db.Clubs.Find(model.ClubId);

            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 (ModelState.IsValid)
            {
                db.Pilots.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ClubId = new SelectList(db.Clubs, "ClubId", "Name", model.ClubId);
            return(View(model));
        }
示例#3
0
        public IActionResult Add(FlightViewModel model, string returnUrtl = null)
        {
            var flight = new Flight {
                Id                 = model.Id,
                Airplane           = _dbContext.Airplanes.Find(model.AirplaneId),
                AviaCompany        = _dbContext.AviaCompanies.Find(model.AviaCompanyId),
                HomeAirport        = _dbContext.Airports.Find(model.HomeAirportId),
                DestinationAirport = _dbContext.Airports.Find(model.DestinationAirportId),
                Departure          = model.Departure,
                Arrival            = model.Arrival
            };
            var curFlights = _dbContext.Flights.ToList().OrderByDescending(item => item.Id);

            if (curFlights == null)
            {
                flight.Id = 1;
            }
            else
            {
                flight.Id = curFlights.First().Id + 1;
            }
            _dbContext.Flights.Add(flight);
            _dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#4
0
        // POST
        public void Add(Plane newPlane)
        {
            // define function for generating a random identifier
            const string LetterPool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            const string NumberPool = "1234567890";
            Random       random     = new Random();

            string RandomString(int Length)
            {
                string part1 = new string(Enumerable.Repeat(NumberPool, Length / 2)
                                          .Select(s => s[random.Next(s.Length)]).ToArray());
                string part2 = new string(Enumerable.Repeat(LetterPool, Length / 2)
                                          .Select(s => s[random.Next(s.Length)]).ToArray());

                return(part1 + part2);
            }

            bool NoMatch = true;
            // Fetch all identifiers
            var Identifiers = _context.Planes.Select(plane => plane.Identifier).ToList();

            while (NoMatch)
            {
                // If random identifier doesnt exist in database, bind it and persist newPlane
                string RandomIndentifier = RandomString(6);
                if (!Identifiers.Contains(RandomIndentifier))
                {
                    newPlane.Identifier = RandomIndentifier;
                    NoMatch             = false;
                }
            }

            _context.Add(newPlane);
            _context.SaveChanges();
        }
示例#5
0
        public ActionResult Create([Bind(Include = "IdFlight,IdDepartureAirport,IdDestinationAirport,FlightTime")] Flight flight)
        {
            if (ModelState.IsValid)
            {
                db.Flights.Add(flight);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(flight));
        }
        public ActionResult Create(Club club)
        {
            if (ModelState.IsValid)
            {
                db.Clubs.Add(club);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(club));
        }
示例#7
0
 public ActionResult Create(Club club)
 {
     if (ModelState.IsValid)
     {
         db.Clubs.Add(club);
         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));
 }
示例#8
0
        public ActionResult Create([Bind(Include = "ID,Description,TakeOff,Weather,Duration")] Flight flight)
        {
            if (ModelState.IsValid)
            {
                db.Flights.Add(flight);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(flight));
        }
示例#9
0
        public ActionResult Create(StartType starttype)
        {
            if (ModelState.IsValid)
            {
                db.StartTypes.Add(starttype);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ClubId = new SelectList(db.Clubs, "ClubId", "ShortName", starttype.ClubId);
            return(View(starttype));
        }
示例#10
0
 public int AddFlight(Flight flight)
 {
     try
     {
         contextDb.Flights.Add(flight);
         contextDb.SaveChanges();
         return(flight.FlightId);
     }
     catch (Exception e)
     {
         return(-1);
     }
 }
示例#11
0
        public ActionResult Create(Plane plane)
        {
            plane.CreatedTimestamp     = DateTime.Now;
            plane.CreatedBy            = User.Pilot().ToString();
            plane.LastUpdatedTimestamp = DateTime.Now;
            plane.LastUpdatedBy        = User.Pilot().ToString();
            if (ModelState.IsValid)
            {
                db.Planes.Add(plane);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.StartTypeId = new SelectList(db.StartTypes, "StartTypeId", "ShortName", plane.StartTypeId);
            return(View(plane));
        }
 public ActionResult flight(/*[Bind(Include ="Email")]*/ Flight f)
 {
     if (ModelState.IsValid)
     {
         using (Fdb)
         {
             Fdb.Flights.Add(f);
             Fdb.SaveChanges();
         }
         ModelState.Clear();
     }
     //Customer ct = new Customer();
     //ViewBag.Message = ct.Name ;
     //return View();
     return(RedirectToAction("ListOfBookings"));
 }
        public async Task AddSchedules(string scheduleFromDate, string scheduleToDate)
        {
            TimeSpan timeAccessory = new TimeSpan(0, 0, 0);
            DateTime fromDate      = Convert.ToDateTime(scheduleFromDate + " " + timeAccessory);
            DateTime toDate        = Convert.ToDateTime(scheduleToDate + " " + timeAccessory);

            AirCraft airCraft = new AirCraft();

            for (var dt = fromDate; dt <= toDate; dt = dt.AddDays(1))
            {
                //var dt = DateTime.Now;
                foreach (var r in _context.Routes)
                {
                    for (var i = 0; i < 4; i++)
                    {
                        DateTime tempDepartDateTime = Convert.ToDateTime(dt.Date.ToString("d") + " " + GenerateDepartTime());
                        DateTime tempArriveDateTime = tempDepartDateTime.Add(r.AveDuration);
                        int      ramID = GenerateAirCraftID();
                        airCraft = _context.AirCrafts.Where(a => a.AirCraftID == ramID).FirstOrDefault();  //随机选取一个飞机
                        await _context.Flight_Schedules.AddAsync(new Flight_Schedule { RouteID = r.RouteID, DepartDateTime = tempDepartDateTime, ArriveDateTime = tempArriveDateTime, AirlineCode = RandomString(2) + RandomInt(3), AirCraftID = airCraft.AirCraftID, NetFaire = r.BasicFare, Economy = airCraft.EconomyCap, Business = airCraft.BusinessCap, PremEconomy = airCraft.PremEconomyCap, First = airCraft.FirstCap });
                    }
                    //_context.SaveChanges();
                }
            }
            _context.SaveChanges();
        }
示例#14
0
 public void UpdateFlight(Flight flight)
 {
     using (FlightContext dbContext = new FlightContext())
     {
         dbContext.Update <Flight>(flight);
         dbContext.SaveChanges();
     }
 }
示例#15
0
 public void FlightAdd(Flight flight)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Flights.Add(flight);
         db.SaveChanges();
     }
 }
示例#16
0
 public void PassEdit(Passenger passenger)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Entry(passenger).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
示例#17
0
 public void PassAdd(Passenger passenger)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Passengers.Add(passenger);
         db.SaveChanges();
     }
 }
示例#18
0
 public void FlightUpdate(Flight flight)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Entry(flight).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
示例#19
0
 public void PassDelete(Passenger passenger)
 {
     using (FlightContext db = new FlightContext())
     {
         db.Passengers.Attach(passenger);
         db.Entry(passenger).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
示例#20
0
 public void Delete(Flight flight)
 {
     using (FlightContext dbContext = new FlightContext())
     {
         flight.IsValid    = false;
         flight.UpdateTime = DateTime.Now;
         dbContext.Update <Flight>(flight);
         dbContext.SaveChanges();
     }
 }
示例#21
0
 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();
     }
 }
示例#22
0
 public ActionResult RemoveFlight(Flight flight)
 {
     using (flightContext = new FlightContext())
     {
         Flight toRemove = flightContext.Flights.Find(flight.Id);
         flightContext.Flights.Remove(toRemove);
         flightContext.SaveChanges();
         return(View("~/Views/Admin/Home.cshtml"));
     }
 }
示例#23
0
 /// <summary>
 /// Method that reads from file all airports and saves in appropriate table.
 /// </summary>
 /// <param name="FlightContext">EntityFramework Flights Context</param>
 public static void SeedAirports(FlightContext context, ILogger logger)
 {
     if (!context.Airports.Any())
     {
         var airportData = System.IO.File.ReadAllText("Migrations/SeedData/airports.json");
         var airports    = JsonConvert.DeserializeObject <IList <Airport> >(airportData);
         context.AddRange(airports);
         context.SaveChanges();
     }
 }
        public ActionResult Create(Location location)
        {
            location.CreatedTimestamp     = DateTime.Now;
            location.CreatedBy            = User.Pilot().ToString();
            location.LastUpdatedTimestamp = DateTime.Now;
            location.LastUpdatedBy        = User.Pilot().ToString();
            if (!location.ICAO.IsNullOrWhiteSpace())
            {
                location.ICAO = location.ICAO.ToUpperInvariant();
            }
            if (ModelState.IsValid)
            {
                db.Locations.Add(location);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(location));
        }
示例#25
0
        public IActionResult Create(Flight flight)
        {
            if (ModelState.IsValid)
            {
                db.Flights.Add(flight);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(flight));
        }
示例#26
0
 public void BookFlight(int flightId, [FromBody] IEnumerable <Traveler> travelers)
 {
     using (var flightContext = new FlightContext())
     {
         var flight = flightContext.Flights.FirstOrDefault(f => f.FlightId == flightId);
         if (flight != null)
         {
             flight.Travelers = travelers.ToList();
             flightContext.SaveChanges();
         }
     }
 }
        public async Task <IActionResult> RetrieveAndSave([FromBody] Search searchInfo)
        {
            searchInfo.Return_date    = (searchInfo.Return_date != null) ? searchInfo.Return_date.Substring(0, 10) : "";
            searchInfo.Departure_date = searchInfo.Departure_date.Substring(0, 10);

            var dbService      = new DbService(db);
            var flightsInfoOld = dbService.getSearchData(searchInfo);

            if (flightsInfoOld.Count() != 0)
            {
                return(Ok(flightsInfoOld));
            }

            var queryUrl = String.Format("{0}?apikey={1}&origin={2}&destination={3}&departure_date={4}&adults={5}&currency={6}",
                                         ServiceUrl,
                                         ApiKey,
                                         searchInfo.Origin,
                                         searchInfo.Destination,
                                         searchInfo.Departure_date,
                                         searchInfo.Adults,
                                         searchInfo.Currency);

            if (searchInfo.Return_date != "")
            {
                queryUrl += "&return_date=" + searchInfo.Return_date;
            }

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(ServiceUrl);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = await client.GetAsync(queryUrl);

            response.EnsureSuccessStatusCode();
            var contents = await response.Content.ReadAsStringAsync();

            RootObject r = JsonConvert.DeserializeObject <RootObject>(contents);

            searchInfo.RootObject = r;
            db.Search.Add(searchInfo);
            db.SaveChanges();

            var flightsInfoNew = dbService.getSearchData(searchInfo);

            return(Ok(flightsInfoNew));
        }
示例#28
0
 public void AddEntriesToFlightEmployees(List <Employee> Employees, int FlightId)
 {
     for (int i = 0; i < Employees.Count(); i++)
     {
         FlightEmployee NewFlightEmployee = new FlightEmployee
         {
             FlightId   = FlightId,
             EmployeeId = Employees[i].Id
         };
         _context.Add(NewFlightEmployee);
         _context.SaveChanges();
     }
 }
示例#29
0
        public bool AddUser(RegisterModel model)
        {
            using (FlightContext db = new FlightContext())
            {
                db.Managers.Add(new Manager {
                    Email = model.Name, Password = model.Password, Role = model.Role
                });
                db.SaveChanges();

                Manager user = db.Managers.FirstOrDefault(u => u.Email == model.Name);
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(model.Name, true);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
示例#30
0
 public ActionResult AddFlight(Flight flightModel)
 {
     using (flightContext = new FlightContext())
     {
         if (flightModel.FromLocation == null || flightModel.ToLocation == null || flightModel.DepartureTime == null || flightModel.ArrivalTime == null ||
             flightModel.AirplaneType == null || flightModel.AirplaneId == null || flightModel.PilotName == null ||
             flightModel.UnusedPlacesBusiness <= 0 || flightModel.UnusedPlacesEconomy <= 0 || flightModel.DepartureTime > flightModel.ArrivalTime)
         {
             ViewBag.FailedAddMessage = "You must fill in all of the spaces and the data should be correct!";
             return(View("AddFlight", new Flight()));
         }
         else
         {
             flightContext.Flights.Add(flightModel);
             flightContext.SaveChanges();
         }
     }
     ModelState.Clear();
     ViewBag.SuccessMessage = "Flight was successfully added!";
     return(View("~/Views/Admin/Home.cshtml"));
 }