public void RecordInDb() { using (var context = new CircusContext()) { context.Update(this); context.SaveChanges(); } }
public UserModule() { Context = new CircusContext(); Get("/User", parameters => GetCurrentUser()); Get("/Performances", parameters => GetPerformances()); Get("/Stars", parameters => GetStars()); Post("/authentify/{UserName}/{Password}", parameters => { string userName = parameters.UserName; string password = parameters.Password; UserSingleton.GetInstance.Init(userName, password); if (UserSingleton.GetInstance.User != null) { var response = Response.AsJson(Nancy.HttpStatusCode.OK); return(response); } else { var response = Response.AsJson(Nancy.HttpStatusCode.Forbidden); return(response); } }); Put("/Country/{Name}", parameters => { string countryName = parameters.Name; bool isCountryRecorded = (from c in Context.Countries where c.Name == countryName select c).Any(); if (!isCountryRecorded) { Country country = new Country() { Name = countryName }; Context.Update(country); Context.SaveChanges(); var response = Response.AsJson(Nancy.HttpStatusCode.OK); return(response); } else { var response = Response.AsJson(Nancy.HttpStatusCode.Forbidden); return(response); } }); }
public void Populate() { _context.Database.EnsureDeleted(); _context.Database.EnsureCreated(); List <Address> addresses = PopulateLocations(); List <Star> stars = Stars(); List <User> users = Users(addresses); List <Performance> performances = Performances(stars); List <Tour> tours = Tours(addresses, performances); Orders(users, tours); _context.SaveChanges(); Console.WriteLine("DB populisation terminated"); }