예제 #1
0
        public async Task <string> ExportToExcelAsync(string searchString = "")
        {
            var userSpec = new UserFilterSpecification(searchString);
            var users    = await _userManager.Users
                           .Specify(userSpec)
                           .OrderByDescending(a => a.CreatedOn)
                           .ToListAsync();

            var result = await _excelService.ExportAsync(users, sheetName : _localizer["Users"],
                                                         mappers : new Dictionary <string, Func <BlazorHeroUser, object> >
            {
                { _localizer["Id"], item => item.Id },
                { _localizer["FirstName"], item => item.FirstName },
                { _localizer["LastName"], item => item.LastName },
                { _localizer["UserName"], item => item.UserName },
                { _localizer["Email"], item => item.Email },
                { _localizer["EmailConfirmed"], item => item.EmailConfirmed },
                { _localizer["PhoneNumber"], item => item.PhoneNumber },
                { _localizer["PhoneNumberConfirmed"], item => item.PhoneNumberConfirmed },
                { _localizer["IsActive"], item => item.IsActive },
                { _localizer["CreatedOn (Local)"], item => DateTime.SpecifyKind(item.CreatedOn, DateTimeKind.Utc).ToLocalTime().ToString("G", CultureInfo.CurrentCulture) },
                { _localizer["CreatedOn (UTC)"], item => item.CreatedOn.ToString("G", CultureInfo.CurrentCulture) },
                { _localizer["ProfilePictureDataUrl"], item => item.ProfilePictureDataUrl },
            });

            return(result);
        }
예제 #2
0
        public async Task <string> Handle(ExportQuery request, CancellationToken cancellationToken)
        {
            var products = await _unitOfWork.Repository <Product>().GetAllAsync();

            var data = await _excelService.ExportAsync(products, mappers : new Dictionary <string, Func <Product, object> >()
            {
                { _localizer["Id"], item => item.Id },
                { _localizer["Name"], item => item.Name },
                { _localizer["Barcode"], item => item.Barcode },
                { _localizer["Description"], item => item.Description },
                { _localizer["Rate"], item => item.Rate }
            }, sheetName : _localizer["Products"]);

            return(data);
        }
예제 #3
0
        public async Task <Result <string> > Handle(ExportDocumentTypesQuery request, CancellationToken cancellationToken)
        {
            var documentTypeFilterSpec = new DocumentTypeFilterSpecification(request.SearchString);
            var documentTypes          = await _unitOfWork.Repository <DocumentType>().Entities
                                         .Specify(documentTypeFilterSpec)
                                         .ToListAsync(cancellationToken);

            var data = await _excelService.ExportAsync(documentTypes, mappers : new Dictionary <string, Func <DocumentType, object> >
            {
                { _localizer["Id"], item => item.Id },
                { _localizer["Name"], item => item.Name },
                { _localizer["Description"], item => item.Description }
            }, sheetName : _localizer["Document Types"]);

            return(await Result <string> .SuccessAsync(data : data));
        }
        public async Task <string> Handle(ExportBrandsQuery request, CancellationToken cancellationToken)
        {
            var brandFilterSpec = new BrandFilterSpecification(request.SearchString);
            var brands          = await _unitOfWork.Repository <Brand>().Entities
                                  .Specify(brandFilterSpec)
                                  .ToListAsync(cancellationToken);

            var data = await _excelService.ExportAsync(brands, mappers : new Dictionary <string, Func <Brand, object> >
            {
                { _localizer["Id"], item => item.Id },
                { _localizer["Name"], item => item.Name },
                { _localizer["Description"], item => item.Description },
                { _localizer["Tax"], item => item.Tax }
            }, sheetName : _localizer["Brands"]);

            return(data);
        }
예제 #5
0
        public async Task <Result <string> > Handle(ExportProductsQuery request, CancellationToken cancellationToken)
        {
            var productFilterSpec = new ProductFilterSpecification(request.SearchString);
            var products          = await _unitOfWork.Repository <Product>().Entities
                                    .Specify(productFilterSpec)
                                    .ToListAsync(cancellationToken);

            var data = await _excelService.ExportAsync(products, mappers : new Dictionary <string, Func <Product, object> >
            {
                { _localizer["Id"], item => item.Id },
                { _localizer["Name"], item => item.Name },
                { _localizer["Barcode"], item => item.Barcode },
                { _localizer["Description"], item => item.Description },
                { _localizer["Rate"], item => item.Rate }
            }, sheetName : _localizer["Products"]);

            return(await Result <string> .SuccessAsync(data : data));
        }
예제 #6
0
        public async Task<string> ExportToExcelAsync(string userId)
        {
            var trails = await _context.AuditTrails.Where(x => x.UserId == userId)
                .OrderByDescending(a => a.DateTime).ToListAsync();
            var result = await _excelService.ExportAsync(trails, sheetName: "Audit trails",
                mappers: new Dictionary<string, Func<Audit, object>>()
                {
                    { "Table Name", item => item.TableName },
                    { "Type", item => item.Type },
                    { "Date Time (Local)", item => DateTime.SpecifyKind(item.DateTime, DateTimeKind.Utc).ToLocalTime().ToString("dd/MM/yyyy HH:mm:ss") },
                    { "Date Time (UTC)", item => item.DateTime.ToString("dd/MM/yyyy HH:mm:ss") },
                    { "Primary Key", item => item.PrimaryKey },
                    { "Old Values", item => item.OldValues },
                    { "New Values", item => item.NewValues },
                });

            return result;
        }
예제 #7
0
        public async Task <IResult <string> > ExportToExcelAsync(string userId, string searchString = "", bool searchInOldValues = false, bool searchInNewValues = false)
        {
            var auditSpec = new AuditFilterSpecification(userId, searchString, searchInOldValues, searchInNewValues);
            var trails    = await _context.AuditTrails
                            .Specify(auditSpec)
                            .OrderByDescending(a => a.DateTime)
                            .ToListAsync();

            var data = await _excelService.ExportAsync(trails, sheetName : _localizer["Audit trails"],
                                                       mappers : new Dictionary <string, Func <Audit, object> >
            {
                { _localizer["Table Name"], item => item.TableName },
                { _localizer["Type"], item => item.Type },
                { _localizer["Date Time (Local)"], item => DateTime.SpecifyKind(item.DateTime, DateTimeKind.Utc).ToLocalTime().ToString("G", CultureInfo.CurrentCulture) },
                { _localizer["Date Time (UTC)"], item => item.DateTime.ToString("G", CultureInfo.CurrentCulture) },
                { _localizer["Primary Key"], item => item.PrimaryKey },
                { _localizer["Old Values"], item => item.OldValues },
                { _localizer["New Values"], item => item.NewValues },
            });

            return(await Result <string> .SuccessAsync(data : data));
        }