public async Task <ActionResult <Voter> > UpdateAge(int id, [FromBody] Voter model) { if (ModelState.IsValid) { //First we get today's date. var today = DateTime.Today; //Now calculate age. var age = today.Year - model.DateOfBirth.Year; if (age > 18) { try { await _voterRepository.UpdateAge(id, model); return(Ok("Voter Updated Successfully.")); } catch (Exception) { return(BadRequest()); } } else { return(NotFound("Voter's Age must be > 18.")); } } return(NotFound()); }