Exemplo n.º 1
0
 public async Task<ChildDto> SaveChildAsync(ChildDto childDto)
 {
     if (childDto.ChildId == 0)
     {
         var newChild = EntityMapper.DtoToChild(childDto);
         newChild.UserId = _currentUser.UserId;
         await _childRepository.CreateChildAsync(newChild);
         childDto.ChildId = newChild.ChildId;
         return childDto;
     }
     else
     {
         var child = await _childRepository.FindChildByIdAsync(childDto.ChildId);
         if (child == null)
         {
             throw new NotImplementedException();
         }
         if (child.UserId != _currentUser.UserId)
         {
             throw new NotImplementedException();
         }
         EntityMapper.DtoToChild(childDto, child);
         await _childRepository.SaveChangesAsync();
         return childDto;
     }
 }
Exemplo n.º 2
0
        public static Child DtoToChild(ChildDto childDto, Child child = null)
        {
            if (child == null)
            {
                child = new Child();
            }
            child.ChildId = childDto.ChildId;
            child.FirstName = childDto.FirstName;
            child.LastName = childDto.LastName;
            child.Surname = childDto.Surname;
            child.BirthDate = childDto.BirthDate;
            child.BirthTime = childDto.BirthTime;
            child.BirthPlace = childDto.BirthPlace;
            child.Sex = childDto.Sex;

            return child;
        }