async public Task <ActionResult> Create([Bind(Include = "ID,ContentText,PublichDate,CreateUser")] MainThemes mainThemes) { try { if (ModelState.IsValid) { await repository.Insert(mainThemes); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "無法儲存,請聯絡網站管理員"); } return(View(mainThemes)); }
public async Task <ActionResult> Create([Bind(Include = "ID,TopicID,ContentText,PublichDate,CreateUser")] Forum forum) { try { if (ModelState.IsValid) { await repository.Insert(forum); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "無法儲存,請聯絡網站管理員"); } ViewBag.TopicID = new SelectList(db.MainThemes, "ID", "ContentText", forum.TopicID); return(View(forum)); }
public async Task <ActionResult> Details(ArticleAndReplyModel replyModel) { try { if (ModelState.IsValid) { string subject = TempData["subject"].ToString(); replyModel.reply.ArticleID = db.MainArticles.Where(u => u.ID.ToString().Equals(subject)).Single().ID; replyModel.reply.ArticelMaker = db.MainArticles.Where(u => u.ID.Equals(replyModel.reply.ArticleID)).SingleOrDefault().CreateUser; repository = new ReplyModelRepository(db); await repository.Insert(replyModel); return(RedirectToAction("Details", "MainArticleModels", new { id = replyModel.reply.ArticleID })); } } catch (DataException) { return(RedirectToAction("DataError", "Error", new { message = "用戶儲存錯誤" })); } return(View(replyModel)); }
public async Task <ActionResult> Create([Bind(Include = "Subject,ContentText")] MainArticleModel mainArticleModel) { string forum = TempData["Forum"].ToString(); try { if (ModelState.IsValid) { mainArticleModel.Forum = db.Categories.Where(c => c.ContentText.Equals(forum)).First(); await repository.Insert(mainArticleModel); return(RedirectToAction("Index", "MainArticleModels", new { title = forum })); } } catch (DataException) { return(RedirectToAction("DataError", "Error", new { message = "儲存錯誤" })); } return(View(mainArticleModel)); }