Пример #1
0
        public IActionResult Create(Guid personGuid)
        {
            // Must have an GUID
            if (personGuid == Guid.Empty)
            {
                return(NotFound());
            }

            // Must have a person
            var person =
                _personData.ReadPersonWithDescriptions(personGuid);

            // Do we have what we need so far?
            if (person == null)
            {
                return(NotFound());
            }

            // Page navigation
            ViewData["PersonGuid"] = person.PersonGuid;

            var createModel = new PersonDescriptionCreateModel();

            return(View(createModel));
        }
Пример #2
0
        public IActionResult Create(
            Guid personGuid,
            PersonDescriptionCreateModel createModel)
        {
            // Must have an GUID
            if (personGuid == Guid.Empty)
            {
                return(NotFound());
            }

            // Must have a person
            var person =
                _personData.ReadPersonWithDescriptions(personGuid);

            // Do we have what we need so far?
            if (person == null)
            {
                return(NotFound());
            }

            // Page navigation
            ViewData["PersonGuid"] = person.PersonGuid;

            //
            // Validate
            //

            var form =
                new PersonDescriptionModelState(
                    ModelState,
                    new Logic.Validate.PersonDescription(
                        createModel.Text),
                    createModel.Type,
                    person.Descriptions,
                    null);

            form.HasValidValues();
            if (!ModelState.IsValid)
            {
                return(View(createModel));
            }

            form.HasUniqueTypeToBeCreated();
            if (!ModelState.IsValid)
            {
                return(View(createModel));
            }

            //
            // Create
            //

            var newDescription = new PersonDescription();

            newDescription.PersonId    = person.PersonId;
            newDescription.Type        = (PersonDescriptionType)createModel.Type;
            newDescription.Description = createModel.Text;

            try
            {
                _personData.AddPersonDescription(newDescription);
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.)
                ModelState.AddModelError(
                    "",
                    "Unable to save changes. " +
                    "Try again, and if the problem persists, " +
                    "see your system administrator.");

                return(View(createModel));
            }

            //
            // Update RDF
            //

            var readPerson = _personData.ReadAllPersonData(personGuid);

            if (readPerson != null)
            {
                _rdfData.AddOrUpdatePerson(readPerson);
            }

            //
            // Update search index
            //

            // Descriptions are at this time not searchable.

            //
            // Redirect
            //

            return(RedirectToAction(
                       "Details",
                       "Person",
                       new { personGuid = person.PersonGuid }));
        }