public async Task CheckRegistrationCreateAccessAsync(
            Registration registration,
            CancellationToken cancellationToken)
        {
            var user      = _httpContextAccessor.HttpContext.User;
            var eventInfo =
                await _eventInfoRetrievalService.GetEventInfoByIdAsync(registration.EventInfoId, cancellationToken);

            // Add possibility for organization admin to override later
            if (!user.IsSystemAdmin())
            {
                if (eventInfo.Status != EventInfo.EventInfoStatus.RegistrationsOpen &&
                    eventInfo.Status != EventInfo.EventInfoStatus.WaitingList)
                {
                    throw new NotAccessibleException(
                              $"Registrations are closed for event {eventInfo.Title} with id {eventInfo.EventInfoId}.");
                }
            }

            if (!await CheckOwnerOrAdminAccessAsync(user, registration, cancellationToken))
            {
                throw new NotAccessibleException(
                          $"User {user.GetUserId()} cannot create registration for event {registration.EventInfoId} and user {registration.UserId}");
            }
        }
        public async Task <IActionResult> List(int id,
                                               [FromQuery] EventCertificateQueryDto query,
                                               CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.FormatErrors()));
            }

            var eventInfo = await _eventInfoRetrievalService.GetEventInfoByIdAsync(id, cancellationToken);

            await _eventInfoAccessControlService.CheckEventManageAccessAsync(eventInfo, cancellationToken);

            var certificates = await _certificateRetrievalService
                               .ListCertificatesAsync(new CertificateListRequest
            {
                Limit  = query.Limit,
                Offset = query.Offset,
                Filter = new CertificateFilter
                {
                    EventId = id
                }
            }, new CertificateRetrievalOptions
            {
                LoadIssuingOrganization = true,
                LoadIssuingUser         = true,
                LoadRecipientUser       = true
            }, cancellationToken);

            return(Ok(PageResponseDto <EventDto> .FromPaging(
                          query, certificates,
                          c => new CertificateDto(c))));
        }
Esempio n. 3
0
        public async Task <ActionResult <EventDto> > Get(int id, CancellationToken cancellationToken)
        {
            var eventInfo = await _eventInfoService.GetEventInfoByIdAsync(id, cancellationToken : cancellationToken);

            if (eventInfo == null || eventInfo.Archived)
            {
                return(NotFound());
            }
            return(Ok(new EventDto(eventInfo)));
        }
        public async Task <Registration> CreateRegistrationAsync(
            int eventId,
            string userId,
            Action <Registration> fillAction,
            CancellationToken cancellationToken)
        {
            var @event = await _eventInfoRetrievalService.GetEventInfoByIdAsync(eventId, null, cancellationToken); // To check event reference only

            var user = await _userRetrievalService.GetUserByIdAsync(userId, cancellationToken);

            var registration = new Registration
            {
                EventInfoId     = eventId,
                UserId          = userId,
                ParticipantName = user.Name // TODO: remove this property?
            };

            fillAction?.Invoke(registration);

            await _registrationAccessControlService.CheckRegistrationCreateAccessAsync(registration, cancellationToken);

            await _context.CreateAsync(registration, cancellationToken);

            return(registration);
        }
        private async Task <bool> CheckAdminAccessAsync(
            ClaimsPrincipal user,
            Registration registration,
            CancellationToken cancellationToken)
        {
            if (user.IsSystemAdmin() || user.IsSuperAdmin())
            {
                return(true);
            }

            if (!user.IsAdmin())
            {
                return(false);
            }

            var org = await _currentOrganizationAccessorService.RequireCurrentOrganizationAsync(new OrganizationRetrievalOptions
            {
                LoadMembers = true
            }, cancellationToken);

            if (org.Members.All(m => m.UserId != user.GetUserId()))
            {
                return(false);
            }

            var @event = await _eventInfoRetrievalService.GetEventInfoByIdAsync(registration.EventInfoId, cancellationToken);

            return(@event.OrganizationId.HasValue && @event.OrganizationId.Value == org.OrganizationId);
        }
 /// <summary>
 /// Shortcut for <see cref="IEventInfoRetrievalService.GetEventInfoByIdAsync"/>.
 /// </summary>
 public static Task <EventInfo> GetEventInfoByIdAsync(
     this IEventInfoRetrievalService service,
     int id,
     CancellationToken cancellationToken = default)
 {
     return(service.GetEventInfoByIdAsync(id, null, cancellationToken));
 }
Esempio n. 7
0
        private async Task CheckEventAccessAsync(int eventId)
        {
            var eventInfo = await _eventInfoRetrievalService
                            .GetEventInfoByIdAsync(eventId);

            await _eventInfoAccessControlService
            .CheckEventManageAccessAsync(eventInfo);
        }
Esempio n. 8
0
        public async Task <IActionResult> GenerateCertificatesAndSendEmails(int eventId,
                                                                            CancellationToken cancellationToken)
        {
            var eventInfo = await _eventInfoRetrievalService
                            .GetEventInfoByIdAsync(eventId, cancellationToken);

            var certificates = await _certificateIssuingService
                               .CreateCertificatesForEventAsync(eventInfo, cancellationToken);

            foreach (var certificate in certificates
                     .TakeWhile(_ => !cancellationToken.IsCancellationRequested))
            {
                await _certificateDeliveryService.SendCertificateAsync(certificate, cancellationToken);
            }

            return(Ok());
        }
        public async Task <IActionResult> OnGetAsync(int id)
        {
            EventInfo = await _eventsService.GetEventInfoByIdAsync(id, new EventInfoRetrievalOptions
            {
                LoadProducts = true
            });

            if (EventInfo == null)
            {
                return(NotFound());
            }

            PaymentMethods = await _paymentMethodService.GetActivePaymentMethodsAsync();

            Registration = new RegisterVM(EventInfo, DefaultPaymentMethod);

            return(Page());
        }
Esempio n. 10
0
        public async Task <IActionResult> OnGetAsync(int id)
        {
            EventInfo = await _eventInfoRetrievalService.GetEventInfoByIdAsync(id);

            if (EventInfo == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Esempio n. 11
0
        public async Task <IActionResult> ViewCertificateForEvent(int id)
        {
            var eventInfo = await _eventInfoRetrievalService
                            .GetEventInfoByIdAsync(id,
                                                   EventInfoRetrievalOptions.ForCertificateRendering);

            var html = await _certificateRenderer
                       .RenderToHtmlAsStringAsync(new CertificateViewModel(eventInfo));

            return(Content(html, MediaTypeNames.Text.Html));
        }
Esempio n. 12
0
        public async Task <IActionResult> ViewCertificateForEvent([FromRoute] int id,
                                                                  [FromServices] IEventInfoRetrievalService eventInfoService)
        {
            var eventInfo = await eventInfoService.GetEventInfoByIdAsync(id, new EventInfoRetrievalOptions
            {
                LoadOrganizerUser = true,
                LoadOrganization  = true
            });

            if (eventInfo == null)
            {
                return(NotFound());
            }
            var vm = CertificateVM.Mock;

            vm.Title       = eventInfo.Title;
            vm.Description = eventInfo.CertificateDescription;

            vm.EvidenceDescription = $"{eventInfo.Title} {eventInfo.City}";
            if (eventInfo.DateStart.HasValue)
            {
                vm.EvidenceDescription += " - " + eventInfo.DateStart.Value.ToString("d");
            }
            ;
            if (eventInfo.DateEnd.HasValue)
            {
                vm.EvidenceDescription += " - " + eventInfo.DateEnd.Value.ToString("d");
            }
            ;

            vm.IssuedInCity = eventInfo.City;

            if (eventInfo.OrganizerUser != null)
            {
                vm.IssuerPersonName = eventInfo.OrganizerUser.Name;
            }

            if (eventInfo.OrganizerUser != null && !string.IsNullOrWhiteSpace(eventInfo.OrganizerUser.SignatureImageBase64))
            {
                vm.IssuerPersonSignatureImageBase64 = eventInfo.OrganizerUser.SignatureImageBase64;
            }

            if (eventInfo.Organization != null)
            {
                vm.IssuerOrganizationName = eventInfo.Organization.Name;
            }

            if (eventInfo.Organization != null && !string.IsNullOrWhiteSpace(eventInfo.Organization.LogoBase64))
            {
                vm.IssuerOrganizationLogoBase64 = eventInfo.Organization.LogoBase64;
            }

            return(View("Templates/Certificates/CourseCertificate", vm));
        }
Esempio n. 13
0
        public async Task <IActionResult> List(int id)
        {
            try
            {
                await _eventInfoService.GetEventInfoByIdAsync(id);
            }
            catch (InvalidOperationException)
            {
                return(NotFound());
            }

            var externalEvents = await _externalEventManagementService.ListExternalEventsAsync(id);

            return(Json(externalEvents.Select(c => new ExternalEventDto
            {
                LocalId = c.LocalId,
                ExternalEventId = c.ExternalEventId,
                ExternalServiceName = c.ExternalServiceName
            })));
        }
        private async Task <Product> GetProductAsync(int eventId, int productId, bool forUpdate = false,
                                                     CancellationToken token = default)
        {
            var eventInfo = await _eventInfoRetrievalService.GetEventInfoByIdAsync(eventId,
                                                                                   new EventInfoRetrievalOptions
            {
                ForUpdate    = forUpdate,
                LoadProducts = true
            }, token);

            return(eventInfo.Products
                   .FirstOrDefault(p => p.ProductId == productId)
                   ?? throw new NotFoundException($"Product {productId} not found for event {eventId}"));
        }
        public async Task <IActionResult> OnGetAsync(int id)
        {
            // Get orders for
            Orders = await _orders.GetOrdersForEventAsync(id);

            EventInfo = await _eventInfos.GetEventInfoByIdAsync(id, new EventInfoRetrievalOptions
            {
                LoadProducts = true
            });

            Registrations = await _registrations.GetRegistrationsWithOrders(id);

            Registrations.OrderBy(m => m.ParticipantName);
            return(Page());
        }
        public async Task <EventSynchronizationResult[]> SyncEvent(
            int eventId,
            string syncProviderName,
            CancellationToken cancellationToken)
        {
            var eventInfo = await _eventInfoRetrievalService.GetEventInfoByIdAsync(eventId);

            var results = new List <EventSynchronizationResult>();

            var filteredServices = await FilterProvidersAsync(eventInfo, syncProviderName, results);

            foreach (var syncProviderService in filteredServices)
            {
                results.Add(await SyncAllRegistrationsAsync(syncProviderService, eventInfo, cancellationToken));
            }

            return(results.ToArray());
        }
Esempio n. 17
0
        public async Task <IActionResult> OnGetAsync(int id, string slug)
        {
            EventInfo = await _eventsService.GetEventInfoByIdAsync(id, new EventInfoRetrievalOptions
            {
                LoadProducts = true
            });

            if (EventInfo == null)
            {
                return(NotFound());
            }

            if (EventInfo.Code != slug)
            {
                return(RedirectToPage("./Details", new { id, slug = EventInfo.Code }));
            }

            return(Page());
        }
Esempio n. 18
0
        public async Task <ProductDto[]> List(int eventId, [FromQuery] EventProductsQueryDto query,
                                              CancellationToken token)
        {
            var eventInfo = await _eventInfoRetrievalService.GetEventInfoByIdAsync(eventId, token);

            await _eventInfoAccessControlService.CheckEventReadAccessAsync(eventInfo, token);

            var products = await _productRetrievalService
                           .ListProductsAsync(new ProductListRequest(eventId)
            {
                Filter = query.ToProductFilter()
            }, new ProductRetrievalOptions
            {
                LoadVariants = true
            }, token);

            return(products
                   .Select(p => new ProductDto(p))
                   .ToArray());
        }
        public async Task <ActionResult <OnlineCourseDto> > Get(int id)
        {
            var eventInfo = await _eventInfoService.GetEventInfoByIdAsync(id);

            if (eventInfo == null)
            {
                return(NotFound());
            }

            var dto = new OnlineCourseDto()
            {
                Id          = eventInfo.EventInfoId,
                Name        = eventInfo.Title,
                Slug        = eventInfo.Code,
                Description = eventInfo.Description,
                Featured    = eventInfo.Featured
            };

            return(Ok(dto));
        }
Esempio n. 20
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            try
            {
                EventInfo = await _eventInfoRetrievalService.GetEventInfoByIdAsync(id.Value,
                                                                                   new EventInfoRetrievalOptions
                {
                    LoadProducts = true
                });
            }
            catch (InvalidOperationException)
            {
                return(NotFound());
            }

            return(await PageAsync());
        }
Esempio n. 21
0
        public async Task <ActionResult <EventDto> > Get(int id)
        {
            var eventInfo = await _eventInfoService.GetEventInfoByIdAsync(id);

            if (eventInfo == null)
            {
                return(NotFound());
            }

            var dto = new EventDto()
            {
                Id          = eventInfo.EventInfoId,
                Name        = eventInfo.Title,
                Slug        = eventInfo.Slug,
                Description = eventInfo.Description,
                StartDate   = eventInfo.DateStart,
                EndDate     = eventInfo.DateEnd,
                Featured    = eventInfo.Featured
            };

            return(Ok(dto));
        }
Esempio n. 22
0
        public async Task <IActionResult> OnGet(int id)
        {
            if (id is 0)
            {
                return(BadRequest());
            }
            EventInfo = await _eventsService.GetEventInfoByIdAsync(id, new EventInfoRetrievalOptions
            {
                LoadProducts = true
            });

            if (EventInfo is null)
            {
                return(NotFound());
            }
            Vm = new EventProductsModelVM
            {
                EventInfoId = EventInfo.EventInfoId,
                Products    = EventInfo.Products
            };
            return(Page());
        }
Esempio n. 23
0
 public async Task<IActionResult> OnGetAsync(int id)
 {
     EventInfo = await _eventinfos.GetEventInfoByIdAsync(id);
     return Page();
 }
        public async Task OnGetAsync(int id)
        {
            Messages = await _messageLogService.Get(id);

            EventInfo = await _eventinfos.GetEventInfoByIdAsync(id);
        }
        public async Task <Registration> CreateRegistrationAsync(
            int eventId,
            string userId,
            RegistrationOptions options,
            CancellationToken cancellationToken)
        {
            var existingRegistration = await _context.Registrations
                                       .FirstOrDefaultAsync(m => m.EventInfoId == eventId &&
                                                            m.UserId == userId, cancellationToken : cancellationToken);

            if (existingRegistration != null)
            {
                throw new DuplicateException("Found existing registration for user on event.");
            }

            var eventInfo = await _eventInfoRetrievalService.GetEventInfoByIdAsync(eventId,
                                                                                   new EventInfoRetrievalOptions
            {
                ForUpdate         = true,
                LoadRegistrations = true,
                LoadProducts      = true
            },
                                                                                   cancellationToken);

            var user = await _userRetrievalService.GetUserByIdAsync(userId, null, cancellationToken);

            var registration = new Registration
            {
                EventInfoId     = eventId,
                UserId          = userId,
                ParticipantName = user.Name // TODO: remove this property?
            };

            await _registrationAccessControlService.CheckRegistrationCreateAccessAsync(registration, cancellationToken);

            if (eventInfo.Status == EventInfo.EventInfoStatus.WaitingList)
            {
                registration.Status = Registration.RegistrationStatus.WaitingList;
            }

            await _context.CreateAsync(registration, cancellationToken : cancellationToken);

            options ??= new RegistrationOptions();

            if (options.CreateOrder && registration.Status != Registration.RegistrationStatus.WaitingList)
            {
                var mandatoryItems = eventInfo.Products
                                     .Where(p => p.IsMandatory)
                                     .Select(p => new OrderItemDto
                {
                    ProductId = p.ProductId,
                    Quantity  = p.MinimumQuantity
                }).ToArray();

                if (mandatoryItems.Any())
                {
                    await _registrationOrderManagementService
                    .CreateOrderForRegistrationAsync(
                        registration.RegistrationId,
                        mandatoryItems,
                        cancellationToken);
                }
            }

            if (eventInfo.MaxParticipants > 0 && eventInfo
                .Registrations.Count + 1 >= eventInfo.MaxParticipants)
            {
                eventInfo.Status = EventInfo.EventInfoStatus.WaitingList;
                await _context.SaveChangesAsync(cancellationToken);
            }

            return(registration);
        }