// This method gets called by the runtime. Use this method to add services to the container.
 // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddControllersWithViews();
     services.AddDbContext <SportsStoreDbContext>(options =>
                                                  options.UseSqlServer(configuration["ConnectionStrings:SportsStoreConnection"])
                                                  );
     services.AddScoped <IStoreRepository, EFStoreRepository>();
     services.AddScoped <IOrderRepository, EFOrderRepository>();
     services.AddRazorPages();
     services.AddDistributedMemoryCache();
     services.AddSession();
     services.AddScoped(serviceProvider => SessionCart.GetCart(serviceProvider));
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
 }
Esempio n. 2
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddControllersWithViews();
     services.AddDbContext <ApplicationDBContext>(options =>
                                                  options.UseSqlite(Configuration.GetConnectionString("ApplicationDBContext")));
     services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
     services.AddTransient <IOrderRepository, EFOrderRepository>();
     services.AddIdentity <AppUser, IdentityRole <Guid> >()
     .AddEntityFrameworkStores <ApplicationDBContext>()
     .AddDefaultTokenProviders();
     services.AddMemoryCache();
     services.AddSession();
 }
Esempio n. 3
0
 public int?CartExpirationMinutes()
 {
     if (CartSession != null && CartSession.Count > 0)
     {
         List <SessionCart> cSession    = CartSession.OrderByDescending(c => c.DateAdded).ToList();
         SessionCart        sessionCart = cSession.First();
         TimeSpan           ts          = DateTime.Now - sessionCart.DateAdded;
         return(FashionZone.BL.Configuration.CartExpirationValue - (int)ts.TotalMinutes);
     }
     else
     {
         return(null);
     }
 }
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddDbContext <ApplicationDBContext>(options =>
     {
         options.UseSqlServer(Configuration["Data:SportsStoreProducts:ConnectionString"]);
     });
     services.AddTransient <IProductRepository, EFProductRepository>();
     services.AddTransient <IOrderRepository, EFOrderRepository>();
     services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
     services.AddMvc();
     services.AddMemoryCache();
     services.AddSession();
 }
Esempio n. 5
0
 // This method gets called by the runtime. Use this method to add services to the container.
 // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
 public void ConfigureServices(IServiceCollection services)
 {
     //The AddScoped method specifies that the same object should be used to satisfy related requests for Cart instances.
     //How requests are related can be configured, but by default, it means that any Cart required by components handling the same HTTP request will receive the same object.
     services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
     services.AddControllersWithViews();
     //using sessions:
     services.AddMemoryCache();
     //sets up the in-memory data store
     //using sessions:
     services.AddSession();
     //registers the services used to access session data
 }
Esempio n. 6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddControllersWithViews()
            .AddNewtonsoftJson();
            services.AddMemoryCache();
            services.AddSession();
            services.AddDbContext <MbmStoreContext>(options =>
                                                    options.UseSqlServer(Configuration.GetConnectionString("MbmStoreContext")));

            services.AddScoped <IBookRepository, EFBookRepository>();
            services.AddScoped <IInvoiceRepository, EFInvoiceRepository>();
        }
Esempio n. 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddDbContext <DotNetPizzaDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DotNetPizzaConnection")));

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();


            // Add application services.
            services.AddTransient <IEmailSender, EmailSender>();
            services.AddTransient <IRepository <Pizza>, RepositoryPizza>();
            services.AddTransient <IRepository <Client>, FakeRepositoryClient>();
            services.AddTransient <IRepository <Command>, FakeRepositoryCommand>();
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            var assembly        = typeof(MyComponentViewComponent.MyComponentViewComponent).GetTypeInfo().Assembly;
            var assemblyMessage = typeof(ConixComponents.MessageViewComponent).GetTypeInfo().Assembly;

            services.AddMvc();


            //var embeddedFileProvider = new EmbeddedFileProvider(
            //    assembly,
            //    "MyComponentViewComponent"
            //);

            var embeddedFileProviderMessage = new EmbeddedFileProvider(
                assemblyMessage,
                "ConixComponents"
                );

            //Add the file provider to the Razor view engine
            services.Configure <RazorViewEngineOptions>(options =>
            {
                //options.FileProviders.Add(embeddedFileProvider);
                options.FileProviders.Add(embeddedFileProviderMessage);
            });



            services.AddMemoryCache();
            services.AddSession();
        }
Esempio n. 8
0
        // This method gets called by the runtime.
        //Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //sets up the services provided by Entity Framework Core for the database context
            services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:SportsStoreProducts:ConnectionString"]));
            // //sets up the services provided by Entity Framework Core for the database identity context
            services.AddDbContext <AppIdentityDbContext>(options => options.UseSqlServer(Configuration["Data:SportStoreIdentity:ConnectionString"]));
            //set up the Identity services using the built-in classes to represent users and roles
            services.AddIdentity <IdentityUser, IdentityRole>().AddEntityFrameworkStores <AppIdentityDbContext>().AddDefaultTokenProviders();
            //specifies that a new " EFProductRepository" will be created each time "IProductRepository" interface is needed
            // Dependency Injection
            services.AddTransient <IProductRepository, EFProductRepository>();
            //specifies that the same object should be used for Cart instances request
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddScoped <ImportItems>(sp => SessionImportItems.GetImportItems(sp));
            //use the HttpContextAccessor class when implementations of the IHttpContextAccessor interface are required
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            //Registering the Order Repository Service
            services.AddTransient <IOrderRepository, EFOrderRepository>();
            services.AddTransient <IImportOrderRepository, EFImportOrderRepository>();
            services.AddTransient <IEmployeeRepository, EFEmployeeRepository>();
            services.AddTransient <IIncomeReportRepository, EFIncomeReportRepository>();

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            //Enabling Sessions: storing Session State in memory, lost when restart or shutdown app
            services.AddMemoryCache();
            //Needed for storing Session between Redirection
            services.AddDistributedMemoryCache();
            //services.AddSession();
            services.AddSession(options =>
            {
                // Set a short timeout for easy testing.
                options.IdleTimeout     = TimeSpan.FromSeconds(10);
                options.Cookie.HttpOnly = true;
                // Make the session cookie essential
                options.Cookie.IsEssential = true;
            });
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => false;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
        }
Esempio n. 9
0
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddControllersWithViews();
     services.AddDbContext <StoreDbContext>(opts => {
         opts.UseSqlServer(
             Configuration["ConnectionStrings:CoffeeHouseConnection"]);
     });
     services.AddScoped <IStoreRepository, EFStoreRepository>();
     services.AddScoped <IOrderRepository, EFOrderRepository>();
     services.AddRazorPages();
     services.AddDistributedMemoryCache();
     services.AddSession();
     services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
 }
Esempio n. 10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddScoped <ICategoryRepository, CategoryRepository>();
            services.AddScoped <IProductRepository, ProductRepository>();
            services.AddScoped <IStoreRepository, EFStoreRepository>();

            services.AddDbContext <WSEcommerceDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("WSEcommerceDbContext")));
            services.AddRazorPages();
            services.AddDistributedMemoryCache();
            services.AddSession();
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
        }
Esempio n. 11
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient <IProductRepository, ProductRepository>();

            var connectionString = "Host=localhost;Database=SportsStore;Username=postgres;Password=123456;Port=5432;"; //Configuration["ConnectionStrings:DefaultConnection"];

            services.AddDbContext <AppDbContext>(options => options.UseNpgsql(connectionString));

            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddTransient <IOrderRepository, OrderRepository>();
            services.AddMvc();
            services.AddMemoryCache();
            services.AddSession();
        }
        public void Count_Products()
        {
            SessionCart cart = new SessionCart();

            cart.AddItem(new Product(), 3);
            cart.AddItem(new Product(), 6);
            cart.AddItem(new Product(), 17);
            cart.AddItem(new Product(), 14);
            var target = new TopBarViewComponent(cart);

            var resultModel = (target.Invoke() as ViewViewComponentResult).ViewData.Model as MainInfoViewModel;

            Assert.NotNull(resultModel);
            Assert.Equal(40, resultModel.ProductCount);
        }
Esempio n. 13
0
 // This method gets called by the runtime. Use this method to add services to the container.
 // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddControllersWithViews();
     services.AddDbContext <StoreDbContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:SportsStoreConnection"]));
     services.AddScoped <IStoreRepository, EFStoreRepository>();
     services.AddScoped <IOrderRepository, EFOrderRepository>();
     services.AddRazorPages();
     services.AddDistributedMemoryCache();
     services.AddSession();
     services.AddScoped <Cart>(p => SessionCart.GetCart(p));
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
     services.AddServerSideBlazor();
     services.AddDbContext <AppIdentityDbContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:IdentityConnection"]));
     services.AddIdentity <IdentityUser, IdentityRole>().AddEntityFrameworkStores <AppIdentityDbContext>();
 }
Esempio n. 14
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:SportStoreProducts:ConnectionString"]));
            services.AddDbContext <AppIdentityDbContext>(options => options.UseSqlServer(Configuration["Data:SportStoreIdentity:ConnectionString"]));

            services.AddIdentity <IdentityUser, IdentityRole>().AddEntityFrameworkStores <AppIdentityDbContext>().AddDefaultTokenProviders();

            services.AddTransient <IProductRepository, EFProductRepository>();
            services.AddTransient <IOrderRepository, EFOrderRepository>();
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddMemoryCache();
            services.AddSession();
            services.AddMvc();
        }
Esempio n. 15
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContextPool <ApplicationDbContext>(options => options
                                                             .UseSqlServer(
                                                                 Configuration["Data:SportsStoreProducts:ConnectionString"]));

            services.AddTransient(typeof(IProductRepository), typeof(ProductRepository));
            services.AddTransient(typeof(IProductService), typeof(ProductService));
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton(typeof(IHttpContextAccessor), typeof(HttpContextAccessor));

            services.AddMemoryCache();
            services.AddSession();
            services.AddMvc();
        }
Esempio n. 16
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // services.AddTransient<IProductRepository, FakeProductRepository>();

            services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddTransient <IProductRepository, EFProductRepository>();
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddTransient <IOrderRepository, EFOrderRepository>();

            services.AddMvc(options => options.EnableEndpointRouting = false)
            .AddNewtonsoftJson();
            services.AddMemoryCache();
            services.AddSession();
        }
Esempio n. 17
0
        private bool NeedToRemoveProcessingFee(SessionCart currentCart, RedemptionCode code)
        {
            if (!NeedToRemoveProcessingFee(currentCart))            // check base method
            {
                return(false);
            }

            if (code.RedemptionCodeType == RedemptionCodeType.StraightValue ||      // check out redemption type
                code.RedemptionCodeType == RedemptionCodeType.Transfer)
            {
                return(true);
            }

            return(false);                                           // no good reason to remove it...
        }
Esempio n. 18
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddDbContext <BookstoreDBcontext>(contextOptions =>
            {
                contextOptions.UseSqlite(Configuration["ConnectionStrings:BookstoreConnection"]);
            });

            services.AddScoped <BookstoreRepository, EFBookstoreRepository>();
            services.AddRazorPages();
            services.AddDistributedMemoryCache();
            services.AddSession();
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
        }
Esempio n. 19
0
 // This method gets called by the runtime. Use this method to add services to the container.
 // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:SportsStoreProducts:ConnectionString"]));
     services.AddTransient <IProductRepository, EFProductRepository>();
     services.AddTransient <IOrderRepository, EFOrderRepository>();
     services.AddMvc();
     services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
     services.AddMemoryCache();
     services.AddSession(options =>
     {
         options.IdleTimeout     = TimeSpan.FromSeconds(300);
         options.Cookie.HttpOnly = true;
     });
 }
Esempio n. 20
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <StoreDbContext>(options => options.UseInMemoryDatabase("Products"));
            services.AddControllersWithViews();
            services.AddDistributedMemoryCache();

            var swedbankPayConSettings = Configuration.GetSection("SwedbankPay");

            services.Configure <SwedbankPayConnectionSettings>(swedbankPayConSettings);

            var swedBankPayOptions = swedbankPayConSettings.Get <SwedbankPayConnectionSettings>();

            services.AddSingleton(s => swedBankPayOptions);

            services.Configure <PayeeInfoConfig>(options =>
            {
                options.PayeeId        = swedBankPayOptions.PayeeId;
                options.PayeeReference = DateTime.Now.Ticks.ToString();
            });

            services.Configure <UrlsOptions>(Configuration.GetSection("Urls"));
            services.AddScoped(provider => SessionCart.GetCart(provider));
            services.AddTransient <IHttpContextAccessor, HttpContextAccessor>();

            void configureClient(HttpClient a)
            {
                a.BaseAddress = swedBankPayOptions.ApiBaseUrl;
                a.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", swedBankPayOptions.Token);
            }

            services.AddSwedbankPayClient(configureClient);
            services.AddSession();

            // Code copied from:
            // https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-3.1&tabs=visual-studio#options
            services.AddHsts(options =>
            {
                options.Preload           = true;
                options.IncludeSubDomains = true;
                options.MaxAge            = TimeSpan.FromDays(60);
            });

            services.AddHttpsRedirection(options =>
            {
                options.RedirectStatusCode = StatusCodes.Status307TemporaryRedirect;
                options.HttpsPort          = 5001;
            });
        }
Esempio n. 21
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });



            services.AddDbContextPool <AppDbContext>(
                options => options.UseSqlServer(Configuration.GetConnectionString("SportStoreConnection")));

            services.AddIdentity <Customer, IdentityRole>(options =>
            {
                options.Password.RequiredLength         = 6;
                options.Password.RequiredUniqueChars    = 3;
                options.Password.RequireLowercase       = true;
                options.Password.RequireDigit           = false;
                options.Password.RequireUppercase       = true;
                options.Password.RequireNonAlphanumeric = false;
                options.User.AllowedUserNameCharacters  = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+ ";
            }).AddEntityFrameworkStores <AppDbContext>();



            services.AddMvc(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            }).AddXmlSerializerFormatters();

            services.AddTransient <IOutfitRepository, SqlOutfitRepository>();
            services.AddTransient <IOrderRepository, SQLOrderRepository>();
            services.AddTransient <IOrderedOutfitRepository, SQLOrderedOutfitRepository>();
            services.AddTransient <IFeedbackRepository, SQLFeedbackRepository>();
            services.AddTransient <IDepartmentRepository, SQLDepartmentRepository>();

            services.AddScoped <OrderEditor>(sp => SessionOrderEditor.GetOrderEditor(sp));
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddMemoryCache();
            services.AddSession();
        }
Esempio n. 22
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient <IProductRepository, ProductRepository>();
            services.AddTransient <ICategory, CategoryRepository>();
            services.AddTransient <IOrder, OrderRepository>();
            services.AddTransient <IUser, UserRepository>();
            services.AddDbContext <FlowerSaleStoreDbContext>(options => options.UseSqlServer(Configuration["Data:FlowerSaleStore:ConnectionString"]));
            services.Configure <MailSettings>(Configuration.GetSection("MailSettings"));
            services.AddTransient <IMailService, MailService>();

            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddMvc(options => options.EnableEndpointRouting = false);
            services.AddMemoryCache();
            services.AddSession();
        }
Esempio n. 23
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            services.AddDbContext <HardwareDbContext>(options => options.UseSqlServer(Configuration["Data:HardwareDB:ConnectionString"]));

            services.AddTransient <IDriveRepository, EFDriveRepository>();
            services.AddTransient <IComputerRepository, EFComputerRepository>();
            services.AddTransient <IBuildOrderRepository, EFBuildOrderRepository>();

            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddMemoryCache();
            services.AddSession();
        }
Esempio n. 24
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     // Add framework services.
     services.AddScoped(typeof(GenericRepository <>));
     services.AddScoped <CatRepository>();
     services.AddScoped <SubCatRepository>();
     services.AddScoped <BookRepository>();
     services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
     services.AddScoped <OrderRepository>();
     services.AddScoped <UserRepository>();
     services.AddScoped <RecommendRepository>();
     services.AddMvc();
     services.AddMemoryCache();
     services.AddSession();
 }
Esempio n. 25
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddDbContext <BookDBContext>(options =>
            {   //use databse from sqlserver , set connection value to onlinebooksconnection from the appsettings.json, for accessing database
                options.UseSqlite(Configuration["ConnectionStrings:OnlineBooksConnection"]);
            });
            //each session will get own repository object

            services.AddScoped <IBooksRepository, EFBooks>();
            services.AddRazorPages();
            services.AddDistributedMemoryCache();
            services.AddSession();
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
        }
Esempio n. 26
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddDbContext <ApplicationContext>();
     services.AddDbContext <AppIdentityDbContext>();
     services.AddIdentity <IdentityUser, IdentityRole>()
     .AddEntityFrameworkStores <AppIdentityDbContext>()
     .AddDefaultTokenProviders();
     //services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<AppIdentityDbContext>();
     services.AddTransient <IBookRepository, EFBooksRepository>();
     services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
     services.AddTransient <IOrderRepository, EFOrderRepository>();
     services.AddMvc();
     services.AddMemoryCache();
     services.AddSession();
 }
Esempio n. 27
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddDbContext <CharityDbContext>(options =>
            {
                options.UseSqlite(Configuration["ConnectionStrings:BookCharityConnection"]); //passing configuration, where we are going to store the connection string
            });

            services.AddScoped <ICharityRepository, EFCharityRepository>();

            services.AddRazorPages();             //adds razor pages
            services.AddDistributedMemoryCache(); //'this will get the cart info to stick
            services.AddSession();
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <StoreDbContext>(options => options.UseNpgsql(convertUrlConnectionString(Configuration["DATABASE_URL"])));
            services.AddControllersWithViews().AddRazorRuntimeCompilation();
            services.AddScoped <IStoreRepository, EFStoreRepository>();
            services.AddScoped <IOrderRepository, EFOrderRepository>();
            services.AddRazorPages();
            services.AddDistributedMemoryCache();
            services.AddSession();
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddServerSideBlazor();

            services.AddDbContext <AppIdentityDbContext>(options => options.UseNpgsql(convertUrlConnectionString(Configuration["IdentityConnection"])));
            services.AddIdentity <IdentityUser, IdentityRole>().AddEntityFrameworkStores <AppIdentityDbContext>();
        }
Esempio n. 29
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc();
     services.AddDbContext <OnlineStoreContext>(options => options.UseSqlServer(Configuration.GetConnectionString("OnlineStore")));
     services.AddMemoryCache();
     services.AddSession();
     //services.AddControllersWithViews();
     //services.AddScoped<IProductRepository, FakeProductRepository>();
     services.AddScoped <IProductRepository, EFProductRepository>();
     services.AddScoped <ICategoryRepository, EFCategoryRepository>();
     services.AddScoped(sp => SessionCart.GetCart(sp));
     services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
     services.AddControllers(options => options.EnableEndpointRouting = false);
     services.AddScoped <IOrderRepository, EFOrderRepository>();
     services.AddScoped <IPaymentService, PayIrPaymentService>();
 }
Esempio n. 30
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddDbContext <ProjectDBContext>(options =>
            {
                options.UseSqlite(Configuration["ConnectionStrings:Assignment5Connection"]);
            });
            services.AddScoped <IProjectRepository, EFProjectRepository>();

            services.AddRazorPages();

            services.AddDistributedMemoryCache();
            services.AddSession();
            services.AddScoped <Cart>(sp => SessionCart.GetCart(sp));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
        }
Esempio n. 31
0
	private void detach_SessionCarts(SessionCart entity)
	{
		this.SendPropertyChanging();
		entity.Product = null;
	}
Esempio n. 32
0
 partial void DeleteSessionCart(SessionCart instance);
Esempio n. 33
0
 partial void UpdateSessionCart(SessionCart instance);
Esempio n. 34
0
 partial void InsertSessionCart(SessionCart instance);
Esempio n. 35
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Tạo linQ context
            SanacoDataContext ctx = new SanacoDataContext();
            string sSessionId = Session["SID"].ToString();

            // Lấy product id và session id
            string sPid = Request.QueryString["pid"] ?? "";
            if (sPid != "")
            {
                int nPid = int.Parse(sPid);

                SessionCart newSC = new SessionCart();
                newSC.ProductId = nPid;
                newSC.SessionId = sSessionId;

                // Kiểm tra giỏ hàng với sản phẩm mới
                var DSHang = (from p in ctx.SessionCarts
                              where p.SessionId == sSessionId && p.ProductId == nPid
                              select p);

                if (DSHang.Count() > 0)
                {
                    // Sản phẩm đã được đặt, cộng số lượng đặt lên 1
                    SessionCart oldCart = (SessionCart)(DSHang.First());
                    oldCart.Quantity = oldCart.Quantity + 1;

                }
                else
                {
                    // Chưa đặt sản phẩm này lần nào, thiết lập số lượng đặt là 1
                    newSC.Quantity = 1;
                    ctx.SessionCarts.InsertOnSubmit(newSC);
                }

                // Cập nhật database
                ctx.SubmitChanges();

                var DSCart = (from s in ctx.SessionCarts
                              where s.SessionId == sSessionId
                              select s);
                if (DSCart != null && DSCart.Count() > 0)
                {
                    Session["Amount"] = DSCart.Count();
                }
                else
                {
                    Session["Amount"] = 0;
                }
            }
            LoadDataToCartRepeater(ctx, sSessionId);
        }
    }