Beispiel #1
0
        static void Main(string[] args)
        {
            Interest interest = new Interest()
            {
                Description = "test",
                InterestId  = 2,
                Type        = "Chess"
            };
            List <Interest> interests = new List <Interest>();

            interests.Add(interest);
            Child child = new Child()
            {
                Id        = 1,
                Age       = 12,
                EyeColor  = "blue",
                FirstName = "John",
                HairColor = "Grey",
                Height    = 178,
                LastName  = "Doe",
                Sex       = "M",
                Weight    = 67,
                Interests = interests
            };
            ChildRepo childRepo = new ChildRepo();

            childRepo.AddChild(child);
            Console.WriteLine(childRepo.GetAllChildren().ToString());
        }
Beispiel #2
0
        public async Task <ChildDTO> UpdateChild(Guid personId, Guid childId, ChildDTO child)
        {
            var personEntity = await PersonRepo.GetPerson(personId).ConfigureAwait(false);

            var childEntity = await ChildRepo.GetChild(childId).ConfigureAwait(false);

            if (personEntity == null || childEntity == null)
            {
                return(null);
            }

            await ChildRepo.UpdateChild(personId, childId, child).ConfigureAwait(false);

            child.PersonId = personId;
            child.Age      = child.Birthday.HasValue
                ? DateTime.Today.Year - child.Birthday.Value.Year
                : await NumberGenerator.GetRandomNumbers().ConfigureAwait(false);

            Logger.LogInformation($"Child with id {child.Id} successfully updated.");

            return(child);
        }
Beispiel #3
0
        public async Task <PersonDTO> GetPerson(Guid id)
        {
            var person = await ChildRepo.GetPersonWithChildren(id).ConfigureAwait(false);

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

            var randomNumber = await NumberGenerator.GetRandomNumbers().ConfigureAwait(false);

            var personDto = new PersonDTO
            {
                ID       = person.Id,
                Name     = person.Name,
                Surname  = person.Surname,
                Birthday = person.Birthday,
                Age      = person.Birthday.HasValue
                    ? DateTime.Today.Year - person.Birthday.Value.Year
                    : randomNumber,
                Children = person.Child.Select(c => new ChildDTO
                {
                    Id       = c.Id,
                    Name     = c.Name,
                    Surname  = c.Surname,
                    Birthday = c.Birthday,
                    Age      = c.Birthday.HasValue
                        ? DateTime.Today.Year - person.Birthday.Value.Year
                        : randomNumber,
                    PersonId = person.Id
                })
            };

            Logger.LogInformation($"Person with id {id} successfully received.");

            return(personDto);
        }