public async Task <IActionResult> GetEventPartners(Guid eventId, CancellationToken cancellationToken)
        {
            var displayEventPartners = new List <DisplayEventPartner>();
            var currentPartners      = await eventPartnerRepository.GetEventPartners(eventId, cancellationToken).ConfigureAwait(false);

            var possiblePartners = await eventPartnerRepository.GetPotentialEventPartners(eventId, cancellationToken).ConfigureAwait(false);

            // Convert the current list of partners for the event to a display partner (reduces round trips)
            foreach (var cp in currentPartners.ToList())
            {
                var displayEventPartner = new DisplayEventPartner
                {
                    EventId              = eventId,
                    PartnerId            = cp.PartnerId,
                    PartnerLocationId    = cp.PartnerLocationId,
                    EventPartnerStatusId = cp.EventPartnerStatusId,
                };

                var partner = await partnerRepository.GetPartner(cp.PartnerId, cancellationToken).ConfigureAwait(false);

                displayEventPartner.PartnerName = partner.Name;

                var partnerLocation = partnerLocationRepository.GetPartnerLocations(cancellationToken).FirstOrDefault(pl => pl.PartnerId == cp.PartnerId && pl.Id == cp.PartnerLocationId);

                displayEventPartner.PartnerLocationName  = partnerLocation.Name;
                displayEventPartner.PartnerLocationNotes = partnerLocation.Notes;

                displayEventPartners.Add(displayEventPartner);
            }

            // Convert the current list of possible partners for the event to a display partner unless the partner location is already included (reduces round trips)
            foreach (var pp in possiblePartners.ToList())
            {
                if (!displayEventPartners.Any(ep => ep.PartnerLocationId == pp.Id))
                {
                    var displayEventPartner = new DisplayEventPartner
                    {
                        EventId              = eventId,
                        PartnerId            = pp.PartnerId,
                        PartnerLocationId    = pp.Id,
                        EventPartnerStatusId = (int)EventPartnerStatusEnum.None,
                        PartnerLocationName  = pp.Name,
                        PartnerLocationNotes = pp.Notes,
                    };

                    var partner = await partnerRepository.GetPartner(pp.PartnerId, cancellationToken).ConfigureAwait(false);

                    displayEventPartner.PartnerName = partner.Name;

                    displayEventPartners.Add(displayEventPartner);
                }
            }

            return(Ok(displayEventPartners));
        }
Beispiel #2
0
        public async Task <IActionResult> GetPartnerEvents(Guid partnerId, CancellationToken cancellationToken)
        {
            // Make sure the person adding the user is either an admin or already a user for the partner
            var currentUser = await userRepository.GetUserByNameIdentifier(User.FindFirst(ClaimTypes.NameIdentifier).Value, cancellationToken).ConfigureAwait(false);

            if (!currentUser.IsSiteAdmin)
            {
                var currentUserPartner = partnerUserRepository.GetPartnerUsers(cancellationToken).FirstOrDefault(pu => pu.PartnerId == partnerId && pu.UserId == currentUser.Id);

                if (currentUserPartner == null)
                {
                    return(Forbid());
                }
            }

            var displayPartnerEvents = new List <DisplayPartnerEvent>();
            var currentPartners      = await eventPartnerRepository.GetPartnerEvents(partnerId, cancellationToken).ConfigureAwait(false);

            if (currentPartners.Any())
            {
                var partner = await partnerRepository.GetPartner(partnerId, cancellationToken).ConfigureAwait(false);

                // Convert the current list of partner events for the event to a display partner (reduces round trips)
                foreach (var cp in currentPartners.ToList())
                {
                    var displayPartnerEvent = new DisplayPartnerEvent
                    {
                        EventId              = cp.EventId,
                        PartnerId            = partnerId,
                        PartnerLocationId    = cp.PartnerLocationId,
                        EventPartnerStatusId = cp.EventPartnerStatusId,
                    };

                    displayPartnerEvent.PartnerName = partner.Name;

                    var partnerLocation = partnerLocationRepository.GetPartnerLocations(cancellationToken).FirstOrDefault(pl => pl.PartnerId == cp.PartnerId && pl.Id == cp.PartnerLocationId);

                    displayPartnerEvent.PartnerLocationName = partnerLocation.Name;

                    var mobEvent = await eventRepository.GetEvent(cp.EventId, cancellationToken).ConfigureAwait(false);

                    displayPartnerEvent.EventName          = mobEvent.Name;
                    displayPartnerEvent.EventStreetAddress = mobEvent.StreetAddress;
                    displayPartnerEvent.EventCity          = mobEvent.City;
                    displayPartnerEvent.EventRegion        = mobEvent.Region;
                    displayPartnerEvent.EventCountry       = mobEvent.Country;
                    displayPartnerEvent.EventPostalCode    = mobEvent.PostalCode;
                    displayPartnerEvent.EventDescription   = mobEvent.Description;
                    displayPartnerEvent.EventDate          = mobEvent.EventDate;

                    displayPartnerEvents.Add(displayPartnerEvent);
                }
            }

            return(Ok(displayPartnerEvents));
        }
 public IActionResult GetPartnerLocations(Guid partnerId, CancellationToken cancellationToken)
 {
     return(Ok(partnerLocationRepository.GetPartnerLocations(cancellationToken).Where(pl => pl.PartnerId == partnerId).ToList()));
 }