예제 #1
0
        public IActionResult Download(ViewModels.FilingRequest filingRequestView)
        {
            IContextFactory contextFactory = new DapperContextFactory(_configuration.GetSection("ConnectionStrings").GetSection("DB").Value);
            string          connectFS      = _configuration.GetSection("ConnectionStrings").GetSection("FS").Value;
            string          folder         = "./Filings";

            Models.FilingRequest filingRequest = new Models.FilingRequest(filingRequestView.CIKS,
                                                                          filingRequestView.DateStart,
                                                                          filingRequestView.DateEnd,
                                                                          filingRequestView.Filings,
                                                                          filingRequestView.Items);

            using (IContext context = contextFactory.Create())
            {
                IList <FilingGetDto> dtos    = _filingRepository.GetByCIKDateFilingItem(filingRequest, context);
                IList <string>       names   = dtos.Select(dto => dto.FileName).ToList();
                IList <Stream>       streams = _exportService.DownloadFromFileSystem(names, folder, connectFS);
                using (var ms = new MemoryStream())
                {
                    using (var archive = new ZipArchive(ms, ZipArchiveMode.Create, true))
                    {
                        for (int i = 0; i < streams.Count; i++)
                        {
                            ZipArchiveEntry entry = archive.CreateEntry(names[i], CompressionLevel.Fastest);
                            using (var zipStream = entry.Open())
                            {
                                streams[i].CopyTo(zipStream);
                            }
                            streams[i].Dispose();
                        }
                    }
                    return(File(ms.ToArray(), "application/zip", "Filings.zip"));
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Registers the given <see cref="DapperContext"/> as a service in the <see cref="IServiceCollection"/>.
 /// </summary>
 /// <typeparam name="TDatabaseContext">
 /// The type of context to be registered.
 /// </typeparam>
 /// <param name="services">
 /// The <see cref="IServiceCollection"/> to add services to.
 /// </param>
 /// <param name="configuration">A set of key/value configuration properties.</param>
 /// <param name="contextBuilderAction">
 /// An optional action to configure the
 /// <see cref="DapperContextBuilder"/> for the context.
 /// </param>
 /// <returns>
 /// The <see cref="IServiceCollection"/> so that additional calls can be chained.
 /// </returns>
 public static IServiceCollection AddDapperContext <TDatabaseContext>([NotNull] this IServiceCollection services, IConfiguration configuration, [MaybeNull] Action <IServiceProvider, DapperContextBuilder>?contextBuilderAction) where TDatabaseContext : class, IDapperContext
 {
     services.AddDapperConfiguration(configuration);
     services.AddTransient(sp => CreateContextBuilder(sp, contextBuilderAction));
     services.AddSingleton(sp => DapperContextFactory.Create <TDatabaseContext>(sp));
     return(services);
 }
예제 #3
0
        public IActionResult GetCiks()
        {
            IContextFactory contextFactory = new DapperContextFactory(_configuration.GetSection("ConnectionStrings").GetSection("DB").Value);

            using (IContext context = contextFactory.Create())
            {
                IList <int> ciks = _filingRepository.GetAllCiks(context);
                return(new ObjectResult(ciks));
            }
        }
예제 #4
0
        public IActionResult Subscribe(ViewModels.User userView)
        {
            IContextFactory contextFactory = new DapperContextFactory(_configuration.GetSection("ConnectionStrings").GetSection("DB").Value);

            Models.User     user     = new Models.User(userView.Email, userView.Password, userView.Status);
            Models.HashSalt hashSalt = _authenticationService.ComputeHashSalt(user);
            Console.WriteLine(hashSalt.Hash);
            Console.WriteLine(hashSalt.Salt);
            UserInsertDto dto = new UserInsertDto(userView.Email, hashSalt.Hash, hashSalt.Salt, userView.Status);

            using (IContext context = contextFactory.Create())
            {
                _userRepository.Insert(dto, context);
                context.Commit();
                return(CreatedAtAction("subscribe", new{ userView.Email }));
            }
        }
예제 #5
0
        public IActionResult Login(ViewModels.User userView)
        {
            string          secretKey      = _configuration.GetSection("Secrets").GetSection("SecretKey").Value;
            IContextFactory contextFactory = new DapperContextFactory(_configuration.GetSection("ConnectionStrings").GetSection("DB").Value);

            Models.User user = new Models.User(userView.Email, userView.Password, userView.Status);
            using (IContext context = contextFactory.Create())
            {
                UserGetDto userGetDto = _userRepository.GetByEmail(user.Email, context)[0];
                byte[]     hash       = _authenticationService.ComputeHashFromSalt(userGetDto.Salt, Encoding.UTF8.GetBytes(user.Password));
                if (hash.SequenceEqual(userGetDto.Hash))
                {
                    return(new ObjectResult(_authenticationService.GenerateToken(user, secretKey)));
                }
                else
                {
                    return(Unauthorized());
                }
            }
        }