add supplier attributes
This commit is contained in:
54
AB.Services/Converter/CommunicationTypeConverter.cs
Normal file
54
AB.Services/Converter/CommunicationTypeConverter.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using AB.Contracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AB.Services.Converter;
|
||||
|
||||
internal class CommunicationTypeConverter
|
||||
{
|
||||
|
||||
public static CommunicationType ConvertFromBusinessValue
|
||||
(Domain.Enums.CommunicationType communicationType)
|
||||
{
|
||||
switch (communicationType)
|
||||
{
|
||||
case Domain.Enums.CommunicationType.Email:
|
||||
return CommunicationType.Email;
|
||||
case Domain.Enums.CommunicationType.Phone:
|
||||
return CommunicationType.Phone;
|
||||
case Domain.Enums.CommunicationType.Postal:
|
||||
return CommunicationType.Postal;
|
||||
case Domain.Enums.CommunicationType.Fax:
|
||||
return CommunicationType.Fax;
|
||||
default:
|
||||
var ex = new ArgumentException(
|
||||
$"Invalid Type of {nameof(Domain.Enums.CommunicationType)}: {communicationType}",
|
||||
nameof(communicationType));
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static Domain.Enums.CommunicationType ConvertToBusinessValue
|
||||
(CommunicationType communicationType)
|
||||
{
|
||||
switch (communicationType)
|
||||
{
|
||||
case CommunicationType.Email:
|
||||
return Domain.Enums.CommunicationType.Email;
|
||||
case CommunicationType.Postal:
|
||||
return Domain.Enums.CommunicationType.Postal;
|
||||
case CommunicationType.Fax:
|
||||
return Domain.Enums.CommunicationType.Fax;
|
||||
case CommunicationType.Phone:
|
||||
return Domain.Enums.CommunicationType.Phone;
|
||||
default:
|
||||
var ex = new ArgumentException(
|
||||
$"Invalid Type of {nameof(Domain.Enums.CommunicationType)}: {communicationType}",
|
||||
nameof(communicationType));
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
AB.Services/Converter/ContactPersonConverter.cs
Normal file
44
AB.Services/Converter/ContactPersonConverter.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using AB.Contracts;
|
||||
using AB.Domain.Entities;
|
||||
|
||||
namespace AB.Services.Converter;
|
||||
|
||||
internal static class ContactPersonConverter
|
||||
{
|
||||
|
||||
public static ContactPersonDto ConvertToDto(this ContactPerson contactPerson)
|
||||
{
|
||||
var dto = new ContactPersonDto
|
||||
{
|
||||
Salutation = contactPerson.Salutation,
|
||||
Name = contactPerson.Name,
|
||||
Email = contactPerson.Email,
|
||||
PhoneNumer = contactPerson.PhoneNumber,
|
||||
Notes = contactPerson.Notes,
|
||||
};
|
||||
return dto;
|
||||
}
|
||||
|
||||
public static ContactPerson ConvertToBusinessType(this ContactPersonDto dto)
|
||||
{
|
||||
var contactPerson = new ContactPerson
|
||||
{
|
||||
Salutation = dto.Salutation,
|
||||
Name = dto.Name,
|
||||
Email = dto.Email,
|
||||
PhoneNumber = dto.PhoneNumer,
|
||||
Notes = dto.Notes,
|
||||
};
|
||||
return contactPerson;
|
||||
}
|
||||
|
||||
public static List<ContactPerson> ConvertToContactPersonList(this IEnumerable<ContactPersonDto> contactPersons)
|
||||
{
|
||||
return contactPersons.Select(x => x.ConvertToBusinessType()).ToList();
|
||||
}
|
||||
|
||||
public static IEnumerable<ContactPersonDto> ConvertToContactPersonDtoList(this List<ContactPerson> contactPersons)
|
||||
{
|
||||
return contactPersons.Select(x => x.ConvertToDto());
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,7 @@ using AB.Domain.Entities;
|
||||
using AB.Domain.Exceptions;
|
||||
using AB.Domain.Repositories;
|
||||
using AB.Services.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AB.Services.Converter;
|
||||
|
||||
namespace AB.Services
|
||||
{
|
||||
@@ -28,7 +24,14 @@ namespace AB.Services
|
||||
{
|
||||
var supplier = new Supplier
|
||||
{
|
||||
|
||||
Salutation = supplierForCreation.Salutation,
|
||||
Name1 = supplierForCreation.Name1,
|
||||
Name2 = supplierForCreation.Name2,
|
||||
Email = supplierForCreation.Email,
|
||||
PhoneNumber = supplierForCreation.PhoneNumber,
|
||||
TaxId = supplierForCreation.TaxId,
|
||||
PreferredCommunication = CommunicationTypeConverter.ConvertToBusinessValue(supplierForCreation.PreferredCommunication),
|
||||
ContactPersons = supplierForCreation.ContactPersons.ConvertToContactPersonList(),
|
||||
};
|
||||
|
||||
_supplierRepository.Insert(supplier);
|
||||
@@ -80,8 +83,18 @@ namespace AB.Services
|
||||
var supplierDto = new SupplierDto
|
||||
{
|
||||
Id = supplier.SupplierId,
|
||||
Salutation = supplier.Salutation,
|
||||
Name1 = supplier.Name1,
|
||||
Name2 = supplier.Name2,
|
||||
Email = supplier.Email,
|
||||
PhoneNumber = supplier.PhoneNumber,
|
||||
TaxId = supplier.TaxId,
|
||||
PreferredCommunication = CommunicationTypeConverter.ConvertFromBusinessValue(supplier.PreferredCommunication),
|
||||
ContactPersons = supplier.ContactPersons.ConvertToContactPersonDtoList(),
|
||||
};
|
||||
return supplierDto;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user