public ActionResult Create(AuthorModel model) { if (this.ModelState.IsValid) { // Edit Author Author author = new Author(); author.ID = model.Name; author.Name = model.DisplayName; author.Email = model.Email; EngineException ex = AuthorComp.Create(author); if (ex != null) { this.ModelState.AddModelError("Create", ex); } } if (this.ModelState.IsValid) { this.TempData["Message"] = "用户添加成功"; return this.RedirectToAction("Manage"); } this.ViewData.Model = model; return this.View(); }
public ActionResult Edit(AuthorModel model) { if (this.ModelState.IsValid) { // Edit Author string oldName = this.TempData["AuthorName"].ToString(); Author author = new Author(); author.ID = model.Name; author.Name = model.DisplayName; author.Email = model.Email; EngineException ex = AuthorComp.Update(oldName, author); if (ex != null) { this.ModelState.AddModelError("Edit", ex); } } if (this.ModelState.IsValid) { this.TempData["Message"] = "用户信息已更新"; return this.RedirectToAction("Manage"); } this.ViewData.Model = model; return this.View(); }
public ActionResult Edit(string id) { AuthorModel model = new AuthorModel(); if (!string.IsNullOrEmpty(id)) { Author author = AuthorComp.GetAuthor(id); if (author != null) { this.TempData["AuthorName"] = author.ID; model.Name = author.ID; model.DisplayName = author.Name; model.Email = author.Email; } } this.ViewData.Model = model; return this.View(); }