protected void SubmitClick(object sender, EventArgs e) { using (var eds = new Data.WikipediaEntities()) { string stringid = Request.QueryString["id"]; int id; if (int.TryParse(stringid, out id)) { /* create article */ Data.Article art = new Data.Article(); art.DomainId = id; art.CreateDate = DateTime.Now; if (Request.IsAuthenticated) art.UserName = User.Identity.Name; eds.Articles.AddObject(art); eds.SaveChanges(); /* create article version */ Data.Version ver = new Data.Version(); ver.ArticleId = art.Id; ver.Name = ArticleName.Text; ver.Content = ArticleContent.Text; ver.CreateDate = DateTime.Now; eds.Versions.AddObject(ver); eds.SaveChanges(); /* redirect to new article */ Response.Redirect("~/Article.aspx?id=" + art.Id); } } }
protected void ProtectToggle(object sender, EventArgs e) { using (var eds = new Data.WikipediaEntities()) { string stringid = Request.QueryString["id"]; int id; if (int.TryParse(stringid, out id)) { var article = eds.Articles.Where(art => art.Id == id).First(); if (article.UserName == User.Identity.Name || User.IsInRole("Editor")) { if (article.IsProtected) { article.IsProtected = false; ProtectLink.Text = "Protect"; } else { article.IsProtected = true; ProtectLink.Text = "UnProtect"; } } eds.SaveChanges(); } } }
public void VersionDeleted(object sender, EntityDataSourceChangedEventArgs e) { using (var eds = new Data.WikipediaEntities()) { Data.Version ver = e.Entity as Data.Version; var art = eds.Articles.Where(article => article.Id == ver.ArticleId).First(); if (art.Versions.Count == 0) { eds.Articles.DeleteObject(art); eds.SaveChanges(); } } }
protected void UploadClick(object sender, EventArgs e) { if (File.HasFile) { byte[] buffer = new byte[File.PostedFile.ContentLength]; File.PostedFile.InputStream.Read(buffer, 0, File.PostedFile.ContentLength); using (var eds = new Data.WikipediaEntities()) { var img = new Data.Image(); img.Content = buffer; img.ContentType = File.PostedFile.ContentType; img.ContentLength = File.PostedFile.ContentLength; eds.Images.AddObject(img); eds.SaveChanges(); Response.Redirect("~/Image.ashx?id=" + img.Id); } } }
protected void SubmitClick(object sender, EventArgs e) { using (var eds = new Data.WikipediaEntities()) { Data.Article art = ViewState["article"] as Data.Article; if ((ArticleName.Text != art.Name || ArticleContent.Text != art.Content) && (!art.IsProtected || Request.IsAuthenticated)) { Data.Version ver = new Data.Version(); ver.ArticleId = art.Id; ver.Name = ArticleName.Text; ver.Content = ArticleContent.Text; ver.CreateDate = DateTime.Now; eds.Versions.AddObject(ver); eds.SaveChanges(); } Response.Redirect("~/Article.aspx?id=" + art.Id); } }