/** * Create article from a Articles db object (ADO entity) (don't know if that's the correct terminology) * @param name="article" we run First on article, only one expected */ private Article(Articles article) { try { this.Id = article.Id; this.Title = article.Title; this.Body = article.Body; } catch (Exception) { } }
public ActionResult Edit(string title, FormCollection collection) { Article article = null; ViewData["success"] = false; WikiDb WikiDb = new WikiDb(); //If we cant check session or session username isnt set, this user cannot edit article try { if (Session["username"] == null) { ViewData["error_message"] = "You have to be logged in to edit an article."; return View(new Article(title)); } } catch { ViewData["error_message"] = "You have to be logged in to edit an article."; return View(new Article(title)); } try { article = new Article(title); } catch (ArticleDoesNotExistException) { try { //Articles newArticle = new Articles { Title = collection["Title"], Body = collection["Body"] }; Articles newArticle = new Articles(); newArticle.Title = collection["Title"]; newArticle.Body = collection["Body"]; WikiDb.AddToArticles(newArticle); WikiDb.SaveChanges(); //ViewData["debug"] += collection["Id"]; RedirectToAction("Details/" + title); } catch (Exception) { ViewData["debug"] += "article doesnt exist and cant redirect"; return View(new Article()); } } if (article == null) { return View(new Article()); } UpdateModel(WikiDb.Articles.Single(a => a.Id == article.Id), collection.ToValueProvider()); WikiDb.SaveChanges(); ViewData["success"] = true; return View(new Article(title)); }
/// <summary> /// Deprecated Method for adding a new object to the Articles EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToArticles(Articles articles) { base.AddObject("Articles", articles); }
/// <summary> /// Create a new Articles object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="title">Initial value of the Title property.</param> public static Articles CreateArticles(global::System.Int32 id, global::System.String title) { Articles articles = new Articles(); articles.Id = id; articles.Title = title; return articles; }