116 lines
3.2 KiB
C#
116 lines
3.2 KiB
C#
// Import: Jan Conze / PBS2H23ACO mit Unterstützung durch Radu Catalin Calcan
|
|
|
|
using Core;
|
|
using System.Text;
|
|
|
|
namespace Projekt_Calcan_Conze_Import.Models;
|
|
|
|
internal class User
|
|
{
|
|
public User(
|
|
string title,
|
|
string firstName,
|
|
string lastName,
|
|
DateOnly dateOfBirth,
|
|
string? email,
|
|
Address? address,
|
|
List<PhoneNumber> phoneNumbers)
|
|
{
|
|
this.Title = title;
|
|
this.FirstName = firstName;
|
|
this.LastName = lastName;
|
|
this.DateOfBirth = dateOfBirth;
|
|
this.Email = email;
|
|
this.Address = address;
|
|
this.PhoneNumbers = phoneNumbers;
|
|
}
|
|
|
|
public string Title { get; }
|
|
|
|
public string FirstName { get; }
|
|
|
|
public string LastName { get; }
|
|
|
|
public DateOnly DateOfBirth { get; }
|
|
|
|
public string? Email { get; }
|
|
|
|
public Address? Address { get; }
|
|
|
|
public List<PhoneNumber> PhoneNumbers { get; }
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder builder = new();
|
|
|
|
builder.Append($"{this.Title} {this.FirstName} {this.LastName}");
|
|
builder.Append($"{Constants.Separator} {this.DateOfBirth.ToString(Constants.DateOfBirthFormat)}");
|
|
|
|
if (this.Email is not null)
|
|
{
|
|
builder.Append($"{Constants.Separator} {this.Email}");
|
|
}
|
|
|
|
if (this.Address is not null)
|
|
{
|
|
builder.Append($"{Constants.Separator} {this.Address.StreetAndHouseNumber}");
|
|
builder.Append($"{Constants.Separator} {this.Address.PostalCode} {this.Address.City}");
|
|
}
|
|
|
|
foreach (PhoneNumber phoneNumber in this.PhoneNumbers)
|
|
{
|
|
builder.Append($"{Constants.Separator} {phoneNumber.AreaCode} {phoneNumber.Number}");
|
|
}
|
|
|
|
return builder.ToString();
|
|
}
|
|
|
|
public IEnumerable<string> ToCsv()
|
|
{
|
|
List<string> csvLines =
|
|
[
|
|
this.Title
|
|
+ Constants.Separator
|
|
+ this.FirstName
|
|
+ Constants.Separator
|
|
+ this.LastName
|
|
+ Constants.Separator
|
|
+ this.DateOfBirth.ToString("dd.MM.yyyy")
|
|
];
|
|
|
|
if (this.Address is not null)
|
|
{
|
|
csvLines.Add(
|
|
Constants.AddressAttributeIdentifier
|
|
+ Constants.Separator
|
|
+ this.Address.StreetAndHouseNumber
|
|
+ Constants.Separator
|
|
+ this.Address.PostalCode
|
|
+ Constants.Separator
|
|
+ this.Address.City);
|
|
}
|
|
|
|
if (this.Email is not null)
|
|
{
|
|
csvLines.Add(
|
|
Constants.EmailAttributeIdentifier
|
|
+ Constants.Separator
|
|
+ this.Email
|
|
+ Constants.Separator
|
|
+ Constants.Separator);
|
|
}
|
|
|
|
csvLines.AddRange(
|
|
this.PhoneNumbers
|
|
.Select(
|
|
phoneNumber =>
|
|
Constants.PhoneNumberAttributeIdentifier
|
|
+ Constants.Separator
|
|
+ phoneNumber.AreaCode
|
|
+ Constants.Separator
|
|
+ phoneNumber.Number
|
|
+ Constants.Separator));
|
|
|
|
return csvLines;
|
|
}
|
|
} |