示例#1
0
文件: Repository.cs 项目: idev28/ice
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:IceFactory.Repository.GenericRepository`1" /> class.
 /// </summary>
 /// <param name="context">Context.</param>
 protected Repository(IceFactoryContext context)
 {
     Context = context;
     _dbSet  = context.Set <TEntity>();
 }
示例#2
0
 public vwProductRepository(IceFactoryContext context) : base(context)
 {
 }
示例#3
0
文件: Startup.cs 项目: idev28/ice
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              IceFactoryContext iceFactoryContext)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            //
            // Forward http headers use for run this system under reverse proxy
            // such as IISARR or NGINX.
            app.UseForwardedHeaders();

            app.UseExceptionHandler(appBuilder =>
            {
                appBuilder.Use(async(context, next) =>
                {
                    var error = context.Features[typeof(IExceptionHandlerFeature)] as IExceptionHandlerFeature;

                    //when authorization has failed, should return a json message to client
                    if (error?.Error is SecurityTokenExpiredException)
                    {
                        context.Response.StatusCode  = 401;
                        context.Response.ContentType = "application/json";

                        await context.Response.WriteAsync(JsonConvert.SerializeObject(new
                        {
                            State   = 401,
                            Message = "token expired"
                        }));
                    }
                    //when other error, return a error message json to client
                    else if (error?.Error != null)
                    {
                        context.Response.StatusCode  = 500;
                        context.Response.ContentType = "application/json";

                        await context.Response.WriteAsync(JsonConvert.SerializeObject(new
                        {
                            State = 500,
                            error.Error.Message
                        }));
                    }
                    //when no error, do next.
                    else
                    {
                        await next();
                    }
                });
            });

            //
            // Shows UseCors with named policy.
            app.UseCors("CorsPolicy");
            app.UseAuthentication();
            app.UseHttpsRedirection();
            app.UseMvc();

            //
            // Initial data to database when create new database for first time.
            IceFactoryInitializer.InitializeAsync(iceFactoryContext).Wait();
        }
示例#4
0
 public UnitRepository(IceFactoryContext context) : base(context)
 {
 }
示例#5
0
 public ProductStockRepository(IceFactoryContext context) : base(context)
 {
 }