Пример #1
0
        public ActionResult Create(Guid id)
        {
            try
            {
                var bundle = this.ImsiClient.Query <ReferenceTerm>(r => r.Key == id && r.ObsoletionTime == null, 0, null, true);

                bundle.Reconstitute();

                var referenceTerm = bundle.Item.OfType <ReferenceTerm>().FirstOrDefault(r => r.Key == id && r.ObsoletionTime == null);

                if (referenceTerm == null)
                {
                    TempData["error"] = Locale.ReferenceTermNotFound;

                    return(RedirectToAction("Index", "ReferenceTerm"));
                }

                var model = new CreateReferenceTermNameModel(referenceTerm)
                {
                    LanguageList          = LanguageUtil.GetLanguageList().ToSelectList("DisplayName", "TwoLetterCountryCode", null, true).ToList(),
                    TwoLetterCountryCode  = Locale.EN,
                    ReferenceTermNameList = referenceTerm.DisplayNames.Select(n => new ReferenceTermNameViewModel(n)).ToList()
                };

                return(View(model));
            }
            catch (Exception e)
            {
                Trace.TraceError($"Unable to load reference term name create page: {e}");
                this.TempData["error"] = Locale.UnexpectedErrorMessage;
            }

            return(RedirectToAction("Edit", "ReferenceTerm", new { id }));
        }
Пример #2
0
        public ActionResult Create(CreateReferenceTermNameModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var bundle = this.ImsiClient.Query <ReferenceTerm>(r => r.Key == model.ReferenceTermId && r.ObsoletionTime == null, 0, null, true);

                    bundle.Reconstitute();

                    var referenceTerm = bundle.Item.OfType <ReferenceTerm>().FirstOrDefault(r => r.Key == model.ReferenceTermId && r.ObsoletionTime == null);

                    if (referenceTerm == null)
                    {
                        TempData["error"] = Locale.ReferenceTermNotFound;

                        return(RedirectToAction("Index", "ReferenceTerm"));
                    }

                    referenceTerm.DisplayNames.Add(model.ToReferenceTermName());

                    var result = this.ImsiClient.Update <ReferenceTerm>(referenceTerm);

                    TempData["success"] = Locale.ReferenceTermNameCreatedSuccessfully;

                    return(RedirectToAction("Edit", "ReferenceTerm", new { id = result.Key }));
                }
            }
            catch (Exception e)
            {
                Trace.TraceError($"Unable to retrieve entity: { e }");
            }

            TempData["error"]  = Locale.UnableToCreateReferenceTermName;
            model.LanguageList = LanguageUtil.GetLanguageList().ToSelectList("DisplayName", "TwoLetterCountryCode").ToList();

            return(View(model));
        }