public ActionResult CreateDocument(DocumentInfo document) { if (document.DocumentCategoryInfoID == 0) { InitDocumentCategorySelectList(); ViewBag.Message = "必须指定分类!"; return View(document); } if (string.IsNullOrEmpty(document.Title)) { InitDocumentCategorySelectList(); ViewBag.Message = "标题不能为空!"; return View(document); } if (string.IsNullOrEmpty(document.Content)) { InitDocumentCategorySelectList(); ViewBag.Message = "正文不能为空!"; return View(document); } DocumentInfo doc = new DocumentInfo(); doc.Title = document.Title; doc.DocumentCategoryInfoID = document.DocumentCategoryInfoID; doc.LastUpdateTime = DateTime.Now; doc.Sort = document.Sort; doc.Content = document.Content; _documentRepository.CreateDocument(doc); return RedirectToAction("Manage"); }
public void UpdateDocument(DocumentInfo document) { if (document == null) throw new ArgumentNullException("document"); DataContext.Entry(document).State = EntityState.Modified; DataContext.SaveChanges(); }
public void CreateDocument(DocumentInfo document) { if (document == null) throw new ArgumentNullException("document"); DataContext.DocumentInfoes.Add(document); DataContext.SaveChanges(); }
public ActionResult EditDocument(int id, DocumentInfo document) { var doc = _documentRepository.GetDocumentById(id); if (doc == null) return HttpNotFound(); doc.Content = document.Content; doc.Title = document.Title; doc.Sort = document.Sort; doc.LastUpdateTime = DateTime.Now; _documentRepository.UpdateDocument(doc); return RedirectToAction("Manage"); }