public HttpResponseMessage Post([FromBody] JObject jsonUserId) { // Get userid if (jsonUserId != null) { string userId = jsonUserId["userid"].ToString(); using (var context = ContextManager.CreateContext()) { string loyalty = this.LoyaltyNumber(userId); var user = context.Users.Where(row => string.Compare(row.UserId, userId, true) == 0).FirstOrDefault(); if (user != null) { user.LoyaltyNumber = loyalty; } else { user = new LoyaltyModel { UserId = userId, LoyaltyNumber = loyalty }; context.Users.Add(user); } context.SaveChangesAsync(); return(Request.CreateResponse(HttpStatusCode.OK, user)); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public HttpResponseMessage Get() { string userId = string.Empty; // Try to get userid from header var header = Request.Headers.Where(h => string.Compare(h.Key, "UserId", true) == 0).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(header.Key)) { userId = header.Value.FirstOrDefault(); } if (!string.IsNullOrWhiteSpace(userId)) { using (var context = ContextManager.CreateContext()) { var user = context.Users.Where(row => string.Compare(row.UserId, userId, true) == 0).FirstOrDefault(); if (user != null) { user = new LoyaltyModel { UserId = userId, LoyaltyNumber = user.LoyaltyNumber }; return(Request.CreateResponse(HttpStatusCode.OK, user)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
// 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; }); ContextManager.CreateContext(services, Configuration); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => //CookieAuthenticationOptions { options.LoginPath = new Microsoft.AspNetCore.Http.PathString("/Account/Login"); options.AccessDeniedPath = new Microsoft.AspNetCore.Http.PathString("/Account/Login"); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
internal static void SetInstanceIdInMessage(Message message, string instanceId) { ContextMessageProperty contextProperties = null; if (!ContextMessageProperty.TryGet(message, out contextProperties)) { contextProperties = new ContextMessageProperty(ContextManager.CreateContext(ContextManager.InstanceIdKey, instanceId)); message.Properties.Add(ContextMessageProperty.Name, contextProperties); } else { if (!contextProperties.Context.ContainsKey(ContextManager.InstanceIdKey)) { contextProperties.Context.Add(ContextManager.InstanceIdKey, instanceId); } else { contextProperties.Context[ContextManager.InstanceIdKey] = instanceId; } } }
static void Main(string[] args) { ContextManager.CreateContext(); IClientRepository repo1 = ContextManager.GetBean <ClientRepository>("clientRepository"); IClientRepository repo2 = ContextManager.GetBean <ClientRepository>("clientRepository"); Console.WriteLine(Object.ReferenceEquals(repo1, repo2)); IClientService c1 = ContextManager.GetBean <ClientService>("clientService"); IClientService c2 = ContextManager.GetBean <ClientService>("clientService"); Console.WriteLine(Object.ReferenceEquals(c1, c2)); NonBeanRepo nonBeanRepo = ContextManager.InjectedOf <NonBeanRepo>(typeof(NonBeanRepo)); nonBeanRepo.print(); Console.ReadKey(); }
public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = AuthOptions.ISSUER, ValidAudience = AuthOptions.AUDIENCE, IssuerSigningKey = AuthOptions.GetSymmetricSecurityKey() }; }); var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("customsettings.json", optional: true); Configuration = builder.Build(); ContextManager.CreateContext(services, Configuration); services.AddMvc(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); }); services.AddSwaggerGen(c => { var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); ServiceManager.AddTransient(services); }
/// <summary> /// Creates a render context of SoftGL! /// </summary> /// <param name="deviceContext"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="paramNames">parameters' names.</param> /// <param name="paramValues">parameters' values.</param> /// <returns></returns> public static IntPtr CreateContext(IntPtr deviceContext, int width, int height, string[] paramNames, uint[] paramValues) { return(ContextManager.CreateContext(deviceContext, width, height, paramNames, paramValues)); }