Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.PropertyNamingPolicy = null;
                options.JsonSerializerOptions.DictionaryKeyPolicy  = null;
            });

            // config Connect API Local Angular

            services.AddCors(options =>
            {
                options.AddPolicy(name: "AllowAllHeaders",
                                  builder =>
                {
                    builder.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyOrigin();
                });
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "My API", Version = "v1"
                });
            });

            SalesConfiguration.SetSalesConfiguration(Configuration);

            // auto mapping
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMappingProduct());
            });
            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);


            services.AddMvc(option => option.EnableEndpointRouting = false);


            services.AddScoped <IBannerService, BannerService>();
            services.AddScoped <IBlogService, BlogService>();
            services.AddScoped <ICategoryService, CategoryService>();
            services.AddScoped <IPolicyService, PolicyService>();
            services.AddScoped <IProductService, ProductService>();
            services.AddScoped <IAttributeService, AttributeService>();
            services.AddScoped <IContactService, ContactService>();
            services.AddScoped <IBrandService, BrandService>();
            services.AddScoped <IOrderService, OrderService>();
            services.AddScoped <LogService>();


            services.AddFeatureServiceProduct();
            services.AddControllers();
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.PropertyNamingPolicy = null;
                options.JsonSerializerOptions.DictionaryKeyPolicy  = null;
            });

            // config Connect API Local Angular

            services.AddCors(options =>
            {
                options.AddPolicy(name: "AllowAllHeaders",
                                  builder =>
                {
                    builder.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyOrigin();
                });
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v2", new OpenApiInfo {
                    Title = "My API", Version = "v2"
                });
            });

            SalesConfiguration.SetSalesConfiguration(Configuration);

            // auto mapping
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMappingCommon());
                mc.AddProfile(new AutoMappingAuthentication());
                mc.AddProfile(new AutoMappingProduct());
                mc.AddProfile(new AutoMappingCustomer());
                mc.AddProfile(new AutoMappingOrder());
            });
            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);



            services.AddFeatureServiceAuthentication();
            services.AddFeatureServiceCommon();
            services.AddFeatureServiceCustomer();
            services.AddFeatureServiceOrder();

            services.AddFeatureServiceProduct();
            services.AddControllers();

            // configure basic authentication
            services.AddAuthentication("BasicAuthentication")
            .AddScheme <AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);
        }
Beispiel #3
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     if (!optionsBuilder.IsConfigured)
     {
         IConfigurationRoot configuration = new ConfigurationBuilder()
                                            .Build();
         optionsBuilder
         .UseSqlServer(SalesConfiguration.GetConnectionString());
     }
 }
Beispiel #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy(DefaultCorsPolicyName, options =>
                {
                    options
                    .WithOrigins(Configuration["App:CorsOrigins"])
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });

            SalesConfiguration.SetSalesConfiguration(Configuration);

            // auto mapping
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMappingCommon());
                mc.AddProfile(new AutoMappingAuthentication());
                mc.AddProfile(new AutoMappingProduct());
                mc.AddProfile(new AutoMappingCustomer());
                mc.AddProfile(new AutoMappingOrder());
            });
            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });

            services.AddFeatureServiceAuthentication();
            services.AddFeatureServiceCommon();
            services.AddFeatureServiceCustomer();
            services.AddFeatureServiceOrder();
            services.AddFeatureServiceProduct();
            services.AddControllers();

            // configure basic authentication
            services.AddAuthentication("BasicAuthentication")
            .AddScheme <AuthenticationSchemeOptions, BasicAuthenticationHandler>("BasicAuthentication", null);
        }
        public async Task <UserDto> Login(string username, string password)
        {
            var user = await _userService.Authenticate(username, password);

            if (user == null)
            {
                return(null);
            }
            var securityKey = Encoding.ASCII.GetBytes(SalesConfiguration.GetSecurityKey());
            var expireDate  = DateTime.UtcNow.AddMinutes(SalesConfiguration.GetExpireTime());
            var credentials = new SigningCredentials(new SymmetricSecurityKey(securityKey), SecurityAlgorithms.HmacSha256Signature);
            var claims      = new[]
            {
                new Claim("user_id", user.Id.ToString()),
            };

            var tokenDescriptor = new JwtSecurityToken(
                issuer: SalesConfiguration.GetIssuer(),
                audience: SalesConfiguration.GetIssuer(),
                claims,
                expires: expireDate,
                signingCredentials: credentials
                );
            var userData = _mapper.Map <UserDto>(user);
            var token    = new JwtSecurityTokenHandler().WriteToken(tokenDescriptor);

            userData.Token = token;

            var userLogin = new UserLogin
            {
                TenantId   = user.TenantId,
                UserId     = user.Id,
                Token      = userData.Token,
                ExpireDate = expireDate,
                StoreId    = user.StoreId
            };

            _unitOfWork.UserLoginRepository.Create(userLogin);
            await _unitOfWork.Commit();

            return(userData);
        }
Beispiel #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.PropertyNamingPolicy = null;
                options.JsonSerializerOptions.DictionaryKeyPolicy  = null;
            });

            // config Connect API Local Angular

            services.AddCors(options =>
            {
                options.AddPolicy(name: "AllowAllHeaders",
                                  builder =>
                {
                    builder.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyOrigin();
                });
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "My API", Version = "v1"
                });
            });

            SalesConfiguration.SetSalesConfiguration(Configuration);

            // auto mapping
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new AutoMappingProduct());
            });
            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            //services.AddDbContext<PaymentDetailContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DevConnection")));
            //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            //services.AddMvc().AddJsonOptions(
            //options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            //);
            //services.AddMvc().AddJsonOptions(
            //options => options.SerializerSettings.DateFormatString = "yyyy-MM-dd"
            //);
            //services.AddSwaggerGen(c =>
            //{
            //    c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
            //});

            // In production, the Angular files will be served from this directory
            services.AddMvc(option => option.EnableEndpointRouting = false);

            //services.AddSpaStaticFiles(configuration =>
            //{
            //    configuration.RootPath = "ClientApp/dist";
            //});
            services.AddScoped <IBannerService, BannerService>();
            services.AddScoped <IBlogService, BlogService>();
            services.AddScoped <ICategoryService, CategoryService>();
            services.AddScoped <IPolicyService, PolicyService>();
            services.AddScoped <IProductService, ProductService>();
            services.AddScoped <IAttributeService, AttributeService>();
            services.AddScoped <IContactService, ContactService>();
            services.AddScoped <IBrandService, BrandService>();
            services.AddScoped <LogService>();


            services.AddFeatureServiceProduct();
            services.AddControllers();
        }