public ActionResult SaveGlossary(FormCollection collection) { var model = new GlossaryView(); try { if (TryUpdateModel(model)) { var glossaryDto = model.ToGlossaryDto(); if (glossaryDto == null) { return(Json(new { success = false, errorMessage = "Error saving glossary" })); } // new glossary if (model.Id == -1) { _glossaryBusinessManager.AddGlossary(glossaryDto); } else//edit existing glossary { _glossaryBusinessManager.UpdateGlossary(glossaryDto); } var glossaryModel = GetGlossaryModel(); return(Json(new { success = true, model = MvcHelper.EncodeJson(glossaryModel) }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, errorMessage = string.Join(Environment.NewLine, ModelState.GetErros().ToArray()) })); } catch { return(Json(new { success = false, errorMessage = "Error saving glossary" })); } }
public static Glossary ToGlossaryDto(this GlossaryView glossary) { try { return(new Glossary() { GlossaryId = glossary.Id, Term = glossary.Term, Definition = glossary.Definition }); } catch (Exception) { return(null); } }
public ActionResult Term(int?id, string term) { var m = new GlossaryView(); //m.Terms = DataAccess.GetAllTerms(); if (id.HasValue) { m.ActiveTerm = DataAccess.GetSingleTerm(id.Value); } else if (!string.IsNullOrEmpty(term)) { m.ActiveTerm = DataAccess.GetSingleTerm(term); } m.Version = DataAccess.GetKeyValue("GlossaryVersion"); return(View("Term", m)); }
public ActionResult Term(int? id, string term) { var m = new GlossaryView(); //m.Terms = DataAccess.GetAllTerms(); if (id.HasValue) { m.ActiveTerm = DataAccess.GetSingleTerm(id.Value); } else if (!string.IsNullOrEmpty(term)) { m.ActiveTerm = DataAccess.GetSingleTerm(term); } m.Version = DataAccess.GetKeyValue("GlossaryVersion"); return View("Term",m); }