public static void NotifyNewComment(int commentId) { // Prepare Postal classes to work outside of ASP.NET request var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails")); var engines = new ViewEngineCollection(); engines.Add(new FileSystemRazorViewEngine(viewsPath)); var emailService = new EmailService(engines); // Get comment and send a notification. using (var db = new OdeToFoodDb()) { var comments = db.Comments.Find(commentId); var email = new NewCommentEmail { To = comments.Email, UserName = comments.UserName, Comment = comments.Comment }; emailService.Send(email); } }
protected override void Seed(OdeToFoodDb context) { context.Restaurants.AddOrUpdate(r => r.Name, new Restaurant { Name = "Sabatino's", City = "Baltimore", Country = "USA" }, new Restaurant { Name = "Great Lake", City = "Chicago", Country = "USA" }, new Restaurant { Name = "Smaka", City = "Gothenburg", Country = "Sweden", Reviews = new List <RestaurantReview> { new RestaurantReview { Rating = 9, Body = "Great food!", ReviewerName = "Scott" } } }); for (int i = 0; i < 1000; i++) { context.Restaurants.AddOrUpdate(r => r.Name, new Restaurant { Name = i.ToString(), City = "Nowhere", Country = "USA" }); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // Initialize the product database. Database.SetInitializer(new OdeToFoodDbInitializer()); var con = new OdeToFoodDb(); con.Database.Initialize(true); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // Insert a new user into the database using (var db = new OdeToFoodDb()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return RedirectToAction("Manage"); } if (ModelState.IsValid) { // Insert a new user into the database using (var db = new OdeToFoodDb()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return RedirectToLocal(returnUrl); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return View(model); }
public RestaurantController() { this.db = new OdeToFoodDb(); }
public RestaurantsController(OdeToFoodDb context) { _context = context; }
public Restaurants1Controller() { db = new OdeToFoodDb(); }