Exemple #1
0
        public async Task <byte[]> ExportParticipantsAsync(int lotteryId, UserAndOrganizationDto userAndOrg)
        {
            var participants = await _participantService.GetParticipantsCountedAsync(lotteryId);

            var numberOfTicketsAdded = 0;
            var participantTickets   = new List <string>();
            var tickets = new List <List <string> >();

            foreach (var participant in participants)
            {
                for (var i = 0; i < participant.Tickets; i++)
                {
                    participantTickets.Add(participant.FullName);

                    numberOfTicketsAdded++;

                    if (numberOfTicketsAdded % BusinessLayerConstants.LotteryParticipantsInRow == 0)
                    {
                        tickets.Add(participantTickets);
                        participantTickets = new List <string>();
                    }
                }
            }

            tickets.Add(participantTickets);
            _excelBuilder.AddNewWorksheet(BusinessLayerConstants.LotteryParticipantsExcelTableName, tickets);

            return(_excelBuilder.GenerateByteArray());
        }
        public byte[] ExportToExcel(KudosLogsFilterDTO filter)
        {
            var kudosLogs = _kudosLogsDbSet
                .Include(log => log.Employee)
                .Where(log =>
                    log.OrganizationId == filter.OrganizationId &&
                    log.KudosBasketId == null)
                .Where(KudosServiceHelper.StatusFilter(filter.Status))
                .Where(KudosServiceHelper.UserFilter(filter.SearchUserId))
                .GroupJoin(_userDbSet, log => log.CreatedBy, u => u.Id, KudosServiceHelper.MapKudosLogsToDto())
                .OrderBy(string.Concat(filter.SortBy, " ", filter.SortOrder))
                .AsEnumerable()
                .Select(x => new List<object>
                {
                    x.Sender.FullName,
                    x.Receiver.FullName,
                    x.Type.Name,
                    x.Multiplier,
                    x.Points,
                    x.Created,
                    x.Comment,
                    x.Status,
                    x.Type.Value,
                    x.RejectionMessage
                });

            var header = new List<string>
            {
                Resources.Models.Kudos.Kudos.ExportColumnSender,
                Resources.Models.Kudos.Kudos.ExportColumnReceiver,
                Resources.Models.Kudos.Kudos.ExportColumnKudosType,
                Resources.Models.Kudos.Kudos.ExportColumnMultiplyBy,
                Resources.Models.Kudos.Kudos.ExportColumnPointsInTotal,
                Resources.Models.Kudos.Kudos.ExportColumnCreated,
                Resources.Models.Kudos.Kudos.ExportColumnComment,
                Resources.Models.Kudos.Kudos.ExportColumnStatus,
                Resources.Models.Kudos.Kudos.ExportColumnKudosTypeValue,
                Resources.Models.Kudos.Kudos.ExportColumnRejectionMessage
            };

            _excelBuilder.AddNewWorksheet(
                ConstBusinessLayer.KudosLogExcelSheetName,
                header,
                kudosLogs);

            return _excelBuilder.GenerateByteArray();
        }
        public async Task<byte[]> ExportToExcelAsync(UserAndOrganizationDto userAndOrg, Expression<Func<ServiceRequest, bool>> filter)
        {
            var query = _serviceRequestsDbSet
                .Include(x => x.Status)
                .Include(x => x.Priority)
                .Include(x => x.Employee)
                .Where(x => x.OrganizationId == userAndOrg.OrganizationId);

            if (filter != null)
            {
                query = query.Where(filter);
            }

            var serviceRequests = (await query.OrderByDescending(x => x.Created).ToListAsync())
                .Select(x => new List<object>
                {
                    x.Title,
                    x.Description,
                    x.CategoryName,
                    x.Status?.Title,
                    x.Priority?.Title,
                    x.Employee?.FullName,
                    x.KudosAmmount,
                    x.KudosShopItem?.Name,
                    x.Created,
                    x.Modified
                });

            var header = new List<string>
            {
                Resources.Models.ServiceRequest.ServiceRequest.ExportColumnNameTitle,
                Resources.Models.ServiceRequest.ServiceRequest.ExportColumnNameDescription,
                Resources.Models.ServiceRequest.ServiceRequest.ExportColumnNameCategory,
                Resources.Models.ServiceRequest.ServiceRequest.ExportColumnNameStatus,
                Resources.Models.ServiceRequest.ServiceRequest.ExportColumnNamePriority,
                Resources.Models.ServiceRequest.ServiceRequest.ExportColumnNameUser,
                Resources.Models.ServiceRequest.ServiceRequest.ExportColumnNameKudosAmount,
                Resources.Models.ServiceRequest.ServiceRequest.ExportColumnNameKudosShopItem,
                Resources.Models.ServiceRequest.ServiceRequest.ExportColumnNameDate,
                Resources.Models.ServiceRequest.ServiceRequest.ExportColumnNameModified
            };

            _excelBuilder.AddNewWorksheet(ServiceRequestConstants.ServiceRequestsExcelSheetName, header, serviceRequests);

            return _excelBuilder.GenerateByteArray();
        }
        public async Task <byte[]> ExportOptionsAndParticipantsAsync(Guid eventId, UserAndOrganizationDto userAndOrg)
        {
            var participants = (await _eventParticipationService.GetEventParticipantsAsync(eventId, userAndOrg))
                               .Select(x => new List <string> {
                x.FirstName, x.LastName
            });

            var options = (await _eventUtilitiesService.GetEventChosenOptionsAsync(eventId, userAndOrg))
                          .Select(x => new List <string> {
                x.Option, x.Count.ToString()
            })
                          .ToList();

            AddParticipants(participants);

            if (options.Any())
            {
                AddOptions(options);
            }

            return(_excelBuilder.GenerateByteArray());
        }