Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("FeedbackId", "Email", "Title", "Body")] Feedback feedback)
        {
            if (ModelState.IsValid)
            {
                feedback.Email = User.FindFirstValue(ClaimTypes.Name);
                ctx.Feedback.Add(feedback);
                await ctx.SaveChangesAsync();

                return(RedirectToAction("index", "flight"));
            }

            return(View(feedback));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> MoveToNextFlight(int id)
        {
            var currentFlight = await ctx.Flights.FindAsync(id);

            Flight nextFlight = null;

            // Check if there is a flight with the same dep and dest + a later departure date
            foreach (var flight in ctx.Flights)
            {
                if (flight.Departure == currentFlight.Departure &&
                    flight.Arrival == currentFlight.Arrival &&
                    flight.DepartureTime > currentFlight.DepartureTime)
                {
                    nextFlight = flight;
                    break;
                }
            }

            if (nextFlight != null)
            {
                // check if the next flight is already overbooked
                if (nextFlight.FreeSeats < 0 || nextFlight.FreeSeats < ctx.GetOverbookedUsersFromFlight(currentFlight).Count)
                {
                    return(View("/Views/Errors/NextFlightOverbookedError.cshtml"));
                }
                else
                { // if not, move the overbooked users there
                    List <string> overbookedEmails = new List <string>();

                    // list of overbooked users from this flight
                    var overbookedUsers = ctx.GetOverbookedUsersFromFlight(currentFlight);

                    // Removes all overbooked users and replaces them to the next available flight
                    for (int i = 0; i < overbookedUsers.Count; i++)
                    {
                        overbookedEmails.Add(overbookedUsers.ElementAt(i).Email);
                        ctx.UserFlights.Add(new UserFlights {
                            User = ctx.GetUserFromEmail(overbookedUsers.ElementAt(i).Email), Flight = nextFlight
                        });
                        --nextFlight.FreeSeats;


                        ctx.UserFlights.Remove(ctx.GetSpecificUserFlight(currentFlight, ctx.GetUserFromEmail(overbookedUsers.ElementAt(i).Email)));
                        ctx.OverbookedUsers.Remove(overbookedUsers.ElementAt(i));

                        ++currentFlight.FreeSeats;
                        await ctx.SaveChangesAsync();
                    }



                    return(RedirectToAction("SendEmail", "Email", new { emails = overbookedEmails }));
                }
            }
            else
            {
                return(View("/Views/Errors/NoNextFlightError.cshtml"));
            }
        }
    private async void Window_Loaded(object sender, RoutedEventArgs e)
    {
        await db.Users.LoadAsync();

        /* Data usage */

        /* Binding */
        CollectionViewSource userViewSource = ((CollectionViewSource)(this.FindResource("userViewSource")));

        userViewSource.Source = db.Users.Local;
        /* Add data */
        db.Users.Add(new User());
        await db.SaveChangesAsync();

        this.list_Users.Items.Refresh();
    }