public void Add(string key, string value) { db.Settings.Add(new Setting { Key = key, Value = value }); db.SaveChanges(); }
public AdminModule(IdeastrikeContext dbContext, ISettingsRepository settings) : base("/admin") { Get["/"] = _ => ""; Get["/moderation"] = _ => ""; Get["/search"] = _ => ""; Get["/forums"] = _ => ""; Get["/forum/{forumId}"] = _ => ""; Get["/settings"] = _ => View["Admin/Settings", settings]; Post["/settings"] = _ => { settings.WelcomeMessage = Request.Form.welcomemessage; settings.Title = Request.Form.title; settings.Name = Request.Form.yourname; settings.HomePage = Request.Form.homepage; settings.GAnalyticsKey = Request.Form.analyticskey; try { dbContext.SaveChanges(); } catch (Exception ex) { var y = ex.Message; } return(Response.AsRedirect("/admin/settings")); }; }
public HomeModule() { Get["/"] = _ => { using (var db = new IdeastrikeContext()) { db.Ideas.Add(new Idea { Title = "I heard you like ideas, so I put an idea in your ideas", Time = DateTime.UtcNow }); db.SaveChanges(); return(View["Home/Index", string.Format("Hello, world. There are {0} ideas", db.Ideas.Count())]); } }; }
public IdeaModule() { Get["/idea/{id}"] = parameters => { using (var db = new IdeastrikeContext()) { double id = parameters.id; var idea = db.Ideas.FirstOrDefault(i => i.Id == id); return(string.Format("Id:{0} Title:{1} Description:{2}", idea.Id, idea.Title, idea.Description)); } }; Get["/idea/{id}/delete"] = parameters => { using (var db = new IdeastrikeContext()) { double id = parameters.id; var idea = db.Ideas.FirstOrDefault(i => i.Id == id); db.Ideas.Remove(idea); db.SaveChanges(); return(string.Format("Deleted Item {0}", id)); } }; Post["/idea/add"] = parameters => { using (var db = new IdeastrikeContext()) { var author = Request.Form.author; var title = Request.Form.title; var desc = Request.Form.description; var newIdea = db.Ideas.Add(new Idea { Title = title, Author = author, Description = desc }); if (newIdea.isValid()) { // store the new idea and redirect to the new idea db.SaveChanges(); return(Response.AsRedirect(string.Format("/idea/{0}/", newIdea.Id))); } else { // return to form with errors List <string> errorList = newIdea.generateErrorList(); return(View["Home/Add", new { errorList, author, title, desc }]); } } }; }
public CommentModule() : base("/idea") { Get["/{idea}/comment"] = parameters => { using (var db = new IdeastrikeContext()) { db.Comments.Add(new Comment { IdeaId = parameters.idea }); db.SaveChanges(); return(View["Comment/Index", string.Format("Hello, world. There are {0} comments for Idea {1}", db.Comments.Count(), parameters.idea)]); } }; Get["/{idea}/comment/{id}"] = parameters => { using (var db = new IdeastrikeContext()) { int id = parameters.id; int idea = parameters.idea; var comment = db.Comments.FirstOrDefault(i => i.Id == id && i.IdeaId == idea); return(string.Format("Comment Id:{0}", comment.Id)); } }; Get["/{idea}/comment/{id}/delete"] = parameters => { using (var db = new IdeastrikeContext()) { int id = parameters.id; int idea = parameters.idea; var comment = db.Comments.FirstOrDefault(i => i.Id == id && i.IdeaId == idea); db.Comments.Remove(comment); db.SaveChanges(); return(string.Format("Deleted Comment {0} for Idea {1}", id, idea)); } }; }
public IdeaModule() { Get["/idea/{id}"] = parameters => { using (var db = new IdeastrikeContext()) { double id = parameters.id; var idea = db.Ideas.FirstOrDefault(i => i.Id == id); return(string.Format("Id:{0} Title:{1} Description:{2}", idea.Id, idea.Title, idea.Description)); } }; Get["/idea/{id}/delete"] = parameters => { using (var db = new IdeastrikeContext()) { double id = parameters.id; var idea = db.Ideas.FirstOrDefault(i => i.Id == id); db.Ideas.Remove(idea); db.SaveChanges(); return(string.Format("Deleted Item {0}", id)); } }; }
public AdminModule(IdeastrikeContext dbContext, ISettingsRepository settings, IUserRepository users) : base("/admin") { this.RequiresAuthentication(); Get["/"] = _ => { var m = Context.Model(string.Format("Admin - {0}", settings.Title)); m.Name = settings.Name; m.WelcomeMessage = settings.WelcomeMessage; m.HomePage = settings.HomePage; m.GAnalyticsKey = settings.GAnalyticsKey; return(View["Admin/Index", m]); }; Get["/users"] = _ => { var m = Context.Model(string.Format("Admin - {0}", settings.Title)); m.Name = settings.Name; m.WelcomeMessage = settings.WelcomeMessage; m.HomePage = settings.HomePage; m.GAnalyticsKey = settings.GAnalyticsKey; m.Users = users.GetAll(); return(View["Admin/Users", m]); }; Get["/moderation"] = _ => { var m = Context.Model(string.Format("Admin - {0}", settings.Title)); m.Name = settings.Name; m.WelcomeMessage = settings.WelcomeMessage; m.HomePage = settings.HomePage; m.GAnalyticsKey = settings.GAnalyticsKey; return(View["Admin/Moderation", m]); }; Get["/settings"] = _ => { var m = Context.Model(string.Format("Admin - {0}", settings.Title)); m.Name = settings.Name; m.WelcomeMessage = settings.WelcomeMessage; m.HomePage = settings.HomePage; m.GAnalyticsKey = settings.GAnalyticsKey; return(View["Admin/Settings", m]); }; Post["/settings"] = _ => { settings.WelcomeMessage = Request.Form.welcomemessage; settings.Title = Request.Form.title; settings.Name = Request.Form.yourname; settings.HomePage = Request.Form.homepage; settings.GAnalyticsKey = Request.Form.analyticskey; try { dbContext.SaveChanges(); } catch (Exception ex) { var y = ex.Message; } return(Response.AsRedirect("/admin/settings")); }; Get["/search"] = _ => ""; Get["/forums"] = _ => ""; Get["/forum/{forumId}"] = _ => ""; }
public void Add(Image image) { _dataContext.Images.Add(image); _dataContext.SaveChanges(); }