public JsonResult HasReferenceTerm(EditConceptModel model) { if (!string.IsNullOrWhiteSpace(model.AddReferenceTerm) && !string.Equals(model.AddReferenceTerm, "null")) { return(Json(true, JsonRequestBehavior.AllowGet)); // indicates its valid } return(Json(false, JsonRequestBehavior.AllowGet)); }
public JsonResult HasRelationshipType(EditConceptModel model) { if (!string.IsNullOrWhiteSpace(model.RelationshipType) && !string.Equals(model.RelationshipType, "null")) { return(Json(true, JsonRequestBehavior.AllowGet)); } return(Json(true, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(Guid id, Guid?versionId) { try { var concept = this.GetConcept(id, versionId); if (concept == null) { this.TempData["error"] = Locale.ConceptNotFound; return(RedirectToAction("Index")); } // system concepts cannot be edited if (concept.IsSystemConcept) { this.TempData["error"] = Locale.SystemConceptsCannotBeEdited; return(RedirectToAction("ViewConcept", new { id })); } // force load concept class if the server didn't return it if (concept.Class == null && concept.ClassKey.HasValue && concept.ClassKey.Value != Guid.Empty) { concept.Class = this.GetConceptClass(concept.ClassKey.Value); } var model = new EditConceptModel(concept) { LanguageList = LanguageUtil.GetLanguageList().ToSelectList("DisplayName", "TwoLetterCountryCode").ToList() }; var conceptClasses = this.GetConceptClasses(); model.ConceptClassList.AddRange(conceptClasses.ToSelectList().OrderBy(c => c.Text)); if (concept.Class?.Key != null) { var selectedClass = conceptClasses.FirstOrDefault(c => c.Key == concept.Class.Key); model.ConceptClass = selectedClass?.Key.ToString(); } model.ReferenceTerms = this.GetConceptReferenceTerms(id, versionId).Select(r => new ReferenceTermViewModel(r, concept)).ToList(); return(View(model)); } catch (Exception e) { Trace.TraceError($"Unable to retrieve concept: {e}"); this.TempData["error"] = Locale.UnexpectedErrorMessage; } return(RedirectToAction("ViewConcept", new { id })); }
public ActionResult Edit(EditConceptModel model) { try { var concept = this.GetConcept(model.Id, model.VersionKey); if (concept == null) { TempData["error"] = Locale.ConceptNotFound; return(RedirectToAction("Index")); } if (model.HasAddReferenceTerm()) { if (string.IsNullOrWhiteSpace(model.AddReferenceTerm)) { ModelState.AddModelError("AddReferenceTerm", Locale.ReferenceTermRequired); } if (string.IsNullOrWhiteSpace(model.RelationshipType)) { ModelState.AddModelError("RelationshipType", Locale.RelationshipRequired); } } if (ModelState.IsValid) { if (!string.Equals(concept.Mnemonic, model.Mnemonic) && !DoesConceptExist(model.Mnemonic)) { TempData["error"] = Locale.Mnemonic + " " + Locale.MustBeUnique; return(View(model)); } concept = model.ToEditConceptModel(ImsiClient, concept); concept.ConceptSetsXml = this.LoadConceptSets(model.Id); var result = this.ImsiClient.Update <Concept>(concept); TempData["success"] = Locale.ConceptUpdatedSuccessfully; return(RedirectToAction("ViewConcept", new { id = result.Key, versionId = result.VersionKey })); } var conceptClasses = this.GetConceptClasses(); model.ConceptClassList.AddRange(conceptClasses.ToSelectList().OrderBy(c => c.Text)); if (concept.Class?.Key != null) { var selectedClass = conceptClasses.FirstOrDefault(c => c.Key == concept.Class.Key); model.ConceptClass = selectedClass?.Key.ToString(); } model.ReferenceTerms = this.GetConceptReferenceTerms(concept.Key.Value, concept.VersionKey).Select(r => new ReferenceTermViewModel(r, concept)).ToList(); model.Languages = concept.ConceptNames.Select(k => new ConceptNameViewModel(k.Language, k.Name, concept)).ToList(); } catch (Exception e) { Trace.TraceError($"Unable to update concept: {e}"); } TempData["error"] = Locale.UnableToUpdateConcept; return(View(model)); }