Exemplo 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());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            var dinnerEvent = new DinnerEvent
            {
                EventName         = Input.EventName,
                EventDate         = Input.EventDate,
                LastRegisterDate  = Input.LastRegisterDate,
                PartyLocation     = Input.PartyLocation,
                PartyLocationName = Input.PartyLocationName,
                City             = Input.City,
                EventPictureLink = Input.EventPictureLink,
                RoutesOpen       = false
            };

            _dinnerEventsRepository.Insert(dinnerEvent);
            _dinnerEventsRepository.SaveChanges();
            var apiKey    = _configuration.GetEmailSettings("apiKey");
            var apiSecret = _configuration.GetEmailSettings("apiSecret");
            int id        = await _emailSender.CreateContactListAsync(apiKey, apiSecret, Input.EventName);

            if (id != 0)
            {
                dinnerEvent.ContactList = id;
                _dinnerEventsRepository.Update(dinnerEvent);
            }

            _dinnerEventsRepository.SaveChanges();
            StatusMessage = "Dein Event wurde erstellt.";
            return(RedirectToPage());
        }
Exemplo 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());
        }
        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());
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
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());
        }