public ActionResult Edit(Guid id) { try { var assigningAuthorityInfo = this.AmiClient.GetAssigningAuthorities(m => m.Key == id).CollectionItem.FirstOrDefault(); if (assigningAuthorityInfo == null) { TempData["error"] = Locale.AssigningAuthorityNotFound; return(RedirectToAction("Index")); } var model = new EditAssigningAuthorityModel(assigningAuthorityInfo) { AuthorityScopeList = assigningAuthorityInfo.AssigningAuthority.AuthorityScope.Select(x => new AuthorityScopeViewModel(x, assigningAuthorityInfo.Id) { Class = x.Class == null && x.ClassKey.HasValue ? (this.ImsiClient.Get <ConceptClass>(x.ClassKey.Value, null) as ConceptClass)?.Name : x.Class?.Name }).ToList() }; return(View(model)); } catch (Exception e) { Trace.TraceError($"Unable to retrieve assigning authority: {e}"); this.TempData["error"] = Locale.UnexpectedErrorMessage; } return(RedirectToAction("Index")); }
public ActionResult Edit(EditAssigningAuthorityModel model) { try { var assigningAuthorityInfo = this.AmiClient.GetAssigningAuthorities(m => m.Key == model.Id).CollectionItem.FirstOrDefault(); if (assigningAuthorityInfo == null) { TempData["error"] = Locale.AssigningAuthorityNotFound; return(RedirectToAction("Index")); } if (!assigningAuthorityInfo.AssigningAuthority.Oid.Equals(model.Oid)) { var exists = this.AmiClient.GetAssigningAuthorities(m => m.Oid == model.Oid).CollectionItem.FirstOrDefault(); if (exists?.AssigningAuthority != null) { ModelState.AddModelError("Oid", Locale.OidMustBeUnique); } } if (!assigningAuthorityInfo.AssigningAuthority.Name.Equals(model.Name)) { var duplicateName = this.AmiClient.GetAssigningAuthorities(m => m.Name == model.Name).CollectionItem.FirstOrDefault(); if (duplicateName?.AssigningAuthority != null) { ModelState.AddModelError("Name", Locale.NameMustBeUnique); } } if (!assigningAuthorityInfo.AssigningAuthority.DomainName.Equals(model.DomainName)) { var duplicateDomainName = this.AmiClient.GetAssigningAuthorities(m => m.DomainName == model.DomainName).CollectionItem.FirstOrDefault(); if (duplicateDomainName?.AssigningAuthority != null) { ModelState.AddModelError("DomainName", Locale.DomainNameMustBeUnique); } } if (model.HasSelectedAuthorityScope(assigningAuthorityInfo.AssigningAuthority)) { ModelState.AddModelError("AddConcepts", Locale.ConceptSelectedExists); } if (ModelState.IsValid) { assigningAuthorityInfo.AssigningAuthority = model.ToAssigningAuthorityInfo(assigningAuthorityInfo.AssigningAuthority); this.AmiClient.UpdateAssigningAuthority(model.Id.ToString(), assigningAuthorityInfo); TempData["success"] = Locale.AssigningAuthorityUpdatedSuccessfully; return(RedirectToAction("ViewAssigningAuthority", new { id = model.Id })); } model.AuthorityScopeList = assigningAuthorityInfo.AssigningAuthority.AuthorityScope.Select(x => new AuthorityScopeViewModel(x, assigningAuthorityInfo.Id)).ToList(); } catch (Exception e) { Trace.TraceError($"Unable to update assigning authority: {e}"); } TempData["error"] = Locale.UnableToUpdateAssigningAuthority; return(View(model)); }