コード例 #1
0
 public OrderBusinessContext()
 {
     orderDataBaseContext   = new OrderDatabaseContext();
     addressDatabaseContext = new AddressDatabaseContext();
     cartDataBaseContext    = new CartDatabaseContext();
     productDatabaseContext = new ProductDatabaseContext();
 }
コード例 #2
0
 public ValuesController(ITestService testService, ProductDatabaseContext productDatabaseContext, IHostingEnvironment hostingEnvironment, StatusDatabaseContext statusDatabaseContext, IStatusService iStatusService)
 {
     _iStatusService         = iStatusService;
     _testService            = testService;
     _productDatabaseContext = productDatabaseContext;
     _hostingEnvironment     = hostingEnvironment;
 }
コード例 #3
0
 public ProductService(ProductDatabaseContext productDatabaseContext, IOptions <ProductSettings> productSettings, IHttpContextAccessor iHttpContextAccessor)
 {
     _productSettings              = productSettings;
     _productDatabaseContext       = productDatabaseContext;
     _productRepository            = new ProductRepository(productDatabaseContext, productSettings, iHttpContextAccessor);
     _productTranslationRepository = new ProductTranslationRepository(productDatabaseContext, productSettings, iHttpContextAccessor);
 }
コード例 #4
0
ファイル: Startup.cs プロジェクト: ecoshub/services
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ProductDatabaseContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints => {
                endpoints.MapControllers();
            });

            context.Database.Migrate();
        }
コード例 #5
0
        public static void Seed(ProductDatabaseContext _context)
        {
            product temp = new product("Asus N550JK", 20, 7799.90, "Asus N550JK laptop");

            _context.product.Add(temp);
            _context.SaveChanges();
            temp = new product("IPhone S12", 56, 10999.90, "IPhone S12 Smartphone");
            _context.product.Add(temp);
            _context.SaveChanges();
            temp = new product("Logitech K360", 48, 299.90, "Logitech wireless keyboard");
            _context.product.Add(temp);
            _context.SaveChanges();
            temp = new product("Logitech A67", 20, 7799.90, "Logitech 3+1 Sound System");
            _context.product.Add(temp);
            _context.SaveChanges();
            temp = new product("Samsung A50", 85, 7799.90, "Samsung A50 Smartphone");
            _context.product.Add(temp);
            _context.SaveChanges();
        }
コード例 #6
0
        public BaseTest()
        {
            var serviceProvider = new ServiceCollection()
                                  //.AddEntityFrameworkSqlServer()
                                  //.AddEntityFrameworkNpgsql()
                                  //.AddE
                                  .AddTransient <ITestService, TestService>()
                                  .BuildServiceProvider();

            DbContextOptionsBuilder <ProductDatabaseContext> builderProduct = new DbContextOptionsBuilder <ProductDatabaseContext>();
            var connectionString = "server=localhost;userid=root;password=123456;database=Product;";

            builderProduct.UseMySql(connectionString);
            //.UseInternalServiceProvider(serviceProvider); //burası postgress ile sıkıntı çıkartmıyor, fakat mysql'de çalışmıyor test esnasında hata veriyor.

            _productDatabaseContext = new ProductDatabaseContext(builderProduct.Options);
            //_context.Database.Migrate();

            //Configuration
            iHttpContextAccessor = new HttpContextAccessor {
                HttpContext = new DefaultHttpContext()
            };
            _productSettings = Options.Create(new ProductSettings()
            {
                FileUploadFolderPath = @"C:\Users\haltunbas\Documents\GitHub\ProductV2\Product.Api\Product.Api\wwwroot\upload\"
            });

            _testService            = new TestService(_productDatabaseContext, _productSettings, iHttpContextAccessor);
            _productService         = new ProductService(_productDatabaseContext, _productSettings, iHttpContextAccessor);
            _productCategoryService = new ProductCategoryService(_productDatabaseContext, _productSettings, iHttpContextAccessor);
            productSchemaService    = new ProductSchemaService(_productDatabaseContext, _productSettings, iHttpContextAccessor);

            _server = new TestServer(new WebHostBuilder()
                                     .UseStartup <Startup>());
            _client = _server.CreateClient();
            _client.DefaultRequestHeaders.Accept.Clear();
            _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            //LoginControllerTest controller = new LoginControllerTest();
            //Guid token = controller.GetToken().Result;
            //_client.DefaultRequestHeaders.Add("Token", token.ToString());
            _client.DefaultRequestHeaders.Add("Token", "00000000-0000-0000-0000-000000000000");
        }
コード例 #7
0
 public TestService(ProductDatabaseContext productDatabaseContext, IOptions <ProductSettings> productSettings, IHttpContextAccessor iHttpContextAccessor)
 {
     _testRepository = new TestRepository(productDatabaseContext, productSettings, iHttpContextAccessor);
 }
コード例 #8
0
 public ProductRepository(ProductDatabaseContext productDatabaseContext, IMapper mapper)
 {
     _productDatabaseContext = productDatabaseContext;
     _mapper = mapper;
 }
コード例 #9
0
 public TestController(IOptions <ProductSettings> productSettings, ITestService testService, ProductDatabaseContext productDatabaseContext)
 {
     _productSettings        = productSettings.Value;
     _testService            = testService;
     _productDatabaseContext = productDatabaseContext;
 }
コード例 #10
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            //if (!context.ModelState.IsValid)
            //{
            //    context.Result = new BadRequestObjectResult(context.ModelState);
            //}
            string requestControllerAndMethodName = context.ActionDescriptor.DisplayName.Replace("Product.Api.Controllers.", "").Replace(" (Product.Api)", "");;

            context.HttpContext.Request.Headers.TryGetValue("Token", out _Token);
            bool isAccess = false;

            if (_Token.Count > 0)
            {
                UserView visitorUser = null;
                ProductDatabaseContext _productDatabaseContext = (ProductDatabaseContext)context.HttpContext.RequestServices.GetService(typeof(ProductDatabaseContext));
                //IJwtService _jwtService = (JwtService)context.HttpContext.RequestServices.GetService(typeof(IJwtService));
                UserView systemUserView = AsyncHelpers.RunSync <UserView>(() => identityClient.GetSystemUserCacheAsync(new UserLoginView {
                    Email = Config.IdentitySystemUserName, Password = Config.IdentitySystemPassword
                }));
                List <RoleView>   systemRoleList = AsyncHelpers.RunSync <List <RoleView> >(() => identityClient.GetRoleListCacheAsync(systemUserView.Jwt.Token));
                List <Permission> permissionList = AsyncHelpers.RunSync <List <Permission> >(() => identityClient.GetPermissionListCacheAsync(systemUserView.Jwt.Token));

                Guid token;
                Jwt  jwt = new Jwt();
                try
                {
                    //jwt guid format kontrol ediliyor.
                    token = Guid.Parse(_Token.FirstOrDefault());
                    jwt   = identityClient.CheckTokenAsync(token).Result;
                    if (jwt == null)
                    {
                        CommonApiResponse <dynamic> response = CommonApiResponse <dynamic> .Create(context.HttpContext.Response, System.Net.HttpStatusCode.OK, false, null, "Token geçersiz.");

                        BadRequestObjectResult badReq = new BadRequestObjectResult(response);
                        context.Result = badReq;
                        return;
                    }

                    visitorUser = AsyncHelpers.RunSync <UserView>(() => identityClient.GetUserByTokenAsync(jwt.Token));//userGetirildi.
                }
                catch (Exception ex)
                {
                    CommonApiResponse <dynamic> response = CommonApiResponse <dynamic> .Create(context.HttpContext.Response, System.Net.HttpStatusCode.InternalServerError, false, null, ex.Message);

                    BadRequestObjectResult badReq = new BadRequestObjectResult(response);
                    context.Result = badReq;
                    return;
                }

                try
                {
                    //Burada jwt ile gelen kullanıcının istekte bulunduğu controller içindeki fonksiyona erişimi olup olmadığı sorgulanıyor
                    isAccess = Client.IsAccessRole(systemRoleList, permissionList, visitorUser.Roles, requestControllerAndMethodName);
                    if (!isAccess)
                    {
                        CommonApiResponse <dynamic> response = CommonApiResponse <dynamic> .Create(context.HttpContext.Response, System.Net.HttpStatusCode.OK, false, null, "Yetkiniz yok.");

                        BadRequestObjectResult badReq = new BadRequestObjectResult(response);
                        context.Result = badReq;
                        return;
                    }

                    var controller = context.Controller as Controller;
                    controller.ViewBag.Jwt = jwt;
                }
                catch (Exception ex)
                {
                    CommonApiResponse <dynamic> response = CommonApiResponse <dynamic> .Create(context.HttpContext.Response, System.Net.HttpStatusCode.InternalServerError, false, null, ex.Message);

                    BadRequestObjectResult badReq = new BadRequestObjectResult(response);
                    context.Result = badReq;
                    return;
                }
            }
            else
            {
                CommonApiResponse <dynamic> response = CommonApiResponse <dynamic> .Create(context.HttpContext.Response, System.Net.HttpStatusCode.OK, false, null, "Header Token bulunamadı.");

                ObjectResult badReq = new ObjectResult(response);
                context.Result = badReq;
                return;
            }
        }
コード例 #11
0
 public ProductRepository(ProductDatabaseContext context)
 {
     _context = context;
 }
コード例 #12
0
 public ProductsController(IOptions <ProductSettings> productSettings, ProductDatabaseContext productDatabaseContext, IProductService productService, IHttpContextAccessor iHttpContextAccessor)
 {
     _productSettings        = productSettings;
     _productDatabaseContext = productDatabaseContext;
     _productService         = new ProductService(_productDatabaseContext, _productSettings, iHttpContextAccessor);
 }
コード例 #13
0
 public ProductBusinessContext()
 {
     productDatabaseContext = new ProductDatabaseContext();
 }
コード例 #14
0
 public ProductController(IProductRepository repo, ProductDatabaseContext context, IMapper mapper)
 {
     _repo    = repo;
     _context = context;
     _mapper  = mapper;
 }
コード例 #15
0
 public BrandService(ProductDatabaseContext productDatabaseContext, IOptions <ProductSettings> productSettings, IHttpContextAccessor iHttpContextAccessor)
 {
     _productDatabaseContext = productDatabaseContext;
     _brandRepository        = new BrandRepository(productDatabaseContext, productSettings, iHttpContextAccessor);
 }
コード例 #16
0
 public ProductSchemaService(ProductDatabaseContext productDatabaseContext, IOptions <ProductSettings> productSettings, IHttpContextAccessor iHttpContextAccessor)
 {
     _productDatabaseContext  = productDatabaseContext;
     _productSchemaRepository = new ProductSchemaRepository(_productDatabaseContext, productSettings, iHttpContextAccessor);
 }