public static PrivateUserDTO PrivateUserDTO(User user)
 {
     return(new PrivateUserDTO()
     {
         Id = user.Id,
         Name = user.Name,
         Address = DTOConverter.PrivateAddressDTO(user.Address),
         Accounts = user.Accounts
                    .ToList()
                    .ConvertAll(new Converter <Account, PrivateAccountDTO>(DTOConverter.PrivateAccountDTO))
     });
 }
 public static AdminUserDTO AdminUserDTO(User user)
 {
     return(new AdminUserDTO()
     {
         Id = user.Id,
         Name = user.Name,
         Address = DTOConverter.AdminAddressDTO(user.Address),
         DateOfBirth = user.DateOfBirth,
         Email = user.Email,
         Accounts = user.Accounts
                    .ToList()
                    .ConvertAll(new Converter <Account, AdminAccountDTO>(DTOConverter.AdminAccountDTO))
     });
 }
        public static User UserFromDTO(object dto)
        {
            switch (dto)
            {
            case AdminUserDTO adminDto:
            {
                return(new User()
                    {
                        Id = adminDto.Id,
                        Name = adminDto.Name,
                        Email = adminDto.Email,
                        DateOfBirth = adminDto.DateOfBirth,
                        // setting the navigation properties like this is almost certainly wrong!
                        // the proper way is something like in Mladen's code and only for single objects
                        // collections should never be changed from the navigation property if you don't want trouble...
                        Address = DTOConverter.AddressFromDTO(adminDto.Address),
                        Accounts = adminDto.Accounts
                                   .ToList()
                                   .ConvertAll(new Converter <AdminAccountDTO, Account>(DTOConverter.AccountFromDTO))
                    });
            }

            case PrivateUserDTO privDto:
            {
                return(new User()
                    {
                        Id = privDto.Id,
                        Name = privDto.Name,
                        Accounts = privDto.Accounts
                                   .ToList()
                                   .ConvertAll(new Converter <PrivateAccountDTO, Account>(DTOConverter.AccountFromDTO)),
                        Address = DTOConverter.AddressFromDTO(privDto.Address)
                    });
            }

            default: return(null);
            }
        }