示例#1
0
        public async Task <IActionResult> SendReminderEmailForAllEvents(
            [FromQuery] PagingOptions pagingOptions,
            [FromQuery] SortOptions <Event, EventEntity> sortOptions,
            [FromQuery] SearchOptions <Event, EventEntity> searchOptions,
            CancellationToken ct)
        {
            pagingOptions.Offset = pagingOptions.Offset ?? _defaultPagingOptions.Offset;
            pagingOptions.Limit  = pagingOptions.Limit ?? _defaultPagingOptions.Limit;

            var events = await _event.GetAllAsync(pagingOptions, sortOptions, searchOptions, ct);

            foreach (var @event in events.Items)
            {
                foreach (var participant in @event.Participant.Where(x => !x.IsFeedbackReceived))
                {
                    var feedbackType = participant.Attended ? "participated" :
                                       participant.NotAttended ? "notparticipated" : "unregistered";

                    var emailModel = new FeedbackRequestEmailTemplateModel
                    {
                        EventName       = @event.EventName,
                        EventDate       = @event.EventDate.ToShortDateString(),
                        ParticipantName = participant.EmployeeName,
                        FeedbackUrl     = $"{_configuration.GetSection("EmailUrl").Value}/feedback/{feedbackType}/{@event.Id}/{participant.Id}"
                    };

                    var body = await _renderer.RenderPartialToStringAsync("_FeedbackRequestEmailPartial", emailModel);

                    await _emailService.SendAsync(User.Identity.Name, "Admin", participant.EmployeeId, $"Feedback Requested for {@event.EventName} at {@event.EventDate}", body);
                }
            }

            return(Ok());
        }
        public async Task <ActionResult <Collection <Event> > > GetAllEvents(
            [FromQuery] PagingOptions pagingOptions,
            [FromQuery] SortOptions <Event, EventEntity> sortOptions,
            [FromQuery] SearchOptions <Event, EventEntity> searchOptions,
            CancellationToken ct)
        {
            pagingOptions.Offset = pagingOptions.Offset ?? _defaultPagingOptions.Offset;
            pagingOptions.Limit  = pagingOptions.Limit ?? _defaultPagingOptions.Limit;

            var events = new PagedResults <Event>
            {
                Items = Enumerable.Empty <Event>()
            };

            if (User.Identity.IsAuthenticated)
            {
                var canSeeAllEvents = await _authzService.AuthorizeAsync(
                    User, "ViewAllEventsPolicy");

                if (canSeeAllEvents.Succeeded)
                {
                    events = await _event.GetAllAsync(pagingOptions, sortOptions, searchOptions, ct);
                }
                else
                {
                    var userId = await _user.GetUserIdAsync(User);

                    events = await _event.GetAllByByPocAsync(pagingOptions, sortOptions, searchOptions, Convert.ToInt64(User.Identity.Name.Split('@')[0]), ct);
                }
            }

            var collection = PagedCollection <Event> .Create <EventResponse>(
                Link.ToCollection(nameof(GetAllEvents)),
                events.Items.ToArray(),
                events.TotalSize,
                pagingOptions);

            //TODO
            collection.EventsQuery = FormMetadata.FromResource <Event>(
                Link.ToForm(
                    nameof(GetAllEvents),
                    null,
                    Link.GetMethod,
                    Form.QueryRelation));

            return(collection);
        }