Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public KudosLogsEntriesDto <MainKudosLogDTO> GetKudosLogs(KudosLogsFilterDTO options)
        {
            var kudosLogsQuery = _kudosLogsDbSet
                                 .Include(log => log.Employee)
                                 .Where(log =>
                                        log.OrganizationId == options.OrganizationId &&
                                        log.KudosBasketId == null)
                                 .Where(KudosServiceHelper.StatusFilter(options.Status))
                                 .Where(KudosServiceHelper.UserFilter(options.SearchUserId))
                                 .GroupJoin(_usersDbSet, log => log.CreatedBy, u => u.Id, KudosServiceHelper.MapKudosLogsToDto())
                                 .OrderBy(string.Concat(options.SortBy, " ", options.SortOrder));

            var logsTotalCount     = kudosLogsQuery.Count();
            int entriesCountToSkip = EntriesCountToSkip(options.Page);
            var kudosLogs          = kudosLogsQuery
                                     .Skip(() => entriesCountToSkip)
                                     .Take(() => ConstBusinessLayer.MaxKudosLogsPerPage)
                                     .ToList();

            foreach (var kudosLog in kudosLogs)
            {
                if (IsTranslatableKudosType(kudosLog.Type.Type))
                {
                    kudosLog.Type.Name = TranslateKudos(options.UserId, "KudosType" + kudosLog.Type.Name);
                }
            }

            return(new KudosLogsEntriesDto <MainKudosLogDTO>
            {
                KudosLogs = kudosLogs,
                TotalKudosCount = logsTotalCount
            });
        }
Exemplo n.º 3
0
        public async Task <KudosLogsEntriesDto <MainKudosLogDto> > GetKudosLogsAsync(KudosLogsFilterDto options)
        {
            var kudosLogsQuery = _kudosLogsDbSet
                                 .Include(log => log.Employee)
                                 .Where(log => log.OrganizationId == options.OrganizationId && log.KudosBasketId == null)
                                 .Where(KudosServiceHelper.StatusFilter(options.Status))
                                 .Where(KudosServiceHelper.UserFilter(options.SearchUserId))
                                 .Where(KudosServiceHelper.TypeFilter(options.FilteringType))
                                 .GroupJoin(_usersDbSet, log => log.CreatedBy, u => u.Id, KudosServiceHelper.MapKudosLogsToDto())
                                 .OrderBy(string.Concat(options.SortBy, " ", options.SortOrder));

            var logsTotalCount = await kudosLogsQuery.CountAsync();

            var entriesCountToSkip = EntriesCountToSkip(options.Page);
            var kudosLogs          = await kudosLogsQuery
                                     .Skip(() => entriesCountToSkip)
                                     .Take(() => BusinessLayerConstants.MaxKudosLogsPerPage)
                                     .ToListAsync();

            var user = await _usersDbSet.FindAsync(options.UserId);

            if (user != null)
            {
                var culture = CultureInfo.GetCultureInfo(user.CultureCode);

                foreach (var kudosLog in kudosLogs)
                {
                    if (IsTranslatableKudosType(kudosLog.Type.Type))
                    {
                        kudosLog.Type.Name = TranslateKudos("KudosType" + kudosLog.Type.Name, culture);
                    }
                }
            }

            return(new KudosLogsEntriesDto <MainKudosLogDto>
            {
                KudosLogs = kudosLogs,
                TotalKudosCount = logsTotalCount
            });
        }