예제 #1
0
        public async Task <ActionResult <Dependent> > CreateDependent(Dependent dependent)
        {
            if (await _dependentRepository.DependentExists(dependent))
            {
                return(BadRequest("A Dependent with the name '" + dependent.FirstName + ' ' + dependent.LastName + "' already exists for this employee"));
            }

            dependent.Birthdate = ParseDates.ParseDate(dependent.Birthdate);
            _dependentRepository.Add(dependent);

            if (await _dependentRepository.SaveAllAsync())
            {
                return(NoContent());
            }

            return(BadRequest("Failed to add dependent"));
        }