// 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") options.UseInMemoryDatabase("Default") ); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); // Add application services. services.AddTransient <IEmailSender>((iServiceProvider) => new EmailSender(Configuration.GetValue <string>("SendGrid.ApiKey"))); services.AddTransient <IBraintreeGateway>((IServiceProvider) => new BraintreeGateway( Configuration.GetValue <string>("Braintree.Environment"), Configuration.GetValue <string>("Braintree.MerchantID"), Configuration.GetValue <string>("Braintree.PublicKey"), Configuration.GetValue <string>("Braintree.PrivateKey") )); services.AddTransient <SmartyStreets.USStreetApi.Client>((iSP) => { SmartyStreets.ClientBuilder clientBuilder = new SmartyStreets.ClientBuilder( Configuration.GetValue <string>("SmartyStreets.AuthId"), Configuration.GetValue <string>("SmartyStreets.AuthToken") ); return(clientBuilder.BuildUsStreetApiClient()); }); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { string DonutStoreConnectionString = Configuration.GetConnectionString("DonutStore"); services.AddDbContext <DonutStoreDbContext>(opt => opt.UseSqlServer(DonutStoreConnectionString)); services.AddIdentity <DonutStoreUser, IdentityRole>() .AddEntityFrameworkStores <DonutStoreDbContext>() .AddDefaultTokenProviders(); services.AddMvc(); services.AddTransient((x) => { return(new EmailService(Configuration["SendGridKey"])); }); services.AddTransient((x) => { return(new Braintree.BraintreeGateway( Configuration["BraintreeEnvironment"], Configuration["BraintreeMerchantId"], Configuration["BraintreePublicKey"], Configuration["BraintreePrivateKey"])); }); //smartystreets services.AddTransient((x) => { SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(Configuration["SmartyStreetsAuthId"], Configuration["SmartyStreetsAuthToken"]); return(builder.BuildUsStreetApiClient()); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Configuration.GetConnectionString("AdventureWorks2016"); //Configuration.GetConnectionString("FinalProjDB"); string organicFarmStoreConnectionString = Configuration.GetConnectionString("OrganicFarmStore"); //Singleton:Creates one service when the app starts then it will be the same for every request //Transient:Constructed and destructed every single request //services.AddTransient<SampleService>(); //These are not part of .NET Core... they are seperate libraries that must be installed via a program called NuGet. //Right click on your Project -> Manage NuGet Packages and brwose and install each of the following //using Microsoft.AspNetCore.Identity.EntityFrameworkCore; //using Microsoft.EntityFrameworkCore; //using Microsoft.AspNetCore.Identity; // services.AddDbContext<IdentityDbContext>(opt => opt.UseInMemoryDatabase("Identities")); services.AddDbContext <OrganicStoreDbContext>(opt => opt.UseSqlServer(organicFarmStoreConnectionString)); services.AddIdentity <OrganicStoreUser, IdentityRole>(options => { options.Password.RequireDigit = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireLowercase = false; options.Password.RequireUppercase = false; }) .AddEntityFrameworkStores <OrganicStoreDbContext>() // Will store Identity user info .AddDefaultTokenProviders(); services.AddMvc(); services.AddTransient((x) => { return(new EmailService(Configuration["SendGridKey"])); }); services.AddTransient((x) => { return(new Braintree.BraintreeGateway( Configuration["BraintreeEnvironment"], Configuration["BraintreeMerchantId"], Configuration["BraintreePublicKey"], Configuration["BraintreePrivateKey"])); }); services.AddTransient((x) => { SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(Configuration["SmartyStreetsAuthId"], Configuration["SmartyStreestsAuthToken"]); return(builder.BuildUsStreetApiClient()); //SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(Configuration["SmartyStreetsAuthId"], // Configuration["SmartyStreetsAuthToken"]); //return builder.BuildUsStreetApiClient(); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //These are not part of .NET Core... they are seperate libraries that must be installed via a program called NuGet. //Right click on your Project -> Manage NuGet Packages Configuration.GetConnectionString("Boats"); string boatChartersConnectionString = Configuration.GetConnectionString("Boats"); //using Microsoft.AspNetCore.Identity.EntityFrameworkCore; //using Microsoft.EntityFrameworkCore; //using Microsoft.AspNetCore.Identity; services.AddDbContext <BoatChartersDbContext>(opt => opt.UseSqlServer(boatChartersConnectionString)); services.AddIdentity <BoatChartesUser, IdentityRole>(options => { options.Password.RequireDigit = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireLowercase = false; options.Password.RequireUppercase = false; }) .AddEntityFrameworkStores <BoatChartersDbContext>() .AddDefaultTokenProviders(); services .AddMvc() .AddJsonOptions( o => { o.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); o.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; }); services.AddTransient((x) => { return(new EmailService(Configuration["SendGridKey"])); }); services.AddTransient((x) => { return(new Braintree.BraintreeGateway( Configuration["BraintreeEnvironment"], Configuration["BraintreeMerchantId"], Configuration["BraintreePublicKey"], Configuration["BraintreePrivateKey"])); }); services.AddTransient((x) => { SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(Configuration["SmartyStreetsAuthId"], Configuration["SmartyStreetsAuthToken"]); return(builder.BuildUsStreetApiClient()); }); }
// 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.AddDbContext <ApplicationDbContext>(options => options.UseMySql( Configuration.GetConnectionString("DefaultConnection"))); //services.AddDefaultIdentity<StoreUser>() // .AddEntityFrameworkStores<ApplicationDbContext>(); services.AddIdentity <StoreUser, IdentityRole>() .AddDefaultUI() .AddRoles <IdentityRole>() .AddRoleManager <RoleManager <IdentityRole> >() .AddDefaultTokenProviders() .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddTransient((s) => { return(new SendGrid.SendGridClient(Configuration.GetValue <string>("SendGridApiKey"))); }); services.AddTransient <Microsoft.AspNetCore.Identity.UI.Services.IEmailSender>((s) => { return(new store.Services.EmailSender(s.GetService <SendGrid.SendGridClient>())); }); services.AddTransient <Braintree.IBraintreeGateway>((s) => { return(new Braintree.BraintreeGateway( Configuration.GetValue <string>("Braintree:Environment"), Configuration.GetValue <string>("Braintree:MerchantId"), Configuration.GetValue <string>("Braintree:PublicKey"), Configuration.GetValue <string>("Braintree:PrivateKey") )); }); services.AddTransient <SmartyStreets.IClient <SmartyStreets.USStreetApi.Lookup> >((s) => { SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder( Configuration.GetValue <string>("SmartyStreets:AuthId"), Configuration.GetValue <string>("SmartyStreets:AuthToken") ); return(builder.BuildUsStreetApiClient()); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { string ThisSiteConnectionString = Configuration.GetConnectionString("ThisSite"); services.AddDbContext <ThisSiteDbContext>(opt => opt.UseSqlServer(ThisSiteConnectionString)); services.AddIdentity <ThisSiteUser, IdentityRole>(options => { options.Password.RequireDigit = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireLowercase = false; options.Password.RequireUppercase = false; options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; options.Lockout.AllowedForNewUsers = true; //for testing only, else true options.User.RequireUniqueEmail = false; }) .AddEntityFrameworkStores <ThisSiteDbContext>() .AddDefaultTokenProviders(); services .AddMvc() .AddJsonOptions( options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; }); services.AddTransient((x) => { return(new EmailService(Configuration["SendGridKey"])); }); services.AddTransient((x) => { return(new Braintree.BraintreeGateway( Configuration["BraintreeEnvironment"], Configuration["BraintreeMerchantId"], Configuration["BraintreePublicKey"], Configuration["BraintreePrivateKey"])); }); services.AddTransient((x) => { SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder( Configuration["SmartyStreetsAuthID"], Configuration["SmartStreetsAuthToken"]); return(builder.BuildUsStreetApiClient()); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Use this for the mysql database: services.AddDbContext <ApplicationDbContext>(options => options.UseMySql(Configuration.GetConnectionString("DefaultConnection"))); ////Use this for in memory database like for publishing to azure for demos //services.AddDbContext<ApplicationDbContext>(options => //options.UseInMemoryDatabase("Default")); services.AddIdentity <ApplicationUser, ApplicationRole>( identity => { // whatever identity options you want identity.User.RequireUniqueEmail = true; identity.Password.RequiredLength = 8; }).AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); // Add application services. services.AddTransient <IEmailSender>((iSP) => new EmailSender(Configuration.GetValue <string>("SendGrid.ApiKey"))); services.AddTransient <Braintree.IBraintreeGateway>((iServiceProvider) => new Braintree.BraintreeGateway( Configuration.GetValue <string>("Environment"), Configuration.GetValue <string>("MerchantId"), Configuration.GetValue <string>("PublicKey"), Configuration.GetValue <string>("PrivateKey") )); services.AddTransient <SmartyStreets.USStreetApi.Client>((iSP) => { SmartyStreets.ClientBuilder clientBuilder = new SmartyStreets.ClientBuilder( Configuration.GetValue <string>("SmartyStreets.AuthId"), Configuration.GetValue <string>("SmartyStreets.AuthToken") ); return(clientBuilder.BuildUsStreetApiClient()); }); services.AddSingleton <SettingsService>(); //services.AddMvc(options => //{ // options.Filters.Add(new Microsoft.AspNetCore.Mvc.RequireHttpsAttribute()); //}); services.AddMvc(); }
public ActionResult ValidateAddress(string street, string city, string state, string zip) { string authId = ConfigurationManager.AppSettings["SmartyStreets.AuthID"]; string authToken = ConfigurationManager.AppSettings["SmartyStreets.AuthToken"]; SmartyStreets.ClientBuilder clientBuilder = new SmartyStreets.ClientBuilder(authId, authToken); var client = clientBuilder.BuildUsStreetApiClient(); SmartyStreets.USStreetApi.Lookup lookup = new SmartyStreets.USStreetApi.Lookup(); lookup.City = city; lookup.ZipCode = zip; lookup.Street = street; lookup.State = state; client.Send(lookup); return(Json(lookup.Result.Select(x => new { street = x.DeliveryLine1, city = x.Components.CityName, state = x.Components.State, zip = x.Components.ZipCode + "-" + x.Components.Plus4Code }))); }
public ActionResult ValidateAddress(string street1, string street2, string city, string state, string postalCode) { if (!string.IsNullOrEmpty(street1) && !string.IsNullOrEmpty(city) && !string.IsNullOrEmpty(state) //&& (Request.UrlReferrer.Host == Request.Url.Host) //Uncommenting this will make sure your validate function only works on your site ) { SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder( ConfigurationManager.AppSettings["SmartyStreets.AuthId"], ConfigurationManager.AppSettings["SmartyStreets.AuthToken"]); var client = builder.BuildUsStreetApiClient(); SmartyStreets.USStreetApi.Lookup lookup = new SmartyStreets.USStreetApi.Lookup(); lookup.Street = street1; lookup.Street2 = street2; lookup.City = city; lookup.State = state; lookup.ZipCode = postalCode; client.Send(lookup); return(Json(lookup.Result.Select(x => new { Street1 = x.DeliveryLine1, Street2 = x.DeliveryLine2, City = x.Components.CityName, State = x.Components.State, PostalCode = x.Components.ZipCode }), JsonRequestBehavior.AllowGet)); } return(Json(new object[0], JsonRequestBehavior.AllowGet)); }
// 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"))); //Use this when publishing to Azure options.UseInMemoryDatabase("Default")); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); // Add application services. services.AddTransient <IEmailSender>((iServiceProvider) => new EmailSender(Configuration.GetValue <string>("SendGrid.ApiKey"))); //environment, merchantid, publickey, privatekey has to be in the same order!!! services.AddTransient <Braintree.IBraintreeGateway>((iServiceProvider) => new Braintree.BraintreeGateway( Configuration.GetValue <string>("Braintree.Environment"), Configuration.GetValue <string>("Braintree.MerchantId"), Configuration.GetValue <string>("Braintree.PublicKey"), Configuration.GetValue <string>("Braintree.PrivateKey") )); services.AddTransient <System.Data.SqlClient.SqlConnection>((x) => new System.Data.SqlClient.SqlConnection(Configuration.GetConnectionString("DefaultConnection"))); services.AddTransient <SmartyStreets.USStreetApi.Client>((iSP) => { SmartyStreets.ClientBuilder clientBuilder = new SmartyStreets.ClientBuilder( Configuration.GetValue <string>("SmartyStreets.AuthId"), Configuration.GetValue <string>("SmartyStreets.Token") ); return(clientBuilder.BuildUsStreetApiClient()); }); services.AddMvc(); }
public ActionResult ValidateAddress(Address a) { if (ModelState.IsValid) { string smartyStreetsAuthID = ConfigurationManager.AppSettings["SmartyStreets.AuthID"]; string smartyStreetsAuthToken = ConfigurationManager.AppSettings["SmartyStreets.AuthToken"]; SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(smartyStreetsAuthID, smartyStreetsAuthToken); var smartyClient = builder.BuildUsStreetApiClient(); SmartyStreets.USStreetApi.Lookup lookup = new SmartyStreets.USStreetApi.Lookup(); lookup.City = a.Locality ?? ""; lookup.State = a.Region ?? ""; lookup.Street = a.Street1 ?? ""; lookup.Street2 = a.Street2 ?? ""; lookup.ZipCode = a.PostalCode ?? ""; smartyClient.Send(lookup); return(Json(lookup.Result.Select(x => new { City = x.Components.CityName, Street = x.DeliveryLine1, Street2 = x.DeliveryLine2, State = x.Components.State, ZipCode = x.Components.ZipCode + "-" + x.Components.Plus4Code }), JsonRequestBehavior.AllowGet)); } else { Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; return(Json(new { Message = ModelState.FirstOrDefault(x => x.Value.Errors.Any()).Value.Errors .FirstOrDefault() }, JsonRequestBehavior.AllowGet)); } }
public SmartyStreetsService(string authId, string authToken) { SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(authId, authToken); _client = builder.BuildUsStreetApiClient(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { string tcpConnectionString = Configuration.GetConnectionString("TCP"); services.AddDbContext <Models.TCPDbContext>(opt => opt.UseSqlServer(tcpConnectionString)); services.AddIdentity <TCPUser, IdentityRole>(options => { options.Password.RequireDigit = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireLowercase = false; options.Password.RequireUppercase = false; }) .AddEntityFrameworkStores <Models.TCPDbContext>() .AddDefaultTokenProviders(); services.ConfigureApplicationCookie(options => { // Cookie settings options.Cookie.HttpOnly = true; options.ExpireTimeSpan = TimeSpan.FromMinutes(30); // If the LoginPath isn't set, ASP.NET Core defaults // the path to /Account/Login. options.LoginPath = "/Account/Login"; // If the AccessDeniedPath isn't set, ASP.NET Core defaults // the path to /Account/AccessDenied. options.AccessDeniedPath = "/Account/AccessDenied"; options.SlidingExpiration = true; }); /* * services.AddTransient<SendGrid.SendGridClient>((x) => * { * return new SendGrid.SendGridClient("api_key_here"); * }); * * services.AddTransient<SendGrid.SendGridClient>((x) => * { * return new SendGrid.SendGridClient(Configuration["sendgrid"]); * }); */ services .AddMvc() .AddJsonOptions( o => { o.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); o.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; }); services.AddTransient((x) => { return(new EmailService(Configuration["SendGridKey"])); }); services.AddTransient((x) => { return(new Braintree.BraintreeGateway( Configuration["BraintreeEnvironment"], Configuration["BraintreeMerchantId"], Configuration["BraintreePublicKey"], Configuration["BraintreePrivateKey"])); }); services.AddTransient((x) => { SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(Configuration["SmartyStreetsAuthId"], Configuration["SmartyStreetsAuthToken"]); return(builder.BuildUsStreetApiClient()); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { Configuration.GetConnectionString("burgerStore"); string burgerStoreConnectionString = Configuration.GetConnectionString("burgerStore"); services.AddDbContext <BurgerStoreDbContext>(opt => opt.UseSqlServer(burgerStoreConnectionString)); services.AddIdentity <BurgerStoreUser, IdentityRole>() .AddEntityFrameworkStores <BurgerStoreDbContext>() .AddDefaultTokenProviders(); services.Configure <IdentityOptions>(options => { // Password settings options.Password.RequireDigit = true; options.Password.RequiredLength = 8; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = true; options.Password.RequireLowercase = false; options.Password.RequiredUniqueChars = 6; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 5; options.Lockout.AllowedForNewUsers = true; // User settings options.User.RequireUniqueEmail = true; }); services.ConfigureApplicationCookie(options => { // Cookie settings options.Cookie.HttpOnly = true; options.ExpireTimeSpan = TimeSpan.FromMinutes(30); // If the LoginPath isn't set, ASP.NET Core defaults // the path to /Account/Login. options.LoginPath = "/Account/Login"; // If the AccessDeniedPath isn't set, ASP.NET Core defaults // the path to /Account/AccessDenied. options.AccessDeniedPath = "/Account/AccessDenied"; options.SlidingExpiration = true; }); services.AddMvc(); services.AddTransient((x) => { return(new EmailService(Configuration["SendGridKey"])); }); services.AddTransient((x) => { return(new Braintree.BraintreeGateway( Configuration["BraintreeEnvironment"], Configuration["BraintreeMerchantId"], Configuration["BraintreePublicKey"], Configuration["BraintreePrivateKey"])); }); //remember to add keys to secrets file services.AddTransient((x) => { SmartyStreets.ClientBuilder builder = new SmartyStreets.ClientBuilder(Configuration["SmartyStreetsAuthId"], Configuration["SmartyStreetsAuthToken"]); return(builder.BuildUsStreetApiClient()); }); }