| using System.Web; | using System.Web; | ||||
| using AutoMapper; | using AutoMapper; | ||||
| using BlackRock.Reporting.API.Core; | |||||
| using BlackRock.Reporting.API.Core.Interfaces; | |||||
| using BlackRock.Reporting.API.Core.Models; | using BlackRock.Reporting.API.Core.Models; | ||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||
| using PuppeteerSharp; | using PuppeteerSharp; | ||||
| string path = Path.Combine(host.ContentRootPath, $"wwwroot/pdfs/{fileName}"); | string path = Path.Combine(host.ContentRootPath, $"wwwroot/pdfs/{fileName}"); | ||||
| // Mapping from DTO class to Puppeteer PdfOptions class. For margins and paper format | // Mapping from DTO class to Puppeteer PdfOptions class. For margins and paper format | ||||
| var options = mapper.Map<OptionsForPdf, PdfOptions>(pdfOptions); | var options = mapper.Map<OptionsForPdf, PdfOptions>(pdfOptions); | ||||
| await generator.Generate(result, path, options); | await generator.Generate(result, path, options); | ||||
| FileStream stream = new FileStream(path, FileMode.Open); | FileStream stream = new FileStream(path, FileMode.Open); | ||||
| return File(stream, "application/pdf", fileName); | return File(stream, "application/pdf", fileName); | ||||
| } | } | ||||
| [HttpGet("isolate/{url}")] | [HttpGet("isolate/{url}")] | ||||
| public async Task<IActionResult> GetIsolated([FromQuery] OptionsForPdf pdfOptions, string url = "http://localhost:3000/#/dashboard") | public async Task<IActionResult> GetIsolated([FromQuery] OptionsForPdf pdfOptions, string url = "http://localhost:3000/#/dashboard") |
| using PuppeteerSharp; | |||||
| namespace BlackRock.Reporting.API.Core | |||||
| { | |||||
| public interface IGenerator | |||||
| { | |||||
| Task Generate(string url, string path,PdfOptions options); | |||||
| Task Isolate(string url, string path,PdfOptions options); | |||||
| } | |||||
| } |
| using BlackRock.Reporting.API.Core.Repositories; | |||||
| namespace BlackRock.Reporting.API.Core | |||||
| { | |||||
| public interface IUnitOfWork | |||||
| { | |||||
| IUsersRepository UsersRepository{get;set;} | |||||
| Task SaveChangesAsync(); | |||||
| } | |||||
| } |
| using PuppeteerSharp; | |||||
| namespace BlackRock.Reporting.API.Core.Interfaces | |||||
| { | |||||
| public interface IGenerator | |||||
| { | |||||
| Task Generate(string url, string path, PdfOptions options); | |||||
| Task Isolate(string url, string path, PdfOptions options); | |||||
| } | |||||
| } |
| namespace BlackRock.Reporting.API.Core | |||||
| namespace BlackRock.Reporting.API.Core.Interfaces | |||||
| { | { | ||||
| public interface IPdfGenerator : IGenerator | public interface IPdfGenerator : IGenerator | ||||
| { | { | ||||
| } | } | ||||
| } | } |
| using BlackRock.Reporting.API.Core.Models; | using BlackRock.Reporting.API.Core.Models; | ||||
| namespace BlackRock.Reporting.API.Core.Repositories | |||||
| namespace BlackRock.Reporting.API.Core.Interfaces | |||||
| { | { | ||||
| public interface IRepository<TEntity> where TEntity : class, IBaseEntity | public interface IRepository<TEntity> where TEntity : class, IBaseEntity | ||||
| { | { |
| namespace BlackRock.Reporting.API.Core.Interfaces | |||||
| { | |||||
| public interface IUnitOfWork | |||||
| { | |||||
| IUsersRepository UsersRepository { get; set; } | |||||
| Task SaveChangesAsync(); | |||||
| } | |||||
| } |
| using BlackRock.Reporting.API.Core.Models; | using BlackRock.Reporting.API.Core.Models; | ||||
| namespace BlackRock.Reporting.API.Core.Repositories | |||||
| namespace BlackRock.Reporting.API.Core.Interfaces | |||||
| { | { | ||||
| public interface IUsersRepository : IRepository<User> | public interface IUsersRepository : IRepository<User> | ||||
| { | { | ||||
| void UpdateEmail(User user,string email); | |||||
| void UpdateEmail(User user, string email); | |||||
| Task<PagedCollection<User>> GetAllByFilter(UsersFilter queryObj); | Task<PagedCollection<User>> GetAllByFilter(UsersFilter queryObj); | ||||
| } | } | ||||
| } | } |
| using AutoMapper; | using AutoMapper; | ||||
| using BlackRock.Reporting.API.Core; | |||||
| using BlackRock.Reporting.API.Core.Interfaces; | |||||
| using BlackRock.Reporting.API.Core.Models; | using BlackRock.Reporting.API.Core.Models; | ||||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | using BlackRock.Reporting.API.Mediator.UserMediator.Model; | ||||
| using MediatR; | using MediatR; |
| using AutoMapper; | using AutoMapper; | ||||
| using BlackRock.Reporting.API.Core; | |||||
| using BlackRock.Reporting.API.Core.Interfaces; | |||||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | using BlackRock.Reporting.API.Mediator.UserMediator.Model; | ||||
| using MediatR; | using MediatR; | ||||
| using AutoMapper; | using AutoMapper; | ||||
| using BlackRock.Reporting.API.Core; | |||||
| using BlackRock.Reporting.API.Core.Interfaces; | |||||
| using BlackRock.Reporting.API.Core.Models; | using BlackRock.Reporting.API.Core.Models; | ||||
| using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | ||||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | using BlackRock.Reporting.API.Mediator.UserMediator.Model; | ||||
| { | { | ||||
| public class UpdateUserCommand : IRequest<Result<UserDto>> | public class UpdateUserCommand : IRequest<Result<UserDto>> | ||||
| { | { | ||||
| public UserCommand User { get;set; } | |||||
| public int Id { get;set; } | |||||
| public UserCommand User { get; set; } | |||||
| public int Id { get; set; } | |||||
| } | } | ||||
| public class UpdateUserCommandHandlers : IRequestHandler<UpdateUserCommand, Result<UserDto>> | public class UpdateUserCommandHandlers : IRequestHandler<UpdateUserCommand, Result<UserDto>> |
| using AutoMapper; | using AutoMapper; | ||||
| using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | ||||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | using BlackRock.Reporting.API.Mediator.UserMediator.Model; | ||||
| using BlackRock.Reporting.API.Core; | |||||
| using BlackRock.Reporting.API.Core.Interfaces; | |||||
| using BlackRock.Reporting.API.Core.Models; | using BlackRock.Reporting.API.Core.Models; | ||||
| using MediatR; | using MediatR; | ||||
| { | { | ||||
| public class UpdateUserEmailCommand : IRequest<Result<UserDto>> | public class UpdateUserEmailCommand : IRequest<Result<UserDto>> | ||||
| { | { | ||||
| public UserCommand User {set;get;} | |||||
| public int Id { get; set;} | |||||
| public UserCommand User { set; get; } | |||||
| public int Id { get; set; } | |||||
| } | } | ||||
| public class UpdateUserEmailCommandHandlers : IRequestHandler<UpdateUserEmailCommand, Result<UserDto>> | public class UpdateUserEmailCommandHandlers : IRequestHandler<UpdateUserEmailCommand, Result<UserDto>> | ||||
| try | try | ||||
| { | { | ||||
| var user = await unitOfWork.UsersRepository.GetByIdAsync(command.Id); | var user = await unitOfWork.UsersRepository.GetByIdAsync(command.Id); | ||||
| unitOfWork.UsersRepository.UpdateEmail(user,command.User.Email); | |||||
| unitOfWork.UsersRepository.UpdateEmail(user, command.User.Email); | |||||
| await unitOfWork.SaveChangesAsync(); | await unitOfWork.SaveChangesAsync(); | ||||
| var updatedUser = mapper.Map<User, UserDto>(user); | var updatedUser = mapper.Map<User, UserDto>(user); | ||||
| logger.LogInformation($"Email of the user with id {user.Id} has been updated successfully"); | logger.LogInformation($"Email of the user with id {user.Id} has been updated successfully"); |
| using AutoMapper; | using AutoMapper; | ||||
| using BlackRock.Reporting.API.Core; | |||||
| using BlackRock.Reporting.API.Core.Interfaces; | |||||
| using BlackRock.Reporting.API.Core.Models; | using BlackRock.Reporting.API.Core.Models; | ||||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | using BlackRock.Reporting.API.Mediator.UserMediator.Model; | ||||
| using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | using BlackRock.Reporting.API.Mediator.UserMediator.Dto; |
| using AutoMapper; | using AutoMapper; | ||||
| using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | ||||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | using BlackRock.Reporting.API.Mediator.UserMediator.Model; | ||||
| using BlackRock.Reporting.API.Core; | |||||
| using BlackRock.Reporting.API.Core.Models; | using BlackRock.Reporting.API.Core.Models; | ||||
| using MediatR; | using MediatR; | ||||
| using BlackRock.Reporting.API.Core.Repositories; | |||||
| using BlackRock.Reporting.API.Core.Interfaces; | |||||
| namespace BlackRock.Reporting.API.Mediator.UserMediator.Queries | namespace BlackRock.Reporting.API.Mediator.UserMediator.Queries | ||||
| { | { |
| using BlackRock.Reporting.API.Core; | |||||
| using BlackRock.Reporting.API.Core.Interfaces; | |||||
| using iTextSharp.text; | using iTextSharp.text; | ||||
| using iTextSharp.text.pdf; | using iTextSharp.text.pdf; | ||||
| using PuppeteerSharp; | using PuppeteerSharp; |
| using BlackRock.Reporting.API.Core.Repositories; | |||||
| using BlackRock.Reporting.API.Core.Interfaces; | |||||
| using BlackRock.Reporting.API.Core.Models; | using BlackRock.Reporting.API.Core.Models; | ||||
| using Microsoft.EntityFrameworkCore; | using Microsoft.EntityFrameworkCore; | ||||
| using System.Linq.Expressions; | using System.Linq.Expressions; | ||||
| using BlackRock.Reporting.API.Core.Repositories; | |||||
| using BlackRock.Reporting.API.Core.Interfaces; | |||||
| using BlackRock.Reporting.API.Core.Extensions; | using BlackRock.Reporting.API.Core.Extensions; | ||||
| using BlackRock.Reporting.API.Core.Models; | using BlackRock.Reporting.API.Core.Models; | ||||
| using Microsoft.EntityFrameworkCore; | using Microsoft.EntityFrameworkCore; |
| using BlackRock.Reporting.API.Core; | using BlackRock.Reporting.API.Core; | ||||
| using BlackRock.Reporting.API.Core.Repositories; | |||||
| using BlackRock.Reporting.API.Core.Interfaces; | |||||
| namespace BlackRock.Reporting.API.Persistence | namespace BlackRock.Reporting.API.Persistence | ||||
| { | { |
| using BlackRock.Reporting.API.Authentication; | using BlackRock.Reporting.API.Authentication; | ||||
| using BlackRock.Reporting.API.Core; | |||||
| using BlackRock.Reporting.API.Core.Models; | using BlackRock.Reporting.API.Core.Models; | ||||
| using BlackRock.Reporting.API.Core.Repositories; | |||||
| using BlackRock.Reporting.API.Core.Interfaces; | |||||
| using BlackRock.Reporting.API.Persistence; | using BlackRock.Reporting.API.Persistence; | ||||
| using BlackRock.Reporting.API.Persistence.Repositories; | using BlackRock.Reporting.API.Persistence.Repositories; | ||||
| using MediatR; | using MediatR; | ||||
| builder.Services.AddControllers(); | builder.Services.AddControllers(); | ||||
| builder.Services.AddAutoMapper(typeof(Program)); | builder.Services.AddAutoMapper(typeof(Program)); | ||||
| builder.Services.AddIdentity<ApplicationUser, IdentityRole>() | builder.Services.AddIdentity<ApplicationUser, IdentityRole>() | ||||
| .AddTokenProvider("MyApp",typeof(DataProtectorTokenProvider<ApplicationUser>)) | |||||
| .AddTokenProvider("MyApp", typeof(DataProtectorTokenProvider<ApplicationUser>)) | |||||
| .AddEntityFrameworkStores<BRDbContext>() | .AddEntityFrameworkStores<BRDbContext>() | ||||
| .AddDefaultTokenProviders(); | .AddDefaultTokenProviders(); | ||||
| builder.Services.AddAuthentication(options => | builder.Services.AddAuthentication(options => | ||||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||||
| builder.Services.AddEndpointsApiExplorer(); | builder.Services.AddEndpointsApiExplorer(); | ||||
| builder.Services.AddSwaggerGen( | builder.Services.AddSwaggerGen( | ||||
| c => { | |||||
| c => | |||||
| { | |||||
| c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "BlackRock.Service.API", Version = "v1" }); | c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "BlackRock.Service.API", Version = "v1" }); | ||||
| c.AddSecurityDefinition("Bearer", new Microsoft.OpenApi.Models.OpenApiSecurityScheme | c.AddSecurityDefinition("Bearer", new Microsoft.OpenApi.Models.OpenApiSecurityScheme | ||||
| { | { | ||||
| var app = builder.Build(); | var app = builder.Build(); | ||||
| // Configure the HTTP request pipeline. | // Configure the HTTP request pipeline. | ||||
| app.ConfigureExceptionHandler(builder.Logging); | |||||
| // app.ConfigureExceptionHandler(builder.Logging); | |||||
| app.UseCors(options => | app.UseCors(options => | ||||
| options.AllowAnyHeader() | options.AllowAnyHeader() | ||||
| .AllowAnyMethod() | .AllowAnyMethod() |