public ActionResult _ajaxSaveAuthor(Author author) { if (ModelState.IsValid) { try { //should really do some checking here to validate the save operation var a = _authorsRepository.SaveAuthor(author); ViewBag.SuccessMessage = "Author Saved"; return View("EditorTemplates/Author", a); } catch (Exception ex) { ViewBag.SuccessMessage = "There was a problem saving the record"; //log the exception somewhere and then tell someone who cares return View("EditorTemplates/Author", author); } } else { ViewBag.SuccessMessage = "Author Save Failed"; return View("EditorTemplates/Author", author); } }
/// <summary> /// save the author /// </summary> /// <param name="author">the author to be saved</param> /// <returns></returns> public Author SaveAuthor(Author author) { return _context.SaveAuthor(author); }
public Author SaveAuthor(Author author) { //does it exist? var upd = (from a in _dataContext.Authors where a.AuthorId == author.AuthorId select a).FirstOrDefault(); if (upd == null) { upd = new Author(); _dataContext.Authors.Add(upd); } upd.AuthorFirstName = author.AuthorFirstName; upd.AuthorLastName = author.AuthorLastName; return upd; }