Example #1
0
        public IActionResult Edit(int personDescriptionId)
        {
            //
            // Get data
            //

            var description =
                _personData
                .GetPersonDescriptionWithNavigation(
                    personDescriptionId);

            if (description == null)
            {
                return(NotFound());
            }

            //
            // Create edit model
            //

            var editModel = new PersonDescriptionEditModel();

            editModel.Type = (PersonDescriptionTypeOptions)description.Type;
            editModel.Text = description.Description;

            // View helpers
            ViewData["PersonGuid"] = description.Person.PersonGuid;

            return(View(editModel));
        }
Example #2
0
        public IActionResult Edit(
            int personDescriptionId,
            PersonDescriptionEditModel editModel)
        {
            //
            // Get data
            //

            var description =
                _personData
                .GetPersonDescriptionWithNavigation(
                    personDescriptionId);

            if (description == null)
            {
                return(NotFound());
            }

            // Read to validate
            var person =
                _personData
                .ReadPersonWithDescriptions(
                    description.Person.PersonGuid);

            if (person == null)
            {
                return(NotFound());
            }

            //
            // View helpers
            // Model must be ready if validation fails
            //

            ViewData["PersonGuid"] = person.PersonGuid;

            //
            // Validate
            //

            var form =
                new PersonDescriptionModelState(
                    ModelState,
                    new Logic.Validate.PersonDescription(
                        editModel.Text),
                    editModel.Type,
                    person.Descriptions,
                    description.PersonDescriptionId);

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

            form.HasUniqueTypeToBeEdited();
            if (!ModelState.IsValid)
            {
                return(View(editModel));
            }

            //
            // Edit
            //

            description.Type        = (PersonDescriptionType)editModel.Type;
            description.Description = editModel.Text;

            try
            {
                _personData.UpdatePersonDescription(description);
            }
            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(editModel));
            }

            //
            // Update RDF
            //

            var readPerson =
                _personData.ReadAllPersonData(description.Person.PersonGuid);

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

            //
            // Update search index
            //

            // Descriptions are at this time not searchable.

            //
            // Redirect
            //

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