public static bool HuntIsValid(string id) { Int32 hId; var context = new RabbitDBContext(); var cn = new SqliteConnection(((DbContext)context).Database.GetDbConnection().ConnectionString); try { if (!Int32.TryParse(id, out hId)) { return(false); } cn.Open(); var cmd = new SqliteCommand("select count(*) from Contests where ID = " + hId.ToString() + " and Closed = 0", cn); string result = cmd.ExecuteScalar().ToString(); Int32 count; if (Int32.TryParse(result, out count) && count > 0) { return(true); } return(false); } finally { if (cn.State != System.Data.ConnectionState.Closed) { cn.Close(); } } }
public ActionResult Index() { using (var context = new RabbitDBContext()) { return(View(context.Hunts.OrderByDescending(c => c.Id).ToList())); } }
// DELETE api/hunt/5 public void Delete(string id) { using (var context = new RabbitDBContext()) { string q = string.Format("DELETE FROM Hunt WHERE Id = {0}", id); context.Database.ExecuteSqlCommand(q); } }
public IEnumerable <Hunt> Get() { var hunts = new List <Hunt>(); using (var context = new RabbitDBContext()) { var q = from c in context.Hunts select c; hunts = q.ToList(); } return(hunts); }
public Hunt Get(int id) { Hunt hunt = null; using (var context = new RabbitDBContext()) { var q = from c in context.Hunts where c.Id == id select c; hunt = q.FirstOrDefault(); } return(hunt); }
void Application_Start(object sender, EventArgs e) { // Code that runs on application startup RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var context = new RabbitDBContext(); if (!context.AllMigrationsApplied()) { context.Database.Migrate(); } context.EnsureSeedData(); }
public static void Main(string[] args) { var context = new RabbitDBContext(); if (!context.AllMigrationsApplied()) { context.Database.Migrate(); } context.EnsureSeedData(); var test = context.Hunts.Include(h => h.Animals).FirstOrDefault(); Console.WriteLine(test.PhoneNumber); Console.WriteLine(test.Animals.Count()); }
// 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, RabbitDBContext serverContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); if (!serverContext.AllMigrationsApplied()) { serverContext.Database.Migrate(); } serverContext.EnsureSeedData(); app.UseAuthentication(); /* TODO * // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715 * app.UseJwtBearerAuthentication(new JwtBearerOptions * { * AutomaticAuthenticate = true, * AutomaticChallenge = true, * TokenValidationParameters = new TokenValidationParameters * { * ValidateIssuer = true, * ValidIssuer = "https://issuer.example.com", * * ValidateAudience = true, * ValidAudience = "https://yourapplication.example.com", * * ValidateLifetime = true, * } * }); */ app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public BaseAPIController(RabbitDBContext db, IMapper mapper) { this.db = db; this.mapper = mapper; }