private void DeleteData()
        {
            try
            {
                using (var ctx = new TrendingContext())
                {
                    IQueryable <Item> allItems = ctx.Item;
                    ctx.Item.RemoveRange(allItems);
                    ctx.Database.ExecuteSqlCommand("DBCC CHECKIDENT('Item', RESEED, 0)");
                    ctx.SaveChanges();

                    IQueryable <RootObject> allRoot = ctx.RootObject;
                    ctx.RootObject.RemoveRange(allRoot);
                    ctx.Database.ExecuteSqlCommand("DBCC CHECKIDENT('RootObject', RESEED, 0)");
                    ctx.SaveChanges();

                    IQueryable <Owner> allOwner = ctx.Owner;
                    ctx.Owner.RemoveRange(allOwner);
                    ctx.Database.ExecuteSqlCommand("DBCC CHECKIDENT('Owner', RESEED, 0)");
                    ctx.SaveChanges();
                }
            }
            catch (Exception e)
            {
                ViewBag.Message = e.Message;
            }
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            ConfigureConsul(services);

            var secret = "eBCatxoffIIq6ESdrDZ8LKI3zpxhYkYM";
            var key    = Encoding.ASCII.GetBytes(secret);

            services.AddAuthentication(option =>
            {
                option.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                option.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.SaveToken                 = true;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuerSigningKey = true,
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });

            services.AddAuthorization();

            services.AddMessagePublishing("TrendingService", builder =>
            {
                builder.WithHandler <NewTopicTweetMessageHandler>("NewTopicTweetMessage");
            });

            var config = new ServerConfig();

            Configuration.Bind(config);

            var trendingContext = new TrendingContext(config.MongoDB);
            var repo            = new TrendingRepository(trendingContext);

            services.AddSingleton <ITrendingRepository>(repo);

            services.AddScoped <ITrendingService, Services.TrendingService>();
        }