Ejemplo n.º 1
0
        public IActionResult OnGet()
        {
            if (HttpContext.Session.GetString("EventId") == null)
            {
                string returnUrl = HttpContext.Request.Path.ToString();
                return(RedirectToPage("/Account/Login", new { area = "Identity" }));
            }

            ViewData["IsParticipating"] = HttpContext.Session.GetString("IsParticipating");
            int eventId = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture);

            ViewData["EventId"] = eventId;
            DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(eventId);

            if (dinnerEvent != null)
            {
                // Values are passed-through to layout page
                ViewData["EventName"]        = dinnerEvent.EventName;
                ViewData["EventDate"]        = dinnerEvent.EventDate.ToShortDateString();
                ViewData["EventCity"]        = dinnerEvent.City;
                ViewData["EventPictureLink"] = dinnerEvent.EventPictureLink;
            }

            List <Team> teams = TeamsRepository.SearchFor(x => x.Event.Id == eventId).Include("Partner1").Include("Partner2").ToList();

            Teams = teams;
            return(Page());
        }
        /// <summary>
        /// Adds a route.
        /// </summary>
        /// <param name="routeId"></param>
        public IActionResult OnGetAddRoute(int eventId)
        {
            var route       = new Route();
            var dinnerEvent = DinnerEventsRepository.GetById(eventId);

            route.Event = dinnerEvent;
            RoutesRepository.Insert(route);
            RoutesRepository.SaveChanges();
            return(OnGet());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends email to partner for confirmation.
        /// </summary>
        /// <param name="eventId"></param>
        /// <param name="partnerFirstName"></param>
        /// <param name="partnerEmail"></param>
        /// <param name="partnerEmail"></param>
        /// <param name="userId"></param>
        public async Task <IActionResult> OnPostSendPartnerInvitation(int eventId, string partnerFirstName, string partnerLastName, string partnerEmail, string userId)
        {
            ApplicationUser user = await UserManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(Page());
            }

            DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(eventId);

            if (dinnerEvent == null)
            {
                return(Page());
            }

            Invitation invitation = new Invitation
            {
                Event           = dinnerEvent,
                InvitationEmail = partnerEmail,
                User            = user,
                SentTime        = DateTime.Now
            };

            InvitationsRepository.Insert(invitation);
            InvitationsRepository.SaveChanges();
            EventParticipation participation = EventParticipationsRepository.SearchFor(x => x.User.Id == user.Id && x.Event.Id == eventId).FirstOrDefault();

            if (participation != null)
            {
                if (!participation.RegistrationComplete)
                {
                    TempData["StatusMessage"] = @"Bitte fülle zuerst die Teamdaten aus.";
                    return(Page());
                }

                participation.InvitationMailSent = true;
                EventParticipationsRepository.Update(participation);
                EventParticipationsRepository.SaveChanges();
            }

            var confirmationLink = Url.PartnerConfirmationLink(invitation.Id, partnerEmail);
            var callbackLink     = Url.PartnerConfirmationLinkCallback(invitation.Id, partnerEmail, confirmationLink, Request.Scheme);
            // Send the email
            string apiKey    = Configuration?.GetEmailSettings("apiKey");
            string apiSecret = Configuration?.GetEmailSettings("apiSecret");
            await EmailSender.SendMailjetAsync(apiKey, apiSecret, 1081044, "Du wurdest zum Großstadt Dinner eingeladen", "*****@*****.**", "Das Großstadt Dinner Team", partnerFirstName, partnerEmail, partnerFirstName + " " + partnerLastName, callbackLink, user.FirstName, dinnerEvent.EventName, dinnerEvent.EventDate.ToShortDateString());

            TempData["StatusMessage"] = @"Eine Einladung wurde an " + partnerEmail + " geschickt.";
            return(Page());
        }
        /// <summary>
        /// Settings Post Method.
        /// </summary>
        /// <returns></returns>
        public IActionResult OnPost()
        {
            if (HttpContext.Session.GetString("EventId") == null)
            {
                string returnUrl = HttpContext.Request.Path.ToString();
                return(RedirectToPage("/Account/Login", new { area = "Identity" }));
            }

            ViewData["IsParticipating"] = HttpContext.Session.GetString("IsParticipating");
            var         eventId     = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture);
            DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(eventId);

            if (dinnerEvent != null)
            {
                // Values are passed-through to layout page
                ViewData["EventName"]        = dinnerEvent.EventName;
                ViewData["EventDate"]        = dinnerEvent.EventDate.ToShortDateString();
                ViewData["EventCity"]        = dinnerEvent.City;
                ViewData["EventPictureLink"] = dinnerEvent.EventPictureLink;
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (dinnerEvent == null)
            {
                return(Page());
            }

            dinnerEvent.EventEnabled      = Input.EventEnabled;
            dinnerEvent.EventDate         = Input.EventDate;
            dinnerEvent.LastRegisterDate  = Input.LastRegisterDate;
            dinnerEvent.RoutesOpen        = Input.RoutesOpen;
            dinnerEvent.City              = Input.EventCity;
            dinnerEvent.PartyLocation     = Input.PartyLocation;
            dinnerEvent.PartyLocationName = Input.PartyLocationName;
            dinnerEvent.EventPictureLink  = Input.EventPictureLink;
            dinnerEvent.EventName         = Input.EventName;
            DinnerEventsRepository.Update(dinnerEvent);
            DinnerEventsRepository.SaveChanges();
            TempData["StatusMessage"] = "Die Eventeinstellungen wurden gespeichert.";
            return(RedirectToPage());
        }
        /// <summary>
        /// Settings Get Method.
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnGetAsync()
        {
            if (HttpContext.Session.GetString("EventId") == null)
            {
                string returnUrl = HttpContext.Request.Path.ToString();
                return(RedirectToPage("/Account/Login", new { area = "Identity" }));
            }

            ViewData["IsParticipating"] = HttpContext.Session.GetString("IsParticipating");
            var         eventId     = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture);
            DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(eventId);
            var         images      = await GetEventPictures();

            Images = new List <SelectListItem>();
            foreach (var image in images)
            {
                Images.Add(new SelectListItem {
                    Text = image, Value = "https://runningdinner.blob.core.windows.net/$web/" + image
                });
            }

            if (dinnerEvent != null)
            {
                Input = new InputModel();
                // Values are passed-through to layout page
                ViewData["EventName"]        = dinnerEvent.EventName;
                ViewData["EventDate"]        = dinnerEvent.EventDate.ToShortDateString();
                ViewData["EventCity"]        = dinnerEvent.City;
                ViewData["EventPictureLink"] = dinnerEvent.EventPictureLink;
                Input.RoutesOpen             = dinnerEvent.RoutesOpen;
                Input.EventDate         = dinnerEvent.EventDate;
                Input.EventEnabled      = dinnerEvent.EventEnabled;
                Input.LastRegisterDate  = dinnerEvent.LastRegisterDate;
                Input.PartyLocation     = dinnerEvent.PartyLocation;
                Input.PartyLocationName = dinnerEvent.PartyLocationName;
                Input.EventPictureLink  = dinnerEvent.EventPictureLink;
                Input.EventCity         = dinnerEvent.City;
                Input.EventName         = dinnerEvent.EventName;
            }

            return(Page());
        }
        public async Task <IActionResult> OnGetAsync(int eventId)
        {
            // Get eventId
            if (eventId == 0)
            {
                if (HttpContext.Session.GetString("EventId") == null)
                {
                    string returnUrl = HttpContext.Request.Path.ToString();
                    return(RedirectToPage("/Account/Login", new { area = "Identity" }));
                }

                eventId = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture);
            }

            else
            {
                HttpContext.Session.SetString("EventId", eventId.ToString(CultureInfo.CurrentCulture));
            }

            ApplicationUser user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(Page());
            }

            bool isParticipating = IsUserParticipating(eventId, user.Id);

            ViewData["IsParticipating"] = isParticipating;
            HttpContext.Session.SetString("IsParticipating", isParticipating.ToString(CultureInfo.CurrentCulture));
            DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(eventId);

            ViewData["apiKey"]           = Configuration?.GetMapsSettings("apiKeyJs");
            ViewData["MapCenterLat"]     = "50.113745";
            ViewData["MapCenterLong"]    = "8.679317";
            ViewData["EventName"]        = dinnerEvent.EventName;
            ViewData["EventDate"]        = dinnerEvent.EventDate.ToShortDateString();
            ViewData["EventCity"]        = dinnerEvent.City;
            ViewData["EventPictureLink"] = dinnerEvent.EventPictureLink;
            return(Page());
        }
        public async Task <IActionResult> OnGetAsync()
        {
            if (HttpContext.Session.GetString("EventId") == null)
            {
                string returnUrl = HttpContext.Request.Path.ToString();
                return(RedirectToPage("/Account/Login", new { area = "Identity" }));
            }

            ViewData["IsParticipating"] = HttpContext.Session.GetString("IsParticipating");
            int eventId = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture);

            ViewData["EventId"] = eventId;
            DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(eventId);

            if (dinnerEvent != null)
            {
                // Values are passed-through to layout page
                ViewData["EventName"]        = dinnerEvent.EventName;
                ViewData["EventDate"]        = dinnerEvent.EventDate.ToShortDateString();
                ViewData["EventCity"]        = dinnerEvent.City;
                ViewData["EventPictureLink"] = dinnerEvent.EventPictureLink;
            }

            List <EventParticipation> participations = EventParticipationsRepository.SearchFor(x => x.Event.Id == eventId).Include("User").ToList();
            List <ApplicationUser>    participants   = new List <ApplicationUser>();

            foreach (EventParticipation participation in participations)
            {
                var user = await _userManager.FindByIdAsync(participation.User.Id);

                participants.Add(user);
            }

            Participants = participants;
            return(Page());
        }
        public async Task <IActionResult> OnGet(int invitationId, string email, string returnUrl = null)
        {
            // Return if invitation is already accepted
            Invitation invitation = InvitationsRepository.SearchFor(x => x.Id == invitationId).Include("User").Include("Event").FirstOrDefault();

            if (invitation.InvitationAccepted)
            {
                // Display page?
                return(RedirectToAction("Index", "Home"));
            }

            ApplicationUser invitee = await _userManager.FindByEmailAsync(email);

            if (invitee == null)
            {
                // If user doesn't exist, redirect to Register page
                return(RedirectToPage("/Account/Register", new { area = "Identity", returnUrl }));
            }

            DinnerEvent        dinnerEvent          = DinnerEventsRepository.GetById(invitation.Event.Id);
            EventParticipation inviteeParticipation = EventParticipationsRepository.SearchFor(x => x.User.Id == invitee.Id && x.Event.Id == invitation.Event.Id).FirstOrDefault();

            if (inviteeParticipation == null)
            {
                inviteeParticipation = new EventParticipation {
                    User = invitee, Event = dinnerEvent
                };
                EventParticipationsRepository.Insert(inviteeParticipation);
                EventParticipationsRepository.SaveChanges();
            }

            invitation.InvitationAccepted = true;
            InvitationsRepository.Update(invitation);
            // Check if user has more pending invitations and make them invalid
            var otherInvitations = InvitationsRepository.SearchFor(x => x.User.Id == invitee.Id);

            foreach (var otherInvitation in otherInvitations)
            {
                otherInvitation.InvitationAccepted = true;
                InvitationsRepository.Update(otherInvitation);
            }

            InvitationsRepository.SaveChanges();
            // Add contact to Mailjet Contacts, save ContactId
            string apiKey    = Configuration?.GetEmailSettings("apiKey");
            string apiSecret = Configuration?.GetEmailSettings("apiSecret");
            // Save list recipient id to database
            long listRecipientId = await EmailSender.AddContactToContactListAsync(apiKey, apiSecret, invitee.ContactId.ToString(CultureInfo.InvariantCulture), dinnerEvent.ContactList.ToString(CultureInfo.InvariantCulture));

            invitee.ListRecipientId = listRecipientId;
            await _userManager.UpdateAsync(invitee);

            EventParticipation inviterParticipation = EventParticipationsRepository.SearchFor(x => x.User.Id == invitation.User.Id && x.Event.Id == invitation.Event.Id).FirstOrDefault();
            // Create a new team
            Team newTeam = new Team
            {
                Partner1         = invitation.User,
                Partner2         = invitee,
                SelectedCourse   = inviterParticipation?.SelectedCourse,
                AddressStreet    = inviterParticipation.Address,
                AddressNumber    = inviterParticipation.AddressNumber,
                FullAddress      = inviterParticipation.Address + " " + inviterParticipation.AddressNumber,
                AddressAdditions = inviterParticipation.AddressAdditions,
                Phone            = inviterParticipation.Phone,
                DinnerSaver      = inviterParticipation.DinnerSaver,
                Event            = invitation.Event,
                Allergies        = inviterParticipation.Allergies,
                City             = dinnerEvent.City
            };

            TeamsRepository.Insert(newTeam);
            TeamsRepository.SaveChanges();
            // Send the email
            await EmailSender.SendMailjetAsync(apiKey, apiSecret, 1197519, "Deine Einladung wurde angenommen", "*****@*****.**", "Das Großstadt Dinner Team", invitation.User.FirstName, invitation.User.Email, invitation.User.FirstName + " " + invitation.User.LastName, "", invitee.FirstName, invitation.Event.EventName, invitation.Event.EventDate.ToShortDateString());

            TempData["StatusMessage"] = @"Du hast die Einladung erfolgreich angenommen. Die Teamdaten deines Partners wurden übernommen. Ihr seid nun vollständig angemeldet.";
            return(RedirectToPage("./RegistrationData"));
        }
        public IActionResult OnGet()
        {
            if (HttpContext.Session.GetString("EventId") == null)
            {
                string returnUrl = HttpContext.Request.Path.ToString();
                return(RedirectToPage("/Account/Login", new { area = "Identity", returnUrl }));
            }

            ViewData["IsParticipating"] = HttpContext.Session.GetString("IsParticipating");
            var         eventId     = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture);
            DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(eventId);

            if (dinnerEvent != null)
            {
                // Values are passed-through to layout page
                ViewData["EventId"]          = dinnerEvent.Id;
                ViewData["EventName"]        = dinnerEvent.EventName;
                ViewData["EventDate"]        = dinnerEvent.EventDate.ToShortDateString();
                ViewData["EventCity"]        = dinnerEvent.City;
                ViewData["EventPictureLink"] = dinnerEvent.EventPictureLink;
            }

            List <EventParticipation> participants           = EventParticipationsRepository.SearchFor(x => x.Event.Id == eventId).Include("User").OrderBy(p => p.User.FirstName).ToList();
            List <SelectListItem>     participantsSelectList = new List <SelectListItem> {
                new SelectListItem {
                    Value = "empty", Text = ""
                }
            };

            foreach (EventParticipation participant in participants)
            {
                participantsSelectList.Add(new SelectListItem {
                    Value = participant.User.Id, Text = participant.User.FirstName + " " + participant.User.LastName
                });
            }

            var                   teams               = TeamsRepository.SearchFor(x => x.Event.Id == eventId);
            List <string>         addresses           = teams.OrderBy(e => e.AddressStreet).Select(e => e.AddressStreet + " " + e.AddressNumber).ToList();
            List <SelectListItem> addressesSelectList = new List <SelectListItem> {
                new SelectListItem {
                    Value = "empty", Text = ""
                }
            };

            foreach (string address in addresses)
            {
                addressesSelectList.Add(new SelectListItem {
                    Value = address, Text = address
                });
            }

            List <Route> routes;

            using (var context = new ApplicationDbContext())
            {
                routes = context.Routes.AsNoTracking().Where(er => er.Event.Id == eventId).Include("Event")
                         .Include(a => a.RouteForTeam)
                         .Include(a => a.FirstCourseHostTeam).ThenInclude(b => b.Partner1)
                         .Include(a => a.FirstCourseHostTeam).ThenInclude(b => b.Partner2)
                         .Include(a => a.FirstCourseGuestTeam1).ThenInclude(b => b.Partner1)
                         .Include(a => a.FirstCourseGuestTeam1).ThenInclude(b => b.Partner2)
                         .Include(a => a.FirstCourseGuestTeam2).ThenInclude(b => b.Partner1)
                         .Include(a => a.FirstCourseGuestTeam2).ThenInclude(b => b.Partner2)
                         .Include(a => a.SecondCourseHostTeam).ThenInclude(b => b.Partner1)
                         .Include(a => a.SecondCourseHostTeam).ThenInclude(b => b.Partner2)
                         .Include(a => a.SecondCourseGuestTeam1).ThenInclude(b => b.Partner1)
                         .Include(a => a.SecondCourseGuestTeam1).ThenInclude(b => b.Partner2)
                         .Include(a => a.SecondCourseGuestTeam2).ThenInclude(b => b.Partner1)
                         .Include(a => a.SecondCourseGuestTeam2).ThenInclude(b => b.Partner2)
                         .Include(a => a.ThirdCourseHostTeam).ThenInclude(b => b.Partner1)
                         .Include(a => a.ThirdCourseHostTeam).ThenInclude(b => b.Partner2)
                         .Include(a => a.ThirdCourseGuestTeam1).ThenInclude(b => b.Partner1)
                         .Include(a => a.ThirdCourseGuestTeam1).ThenInclude(b => b.Partner2)
                         .Include(a => a.ThirdCourseGuestTeam2).ThenInclude(b => b.Partner1)
                         .Include(a => a.ThirdCourseGuestTeam2).ThenInclude(b => b.Partner2)
                         .ToList();
            }

            Addresses    = addressesSelectList;
            Participants = participantsSelectList;

            var teamsList = TeamsRepository.SearchFor(x => x.Event.Id == eventId).ToList();
            List <SelectListItem> teamsSelectList = new List <SelectListItem> {
                new SelectListItem {
                    Value = "empty", Text = ""
                }
            };

            foreach (var team in teamsList)
            {
                teamsSelectList.Add(new SelectListItem {
                    Value = team.Id.ToString(), Text = "Team " + team.Id.ToString()
                });
            }

            Teams  = teamsSelectList;
            Routes = routes;
            return(Page());
        }
        /// <summary>
        /// PageHandler for creating routes automatically.
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnPostCreateRoutes(int factor)
        {
            if (HttpContext.Session.GetString("EventId") == null)
            {
                string returnUrl = HttpContext.Request.Path.ToString();
                return(RedirectToPage("/Account/Login", new { area = "Identity", returnUrl }));
            }

            ViewData["IsParticipating"] = HttpContext.Session.GetString("IsParticipating");
            var eventId     = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture);
            var dinnerEvent = DinnerEventsRepository.GetById(eventId);
            List <CalculationHost> FirstCourseHosts  = new List <CalculationHost>();
            List <CalculationHost> SecondCourseHosts = new List <CalculationHost>();
            List <CalculationHost> ThirdCourseHosts  = new List <CalculationHost>();
            int routeFactor    = factor;
            int numberOfRoutes = routeFactor * 3;
            var teams          = TeamsRepository.SearchFor(x => x.Event.Id == eventId).Take(numberOfRoutes).ToList();

            ///////////////////////////// Sort teams by course
            foreach (Team team in teams)
            {
                if (team.SelectedCourse == "FirstCourse")
                {
                    FirstCourseHosts.Add(new CalculationHost()
                    {
                        HostTeam = team
                    });
                }

                if (team.SelectedCourse == "SecondCourse")
                {
                    SecondCourseHosts.Add(new CalculationHost()
                    {
                        HostTeam = team
                    });
                }

                if (team.SelectedCourse == "ThirdCourse")
                {
                    ThirdCourseHosts.Add(new CalculationHost()
                    {
                        HostTeam = team
                    });
                }
            }

            List <CalculationHost> FirstCourseHostsOrdered  = new List <CalculationHost>();
            List <CalculationHost> SecondCourseHostsOrdered = SecondCourseHosts;
            List <CalculationHost> ThirdCourseHostsOrdered  = new List <CalculationHost>();

            //////////////////////////////// Get GeoCoordinates
            foreach (var secondCourseHost in SecondCourseHosts)
            {
                var address = secondCourseHost.HostTeam.FullAddress + "," + secondCourseHost.HostTeam.City;
                secondCourseHost.Coordinates = await HereMapsHelper.GetCoordinates(address);
            }

            foreach (var thirdCourseHost in ThirdCourseHosts)
            {
                var address = thirdCourseHost.HostTeam.FullAddress + "," + thirdCourseHost.HostTeam.City;
                thirdCourseHost.Coordinates = await HereMapsHelper.GetCoordinates(address);
            }

            foreach (var firstCourseHost in FirstCourseHosts)
            {
                var address = firstCourseHost.HostTeam.FullAddress + "," + firstCourseHost.HostTeam.City;
                firstCourseHost.Coordinates = await HereMapsHelper.GetCoordinates(address);
            }

            /////////////////////////////// Calculate Distances
            foreach (var secondCourseHost in SecondCourseHosts)
            {
                // From Second to First course hosts
                secondCourseHost.HostDistancesToFirst = new List <RouteNodeDistance>();
                foreach (var firstCourseHost in FirstCourseHosts)
                {
                    RouteNodeDistance hostDistance = new RouteNodeDistance
                    {
                        Host1    = secondCourseHost,
                        Distance = secondCourseHost.Coordinates.GetDistanceTo(firstCourseHost.Coordinates),
                        Host2    = firstCourseHost
                    };
                    secondCourseHost.HostDistancesToFirst.Add(hostDistance);
                }

                secondCourseHost.HostDistancesToFirst = secondCourseHost.HostDistancesToFirst.OrderBy(x => x.Distance).ToList();
                // From Second to Third course hosts
                secondCourseHost.HostDistancesToThird = new List <RouteNodeDistance>();
                foreach (var thirdCourseHost in ThirdCourseHosts)
                {
                    RouteNodeDistance hostDistance = new RouteNodeDistance
                    {
                        Host1    = secondCourseHost,
                        Distance = secondCourseHost.Coordinates.GetDistanceTo(thirdCourseHost.Coordinates),
                        Host2    = thirdCourseHost
                    };
                    secondCourseHost.HostDistancesToThird.Add(hostDistance);
                }

                secondCourseHost.HostDistancesToThird = secondCourseHost.HostDistancesToThird.OrderBy(x => x.Distance).ToList();
            }

            //////////////////////// Re-order hosts by distance
            foreach (var secondCourseHost in SecondCourseHosts)
            {
                // Shortest Distance from SecondCourse to FirstCourse
                foreach (var hostDistance in secondCourseHost.HostDistancesToFirst)
                {
                    if (!FirstCourseHostsOrdered.Contains(hostDistance.Host2))
                    {
                        FirstCourseHostsOrdered.Add(hostDistance.Host2);
                        break;
                    }
                }
            }

            foreach (var secondCourseHost in SecondCourseHosts)
            {
                // Shortest Distance from SecondCourse To ThirdCourse
                foreach (var hostDistance in secondCourseHost.HostDistancesToThird)
                {
                    if (!ThirdCourseHostsOrdered.Contains(hostDistance.Host2))
                    {
                        ThirdCourseHostsOrdered.Add(hostDistance.Host2);
                        break;
                    }
                }
            }

            //////////////////// Set SecondCourseHosts (use only ordered Hosts from here!)
            // Start from First
            int i = 0;
            // Start from Second
            int j = 1;

            foreach (var secondCourseHost in SecondCourseHostsOrdered)
            {
                // Add FirstCourseHost
                FirstCourseHostsOrdered[i].GuestTeam1 = secondCourseHost.HostTeam;
                // Add ThirdCourseHost
                ThirdCourseHostsOrdered[j].GuestTeam1 = secondCourseHost.HostTeam;
                i++;
                j++;
                if (i == routeFactor)
                {
                    i = 0;
                }

                if (j == routeFactor)
                {
                    j = 0;
                }
            }

            /////////////////////////////////// Set ThirdCourseHosts
            // Start from First
            i = 0;
            // Start from Second
            j = 1;
            foreach (var thirdCourseHost in ThirdCourseHostsOrdered)
            {
                // Add FirstCourseHost
                FirstCourseHostsOrdered[i].GuestTeam2 = thirdCourseHost.HostTeam;
                // Add SecondCourseHost
                SecondCourseHostsOrdered[j].GuestTeam1 = thirdCourseHost.HostTeam;
                i++;
                j++;
                if (i == routeFactor)
                {
                    i = 0;
                }

                if (j == routeFactor)
                {
                    j = 0;
                }
            }

            /////////////////////////////////// Set FirstCourseHosts
            // Start from Third
            i = 2;
            // Start from Third
            j = 2;
            foreach (var firstCourseHost in FirstCourseHostsOrdered)
            {
                // Add SecondCourseHost
                SecondCourseHostsOrdered[i].GuestTeam2 = firstCourseHost.HostTeam;
                // Add ThirdCourseHost
                ThirdCourseHostsOrdered[j].GuestTeam2 = firstCourseHost.HostTeam;
                i++;
                j++;
                if (i == routeFactor)
                {
                    i = 0;
                }

                if (j == routeFactor)
                {
                    j = 0;
                }
            }

            ///////////////////////// Create routes
            // Add SecondCourse routes
            foreach (var host in SecondCourseHostsOrdered)
            {
                Route newRoute = new Route
                {
                    Event        = dinnerEvent,
                    RouteForTeam = host.HostTeam,
                    // Second Course
                    SecondCourseHostTeam   = host.HostTeam,
                    SecondCourseGuestTeam1 = host.GuestTeam1,
                    SecondCourseGuestTeam2 = host.GuestTeam2
                };
                // First Course
                var firstCourseHostList = from r in FirstCourseHostsOrdered
                                          where r.GuestTeam1.Id == host.HostTeam.Id
                                          select r;
                var firstCourseHost = firstCourseHostList.FirstOrDefault();
                newRoute.FirstCourseHostTeam   = firstCourseHost.HostTeam;
                newRoute.FirstCourseGuestTeam1 = firstCourseHost.GuestTeam1;
                newRoute.FirstCourseGuestTeam2 = firstCourseHost.GuestTeam2;
                // Third Course
                var thirdCourseHostList = from r in ThirdCourseHostsOrdered
                                          where r.GuestTeam1.Id == host.HostTeam.Id
                                          select r;
                var thirdCourseHost = thirdCourseHostList.FirstOrDefault();
                newRoute.ThirdCourseHostTeam   = thirdCourseHost.HostTeam;
                newRoute.ThirdCourseGuestTeam1 = thirdCourseHost.GuestTeam1;
                newRoute.ThirdCourseGuestTeam2 = thirdCourseHost.GuestTeam2;
                RoutesRepository.Insert(newRoute);
            }

            // Add ThirdCourse routes
            foreach (var host in ThirdCourseHostsOrdered)
            {
                Route newRoute = new Route
                {
                    Event        = dinnerEvent,
                    RouteForTeam = host.HostTeam,
                    // Third Course
                    ThirdCourseHostTeam   = host.HostTeam,
                    ThirdCourseGuestTeam1 = host.GuestTeam1,
                    ThirdCourseGuestTeam2 = host.GuestTeam2
                };
                // First Course
                var firstCourseHostList = from r in FirstCourseHostsOrdered
                                          where r.GuestTeam2.Id == host.HostTeam.Id
                                          select r;
                var firstCourseHost = firstCourseHostList.FirstOrDefault();
                newRoute.FirstCourseHostTeam   = firstCourseHost.HostTeam;
                newRoute.FirstCourseGuestTeam1 = firstCourseHost.GuestTeam1;
                newRoute.FirstCourseGuestTeam2 = firstCourseHost.GuestTeam2;
                // Second Course
                var secondCourseHostList = from r in SecondCourseHostsOrdered
                                           where r.GuestTeam1.Id == host.HostTeam.Id
                                           select r;
                var secondCourseHost = secondCourseHostList.FirstOrDefault();
                newRoute.SecondCourseHostTeam   = secondCourseHost.HostTeam;
                newRoute.SecondCourseGuestTeam1 = secondCourseHost.GuestTeam1;
                newRoute.SecondCourseGuestTeam2 = secondCourseHost.GuestTeam2;
                RoutesRepository.Insert(newRoute);
            }

            // Add FirstCourse routes
            foreach (var host in FirstCourseHostsOrdered)
            {
                Route newRoute = new Route
                {
                    Event        = dinnerEvent,
                    RouteForTeam = host.HostTeam,
                    // First Course
                    FirstCourseHostTeam   = host.HostTeam,
                    FirstCourseGuestTeam1 = host.GuestTeam1,
                    FirstCourseGuestTeam2 = host.GuestTeam2
                };
                // Second Course
                var secondCourseHostList = from r in SecondCourseHostsOrdered
                                           where r.GuestTeam2.Id == host.HostTeam.Id
                                           select r;
                var secondCourseHost = secondCourseHostList.FirstOrDefault();
                newRoute.SecondCourseHostTeam   = secondCourseHost.HostTeam;
                newRoute.SecondCourseGuestTeam1 = secondCourseHost.GuestTeam1;
                newRoute.SecondCourseGuestTeam2 = secondCourseHost.GuestTeam2;
                // Third Course
                var thirdCourseHostList = from r in ThirdCourseHostsOrdered
                                          where r.GuestTeam2.Id == host.HostTeam.Id
                                          select r;
                var thirdCourseHost = thirdCourseHostList.FirstOrDefault();
                newRoute.ThirdCourseHostTeam   = thirdCourseHost.HostTeam;
                newRoute.ThirdCourseGuestTeam1 = thirdCourseHost.GuestTeam1;
                newRoute.ThirdCourseGuestTeam2 = thirdCourseHost.GuestTeam2;
                RoutesRepository.Insert(newRoute);
            }

            RoutesRepository.SaveChanges();
            return(RedirectToPage());
        }
        public IActionResult OnGet()
        {
            if (HttpContext.Session.GetString("EventId") == null)
            {
                string returnUrl = HttpContext.Request.Path.ToString();
                return(RedirectToPage("/Account/Login", new { area = "Identity" }));
            }

            ViewData["IsParticipating"] = HttpContext.Session.GetString("IsParticipating");
            var         eventId     = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture);
            DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(eventId);

            if (dinnerEvent != null)
            {
                // Values are passed-through to layout page
                ViewData["EventName"]        = dinnerEvent.EventName;
                ViewData["EventDate"]        = dinnerEvent.EventDate.ToShortDateString();
                ViewData["EventCity"]        = dinnerEvent.City;
                ViewData["EventPictureLink"] = dinnerEvent.EventPictureLink;
            }

            else
            {
                return(RedirectToPage("RegistrationData"));
            }

            ViewData["apiKey"]        = Configuration?.GetMapsSettings("apiKeyJs");
            ViewData["MapCenterLat"]  = "50.113745";
            ViewData["MapCenterLong"] = "8.679317";

            // Routes
            List <Route> routes = RoutesRepository.SearchFor(x => x.Event.Id == eventId)
                                  .Include(a => a.Event)
                                  .Include(a => a.RouteForTeam)
                                  .Include(a => a.FirstCourseHostTeam)
                                  .Include(a => a.FirstCourseGuestTeam1)
                                  .Include(a => a.FirstCourseGuestTeam2)
                                  .Include(a => a.SecondCourseHostTeam)
                                  .Include(a => a.SecondCourseGuestTeam1)
                                  .Include(a => a.SecondCourseGuestTeam2)
                                  .Include(a => a.ThirdCourseHostTeam)
                                  .Include(a => a.ThirdCourseGuestTeam1)
                                  .Include(a => a.ThirdCourseGuestTeam2).ToList();
            List <string> kitchenAddresses = new List <string>();

            foreach (var route in routes)
            {
                if (route.RouteForTeam?.Id == route.FirstCourseHostTeam?.Id)
                {
                    kitchenAddresses.Add(route.FirstCourseHostTeam.FullAddress + "," + dinnerEvent.City);
                }

                if (route.RouteForTeam?.Id == route.SecondCourseHostTeam?.Id)
                {
                    kitchenAddresses.Add(route.SecondCourseHostTeam.FullAddress + "," + dinnerEvent.City);
                }

                if (route.RouteForTeam?.Id == route.ThirdCourseHostTeam?.Id)
                {
                    kitchenAddresses.Add(route.ThirdCourseHostTeam.FullAddress + "," + dinnerEvent.City);
                }
            }

            List <string> kitchenCoordinates = new List <string>();

            foreach (var kitchenAddress in kitchenAddresses)
            {
                string coordinateString = HereMapsHelper.GetCoordinatesWithAddressString(kitchenAddress);
                kitchenCoordinates.Add(coordinateString);
            }

            ViewData["KitchenCoordinates"] = kitchenCoordinates.ToArray();
            List <string> routeAddresses = new List <string>();

            foreach (Route route in routes)
            {
                // First Course Host
                routeAddresses.Add(route.FirstCourseHostTeam.FullAddress + ", " + dinnerEvent.City);
                // Second Course Host
                routeAddresses.Add(route.SecondCourseHostTeam.FullAddress + ", " + dinnerEvent.City);
                // Third Course Host
                routeAddresses.Add(route.ThirdCourseHostTeam.FullAddress + ", " + dinnerEvent.City);
            }

            List <string> routeCoordinates = new List <string>();

            foreach (var routeAddress in routeAddresses)
            {
                string coordinateString = HereMapsHelper.GetCoordinatesString(routeAddress);
                routeCoordinates.Add(coordinateString);
            }

            ViewData["RouteCoordinates"] = routeCoordinates.ToArray();
            string partyLocationCoordinateString = HereMapsHelper.GetCoordinatesWithAddressString(dinnerEvent.PartyLocation);

            ViewData["PartyLocation"] = partyLocationCoordinateString;
            return(Page());
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Unregister from event method.
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnGetEventUnregister()
        {
            if (HttpContext.Session.GetString("EventId") == null)
            {
                string returnUrl = HttpContext.Request.Path.ToString();
                return(RedirectToPage("/Account/Login", new { area = "Identity", returnUrl }));
            }

            var eventId     = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture);
            var dinnerEvent = DinnerEventsRepository.GetById(eventId);
            var user        = await UserManager.GetUserAsync(HttpContext.User);

            EventParticipation eventParticipation = EventParticipationsRepository.SearchFor(x => x.User == user && x.Event == dinnerEvent).FirstOrDefault();

            EventParticipationsRepository.Delete(eventParticipation);
            EventParticipationsRepository.SaveChanges();
            Team team = TeamsRepository.SearchFor(x => x.Event.Id == dinnerEvent.Id && (x.Partner1.Id == user.Id || x.Partner2.Id == user.Id)).Include("Partner1").Include("Partner2").FirstOrDefault();

            // Remove team
            if (team != null)
            {
                if (dinnerEvent.RoutesOpen)
                {
                    // Delete from existing routes
                    var routes = RoutesRepository.SearchFor(x => x.Event.Id == eventId && x.RouteForTeam.Id == team.Id)
                                 .Include(a => a.Event)
                                 .Include(a => a.RouteForTeam)
                                 .Include(a => a.FirstCourseHostTeam).ThenInclude(b => b.Partner1)
                                 .Include(a => a.FirstCourseHostTeam).ThenInclude(b => b.Partner2)
                                 .Include(a => a.FirstCourseGuestTeam1).ThenInclude(b => b.Partner1)
                                 .Include(a => a.FirstCourseGuestTeam1).ThenInclude(b => b.Partner2)
                                 .Include(a => a.FirstCourseGuestTeam2).ThenInclude(b => b.Partner1)
                                 .Include(a => a.FirstCourseGuestTeam2).ThenInclude(b => b.Partner2)
                                 .Include(a => a.SecondCourseHostTeam).ThenInclude(b => b.Partner1)
                                 .Include(a => a.SecondCourseHostTeam).ThenInclude(b => b.Partner2)
                                 .Include(a => a.SecondCourseGuestTeam1).ThenInclude(b => b.Partner1)
                                 .Include(a => a.SecondCourseGuestTeam1).ThenInclude(b => b.Partner2)
                                 .Include(a => a.SecondCourseGuestTeam2).ThenInclude(b => b.Partner1)
                                 .Include(a => a.SecondCourseGuestTeam2).ThenInclude(b => b.Partner2)
                                 .Include(a => a.ThirdCourseHostTeam).ThenInclude(b => b.Partner1)
                                 .Include(a => a.ThirdCourseHostTeam).ThenInclude(b => b.Partner2)
                                 .Include(a => a.ThirdCourseGuestTeam1).ThenInclude(b => b.Partner1)
                                 .Include(a => a.ThirdCourseGuestTeam1).ThenInclude(b => b.Partner2)
                                 .Include(a => a.ThirdCourseGuestTeam2).ThenInclude(b => b.Partner1)
                                 .Include(a => a.ThirdCourseGuestTeam2).ThenInclude(b => b.Partner2);
                    foreach (var route in routes)
                    {
                        if (route.RouteForTeam.Id == team.Id)
                        {
                            route.RouteForTeam = null;
                        }

                        if (route.FirstCourseHostTeam.Id == team.Id)
                        {
                            route.FirstCourseHostTeam = null;
                        }

                        if (route.FirstCourseGuestTeam1.Id == team.Id)
                        {
                            route.FirstCourseGuestTeam1 = null;
                        }

                        if (route.FirstCourseGuestTeam2.Id == team.Id)
                        {
                            route.FirstCourseGuestTeam2 = null;
                        }

                        if (route.SecondCourseHostTeam.Id == team.Id)
                        {
                            route.SecondCourseHostTeam = null;
                        }

                        if (route.SecondCourseGuestTeam1.Id == team.Id)
                        {
                            route.SecondCourseGuestTeam1 = null;
                        }

                        if (route.SecondCourseGuestTeam2.Id == team.Id)
                        {
                            route.SecondCourseGuestTeam2 = null;
                        }

                        if (route.ThirdCourseHostTeam.Id == team.Id)
                        {
                            route.ThirdCourseHostTeam = null;
                        }

                        if (route.ThirdCourseGuestTeam1.Id == team.Id)
                        {
                            route.ThirdCourseGuestTeam1 = null;
                        }

                        if (route.ThirdCourseGuestTeam2.Id == team.Id)
                        {
                            route.ThirdCourseGuestTeam2 = null;
                        }

                        RoutesRepository.Update(route);
                    }

                    RoutesRepository.SaveChanges();
                }

                // Remove contact from contact list
                string apiKey    = Configuration?.GetEmailSettings("apiKey");
                string apiSecret = Configuration?.GetEmailSettings("apiSecret");
                if (team.Partner1 != null)
                {
                    await EmailSender.RemoveListRecipientAsync(apiKey, apiSecret, team.Partner1.ListRecipientId);
                }

                if (team.Partner2 != null)
                {
                    await EmailSender.RemoveListRecipientAsync(apiKey, apiSecret, team.Partner2.ListRecipientId);
                }

                TeamsRepository.Delete(team);
                TeamsRepository.SaveChanges();
                TempData["StatusMessage"] = "Du hast dein Team vom Event abgemeldet.";
            }

            else
            {
                TempData["StatusMessage"] = "Du hast dich vom Event abgemeldet.";
            }

            return(RedirectToPage("RegistrationData", new { id = eventId }));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (HttpContext.Session.GetString("EventId") == null)
            {
                string returnUrl = HttpContext.Request.Path.ToString();
                return(RedirectToPage("/Account/Login", new { area = "Identity", returnUrl }));
            }

            ViewData["IsParticipating"] = HttpContext.Session.GetString("IsParticipating");
            int         eventId     = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture);
            DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(eventId);

            if (dinnerEvent != null)
            {
                // Values are passed-through to layout page
                ViewData["EventName"]        = dinnerEvent.EventName;
                ViewData["EventDate"]        = dinnerEvent.EventDate.ToShortDateString();
                ViewData["EventCity"]        = dinnerEvent.City;
                ViewData["EventPictureLink"] = dinnerEvent.EventPictureLink;
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await UserManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{UserManager.GetUserId(User)}'.");
            }

            // Load Team
            Team team = TeamsRepository.SearchFor(x => x.Event.Id == dinnerEvent.Id && (x.Partner1.Id == user.Id || x.Partner2.Id == user.Id)).Include("Partner1").Include("Partner2").Include("Event").FirstOrDefault();

            if (team != null)
            {
                team.DinnerSaver      = Input.DinnerSaver;
                team.SelectedCourse   = Input.SelectedCourse;
                team.AddressStreet    = Input.AddressStreet;
                team.AddressAdditions = Input.AddressAdditions;
                team.AddressNumber    = Input.AddressNumber;
                team.FullAddress      = Input.AddressStreet + " " + Input.AddressNumber;
                TeamsRepository.Update(team);
                TeamsRepository.SaveChanges();
                TempData["StatusMessage"] = @"Die Einstellungen für dein Team wurden gespeichert.";
            }

            else
            {
                EventParticipation participation = EventParticipationsRepository.SearchFor(x => x.User.Id == user.Id && x.Event.Id == eventId).FirstOrDefault();
                if (participation == null)
                {
                    participation = new EventParticipation
                    {
                        InvitationMailSent = true,
                        User                 = user,
                        Event                = dinnerEvent,
                        PartnerName          = Input.PartnerFirstName,
                        PartnerLastName      = Input.PartnerLastName,
                        PartnerEmail         = Input.PartnerEmail,
                        Address              = Input.AddressStreet,
                        AddressNumber        = Input.AddressNumber,
                        AddressAdditions     = Input.AddressAdditions,
                        Phone                = Input.Phone,
                        Allergies            = Input.Allergies,
                        SelectedCourse       = Input.SelectedCourse,
                        IsWithoutPartner     = Input.IsWithoutPartner,
                        DinnerSaver          = Input.DinnerSaver,
                        RegistrationComplete = true
                    };

                    EventParticipationsRepository.Insert(participation);
                    EventParticipationsRepository.SaveChanges();
                    // Add contact to Mailjet Contacts, save ContactId
                    string apiKey          = Configuration?.GetEmailSettings("apiKey");
                    string apiSecret       = Configuration?.GetEmailSettings("apiSecret");
                    long   listRecipientId = await EmailSender.AddContactToContactListAsync(apiKey, apiSecret, user.ContactId.ToString(CultureInfo.InvariantCulture), dinnerEvent.ContactList.ToString(CultureInfo.InvariantCulture));

                    user.ListRecipientId = listRecipientId;
                    await UserManager.UpdateAsync(user);
                }

                else
                {
                    participation.Phone                = Input.Phone;
                    participation.Allergies            = Input.Allergies;
                    participation.Address              = Input.AddressStreet;
                    participation.AddressNumber        = Input.AddressNumber;
                    participation.AddressAdditions     = Input.AddressAdditions;
                    participation.PartnerName          = Input.PartnerFirstName;
                    participation.PartnerLastName      = Input.PartnerLastName;
                    participation.PartnerEmail         = Input.PartnerEmail;
                    participation.SelectedCourse       = Input.SelectedCourse;
                    participation.IsWithoutPartner     = Input.IsWithoutPartner;
                    participation.DinnerSaver          = Input.DinnerSaver;
                    participation.RegistrationComplete = true;
                    EventParticipationsRepository.Update(participation);
                    EventParticipationsRepository.SaveChanges();
                }

                await OnPostSendPartnerInvitation(eventId, Input.PartnerFirstName, Input.PartnerLastName, Input.PartnerEmail, user.Id);

                TempData["StatusMessage"] = "Deine Anmeldung wurde gespeichert. Eine Einladung wurde an " + Input.PartnerEmail +
                                            " geschickt. Die Anmeldung ist vollständig sobald dein Partner bestätigt hat.";
            }

            return(RedirectToPage("./RegistrationData", eventId));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Returns the RegistrationData page.
        /// </summary>
        /// <param name="eventId"></param>
        /// <returns></returns>
        public async Task <IActionResult> OnGetAsync(int eventId)
        {
            var user = await UserManager.GetUserAsync(HttpContext.User);

            bool isSignedIn = SignInManager.IsSignedIn(User);

            if (!isSignedIn)
            {
                string returnUrl = HttpContext.Request.Path.ToString() + "?eventid=" + eventId;
                return(RedirectToPage("/Account/Login", new { area = "Identity", returnUrl }));
            }

            // Get eventId
            if (eventId == 0)
            {
                if (HttpContext.Session.GetString("EventId") == null)
                {
                    string returnUrl = HttpContext.Request.Path.ToString();
                    return(RedirectToPage("/Account/Login", new { area = "Identity", returnUrl }));
                }

                eventId = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture);
            }

            else
            {
                HttpContext.Session.SetString("EventId", eventId.ToString(CultureInfo.CurrentCulture));
            }

            // Get eventTitle
            DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(eventId);

            if (dinnerEvent != null)
            {
                // Values are passed-through to layout page
                ViewData["EventName"]        = dinnerEvent.EventName;
                ViewData["EventDate"]        = dinnerEvent.EventDate.ToShortDateString();
                ViewData["EventCity"]        = dinnerEvent.City;
                ViewData["EventPictureLink"] = dinnerEvent.EventPictureLink;
                ViewData["EventId"]          = eventId;
            }

            IsParticipating             = IsUserParticipating(eventId, user.Id);
            ViewData["IsParticipating"] = IsParticipating.ToString(CultureInfo.CurrentCulture);
            HttpContext.Session.SetString("IsParticipating", IsParticipating.ToString(CultureInfo.CurrentCulture));
            // Load EventParticipation
            EventParticipation eventParticipation = EventParticipationsRepository.SearchFor(x => x.User.Id == user.Id && x.Event.Id == eventId).FirstOrDefault();

            if (eventParticipation == null)
            {
                eventParticipation = new EventParticipation
                {
                    User  = user,
                    Event = dinnerEvent
                };
            }

            Input = new InputModel();

            // Load Team
            Team team = TeamsRepository.SearchFor(x => x.Event.Id == dinnerEvent.Id && (x.Partner1.Id == user.Id || x.Partner2.Id == user.Id)).Include("Partner1").Include("Partner2").Include("Event").FirstOrDefault();

            if (team != null)
            {
                string partnerFirstName = "";
                string partnerLastName  = "";
                string partnerEmail     = "";
                if (team.Partner1.Id == user.Id)
                {
                    partnerFirstName = team.Partner2.FirstName;
                    partnerLastName  = team.Partner2.LastName;
                    partnerEmail     = team.Partner2.Email;
                }

                else
                {
                    partnerFirstName = team.Partner1.FirstName;
                    partnerLastName  = team.Partner1.LastName;
                    partnerEmail     = team.Partner1.Email;
                }

                Team  = team;
                Event = team.Event;
                Input.SelectedCourse   = team.SelectedCourse;
                Input.FirstName        = user.FirstName;
                Input.LastName         = user.LastName;
                Input.Email            = user.Email;
                Input.Phone            = team.Phone;
                Input.Allergies        = team.Allergies;
                Input.AddressStreet    = team.AddressStreet;
                Input.AddressAdditions = team.AddressAdditions;
                Input.AddressNumber    = team.AddressNumber;
                Input.PartnerFirstName = partnerFirstName;
                Input.PartnerLastName  = partnerLastName;
                Input.PartnerEmail     = partnerEmail;
                Input.DinnerSaver      = team.DinnerSaver;
                Input.IsWithoutPartner = eventParticipation.IsWithoutPartner;
            }

            else
            {
                Team  = null;
                Event = eventParticipation.Event;
                Input.SelectedCourse   = eventParticipation.SelectedCourse;
                Input.FirstName        = user.FirstName;
                Input.LastName         = user.LastName;
                Input.Email            = user.Email;
                Input.Phone            = eventParticipation.Phone;
                Input.Allergies        = eventParticipation.Allergies;
                Input.AddressStreet    = eventParticipation.Address;
                Input.AddressAdditions = eventParticipation.AddressAdditions;
                Input.AddressNumber    = eventParticipation.AddressNumber;
                Input.PartnerFirstName = eventParticipation.PartnerName;
                Input.PartnerLastName  = eventParticipation.PartnerLastName;
                Input.PartnerEmail     = eventParticipation.PartnerEmail;
                Input.DinnerSaver      = eventParticipation.DinnerSaver;
                Input.IsWithoutPartner = eventParticipation.IsWithoutPartner;
            }

            return(Page());
        }
        public async Task <IActionResult> OnGet()
        {
            if (HttpContext.Session.GetString("EventId") == null)
            {
                string returnUrl = HttpContext.Request.Path.ToString();
                return(RedirectToPage("/Account/Login", new { area = "Identity" }));
            }

            ViewData["IsParticipating"] = HttpContext.Session.GetString("IsParticipating");
            var             eventId = int.Parse(HttpContext.Session.GetString("EventId"), CultureInfo.CurrentCulture);
            ApplicationUser user    = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(Page());
            }

            bool isParticipating = IsUserParticipating(eventId, user.Id);

            ViewData["IsParticipating"] = isParticipating;
            HttpContext.Session.SetString("IsParticipating", isParticipating.ToString(CultureInfo.CurrentCulture));
            DinnerEvent dinnerEvent = DinnerEventsRepository.GetById(eventId);

            if (dinnerEvent != null)
            {
                // Values are passed-through to layout page
                ViewData["EventName"]        = dinnerEvent.EventName;
                ViewData["EventDate"]        = dinnerEvent.EventDate.ToShortDateString();
                ViewData["EventCity"]        = dinnerEvent.City;
                ViewData["EventPictureLink"] = dinnerEvent.EventPictureLink;
            }

            if (dinnerEvent == null)
            {
                return(Page());
            }
            ViewData["apiKey"]        = Configuration?.GetMapsSettings("apiKeyJs");
            ViewData["MapCenterLat"]  = "50.113745";
            ViewData["MapCenterLong"] = "8.679317";
            Event = dinnerEvent;

            // Load Team
            Team team = TeamsRepository.SearchFor(x => x.Event.Id == dinnerEvent.Id && (x.Partner1.Id == user.Id || x.Partner2.Id == user.Id)).Include("Partner1").Include("Partner2").Include("Event").FirstOrDefault();

            if (!dinnerEvent.RoutesOpen)
            {
                return(Page());
            }

            // Routes
            Route route = RoutesRepository.SearchFor(x => x.Event.Id == eventId && x.RouteForTeam.Id == team.Id)
                          .Include(a => a.Event)
                          .Include(a => a.RouteForTeam)
                          .Include(a => a.FirstCourseHostTeam).ThenInclude(b => b.Partner1)
                          .Include(a => a.FirstCourseHostTeam).ThenInclude(b => b.Partner2)
                          .Include(a => a.FirstCourseGuestTeam1).ThenInclude(b => b.Partner1)
                          .Include(a => a.FirstCourseGuestTeam1).ThenInclude(b => b.Partner2)
                          .Include(a => a.FirstCourseGuestTeam2).ThenInclude(b => b.Partner1)
                          .Include(a => a.FirstCourseGuestTeam2).ThenInclude(b => b.Partner2)
                          .Include(a => a.SecondCourseHostTeam).ThenInclude(b => b.Partner1)
                          .Include(a => a.SecondCourseHostTeam).ThenInclude(b => b.Partner2)
                          .Include(a => a.SecondCourseGuestTeam1).ThenInclude(b => b.Partner1)
                          .Include(a => a.SecondCourseGuestTeam1).ThenInclude(b => b.Partner2)
                          .Include(a => a.SecondCourseGuestTeam2).ThenInclude(b => b.Partner1)
                          .Include(a => a.SecondCourseGuestTeam2).ThenInclude(b => b.Partner2)
                          .Include(a => a.ThirdCourseHostTeam).ThenInclude(b => b.Partner1)
                          .Include(a => a.ThirdCourseHostTeam).ThenInclude(b => b.Partner2)
                          .Include(a => a.ThirdCourseGuestTeam1).ThenInclude(b => b.Partner1)
                          .Include(a => a.ThirdCourseGuestTeam1).ThenInclude(b => b.Partner2)
                          .Include(a => a.ThirdCourseGuestTeam2).ThenInclude(b => b.Partner1)
                          .Include(a => a.ThirdCourseGuestTeam2).ThenInclude(b => b.Partner2).FirstOrDefault();

            FirstCourseTeam  = route.FirstCourseHostTeam;
            SecondCourseTeam = route.SecondCourseHostTeam;
            ThirdCourseTeam  = route.ThirdCourseHostTeam;

            List <string> routeAddresses = new List <string>();

            // First Course Host
            routeAddresses.Add(route.FirstCourseHostTeam.FullAddress + ", " + dinnerEvent.City);
            // Second Course Host
            routeAddresses.Add(route.SecondCourseHostTeam.FullAddress + ", " + dinnerEvent.City);
            // Third Course Host
            routeAddresses.Add(route.ThirdCourseHostTeam.FullAddress + ", " + dinnerEvent.City);

            List <string> kitchenCoordinates = new List <string>();

            foreach (var routeAddress in routeAddresses)
            {
                string coordinateString = HereMapsHelper.GetCoordinatesWithAddressString(routeAddress);
                kitchenCoordinates.Add(coordinateString);
            }

            ViewData["KitchenCoordinates"] = kitchenCoordinates.ToArray();

            List <string> routeCoordinates = new List <string>();

            foreach (var routeAddress in routeAddresses)
            {
                string coordinateString = HereMapsHelper.GetCoordinatesString(routeAddress);
                routeCoordinates.Add(coordinateString);
            }

            ViewData["RouteCoordinates"] = routeCoordinates;
            string partyLocationCoordinateString = HereMapsHelper.GetCoordinatesWithAddressString(dinnerEvent.PartyLocation);

            ViewData["PartyLocation"] = partyLocationCoordinateString;
            return(Page());
        }