Esempio n. 1
0
        IAggregateInfoConstructor IGetAccountByIdGateway.GetAccountById(string accountId)
        {
            var aggregate = _context.Aggregates.ToList().DefaultIfEmpty(null).SingleOrDefault(b => b.Id == accountId);

            if (aggregate == null)
            {
                throw new InvalidOperationException();
            }

            var events = _context.Events.ToList().Where(x => x.AggregateId == accountId).OrderBy(x => x.AggregateVersion);

            return(new AggregateInfoConstructor
            {
                AggregateId = aggregate.Id,
                AggregateBaseVersion = aggregate.LastVersion,
                Events = EventsMapper.EventsMapperRepositoryToIEvents(events)
            });
        }
        public async Task <IAggregateInfoConstructor> GetAccountById(string accountId)
        {
            //if(!_context.Aggregates.Any())
            //    throw new InvalidOperationException();

            var aggregate = await _context.Aggregates.FindAsync(accountId);

            if (aggregate == null)
            {
                throw new InvalidOperationException();
            }

            var events = await _context.Events.Where(x => x.AggregateId == accountId).OrderBy(x => x.AggregateVersion).ToListAsync();

            return(new AggregateInfoConstructor
            {
                AggregateId = aggregate.Id,
                AggregateBaseVersion = aggregate.LastVersion,
                Events = EventsMapper.EventsMapperRepositoryToIEvents(events)
            });
        }
Esempio n. 3
0
 public EventsManager(IEventsRepository eventsRepository, EventsMapper eventMapper)
 {
     _eventsRepository = eventsRepository;
     _eventMapper = eventMapper;
 }
Esempio n. 4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddScoped <ApplicationDbContext>();

            services.AddIdentityMongoDbProvider <ApplicationUser, ApplicationRole>(identityOptions =>
            {
                identityOptions.Password.RequiredLength         = 6;
                identityOptions.Password.RequireLowercase       = false;
                identityOptions.Password.RequireUppercase       = false;
                identityOptions.Password.RequireNonAlphanumeric = false;
                identityOptions.Password.RequireDigit           = false;
            }, mongoIdentityOptions => { mongoIdentityOptions.ConnectionString = Configuration.GetMongoConnection(); });

            services.AddAutoMapper(config =>
            {
                ChcMapper.MapModels(config);
                CrmMapper.MapModels(config);
                EventsMapper.MapModels(config);
                DocumentsMapper.MapModels(config);
                EventsMapper.MapModels(config);
                GroupsMapper.MapModels(config);
                ExternalMapper.MapModels(config);
            });

            // Add application services.
            //services.AddTransient<IEmailSender, EmailSender>();
            ConfigureDepenedencyInjection(services);
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); // => remove default claims
            services
            .AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(cfg =>
            {
                cfg.RequireHttpsMetadata      = false;
                cfg.SaveToken                 = true;
                cfg.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidIssuer      = Configuration["JwtIssuer"],
                    ValidAudience    = Configuration["JwtIssuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtKey"])),
                    ClockSkew        = TimeSpan.Zero // remove delay of token when expire
                };
            });

            services.AddCors(options =>
            {
                options.AddPolicy("default", policy =>
                {
                    policy.WithOrigins("*")
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials();
                });
            });
            services.AddMvc(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
                options.Filters.Add(new ValidateModelAttribute());
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                };
                options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Title       = "Demo API",
                    Version     = "0.0.1",
                    Description = "This is a restful web api",
                    Contact     = new Contact
                    {
                        Name  = "Timothy Kasasa",
                        Email = "*****@*****.**"
                    }
                });

                var basePath = Environment.WebRootPath;
                var xmlPath  = Path.Combine(basePath, "Documentation", "App.xml");
                c.IncludeXmlComments(xmlPath);
                c.DescribeAllEnumsAsStrings();
            });
            services.AddSignalR();
        }
Esempio n. 5
0
 public static void CreateConfigs(IMapperConfigurationExpression cfg)
 {
     ChcMapper.MapModels(cfg);
     EventsMapper.MapModels(cfg);
     DocumentsMapper.MapModels(cfg);
 }