public IActionResult GetPerson([FromRoute] int id)
        {
            PersonAccomplishmentCommand person = _dbHelper.GetPerson(id);

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

            return(Ok(person));
        }
Exemplo n.º 2
0
        public IActionResult Create(PersonAccomplishmentCommand input)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", input));
            }
            else
            {
                Person person = MapPerson(input);
                person = _helper.CreatePerson(person);

                return(RedirectToAction("AllPersons"));
            }
        }
Exemplo n.º 3
0
        public IActionResult EditPerson(PersonAccomplishmentCommand input)
        {
            if (!ModelState.IsValid)
            {
                return(View("EditPerson", input));
            }
            else
            {
                Person newPerson = MapPerson(input);
                newPerson.PersonID = input.PersonID;
                _helper.UpdatePerson(newPerson);

                return(RedirectToAction("AllPersons"));
            }
        }
        public void OnActionExecuting(ActionExecutingContext context)
        {
            Person person = (Person)context.ActionArguments["person"];

            PersonAccomplishmentCommand oldPerson = _dBHelper.GetPerson(person.PersonID);

            if (oldPerson == null)
            {
                _log.LogWarning("The following Person ID was not found: {personID}", person.PersonID);
                context.Result = new BadRequestObjectResult("Person not found.");
            }
            else if (!person.FirstName.Equals(oldPerson.FirstName) || !person.LastName.Equals(oldPerson.LastName))
            {
                _log.LogWarning("A user attempted to updated the following name: {lastName}, {firstName}", person.LastName, person.FirstName);
                context.Result = new BadRequestObjectResult("Cannot update a person's name.");
            }
        }
Exemplo n.º 5
0
        public Person MapPerson(PersonAccomplishmentCommand input)
        {
            Person person = new Person
            {
                FirstName       = input.FirstName,
                LastName        = input.LastName,
                Birthdate       = input.Birthdate,
                City            = input.City,
                State           = input.State,
                Accomplishments = input.Accomplishments?.Select(accomplishment =>
                                                                new Accomplishment
                {
                    Name = accomplishment.Name,
                    DateOfAccomplishment = accomplishment.DateOfAccomplishment
                }).ToHashSet()
            };

            return(person);
        }