add supplier attributes
This commit is contained in:
parent
9cb007399a
commit
73bfcccc9c
@ -21,6 +21,9 @@ builder.Services.AddSwaggerGen(c => c.SwaggerDoc("v1", new OpenApiInfo { Title =
|
|||||||
builder.Services.AddScoped<ICustomerService, CustomerService>();
|
builder.Services.AddScoped<ICustomerService, CustomerService>();
|
||||||
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
|
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
|
||||||
|
|
||||||
|
builder.Services.AddScoped<ISupplierService, SupplierService>();
|
||||||
|
builder.Services.AddScoped<ISupplierRepository, SupplierRepository>();
|
||||||
|
|
||||||
builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
|
builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
|
||||||
|
|
||||||
builder.Services.AddDbContextPool<RepoDbContext>(builder =>
|
builder.Services.AddDbContextPool<RepoDbContext>(builder =>
|
||||||
|
@ -11,6 +11,11 @@ public class SupplierController : ControllerBase
|
|||||||
|
|
||||||
public readonly ISupplierService _supplierService;
|
public readonly ISupplierService _supplierService;
|
||||||
|
|
||||||
|
public SupplierController(ISupplierService supplierService)
|
||||||
|
{
|
||||||
|
_supplierService = supplierService;
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<ActionResult<IEnumerable<SupplierDto>>> GetSupplieres(CancellationToken cancellationToken)
|
public async Task<ActionResult<IEnumerable<SupplierDto>>> GetSupplieres(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
19
AB.Contracts/CommunicationType.cs
Normal file
19
AB.Contracts/CommunicationType.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace AB.Contracts
|
||||||
|
{
|
||||||
|
public enum CommunicationType
|
||||||
|
{
|
||||||
|
[EnumMember(Value = "Email")]
|
||||||
|
Email,
|
||||||
|
|
||||||
|
[EnumMember(Value = "Postal")]
|
||||||
|
Postal,
|
||||||
|
|
||||||
|
[EnumMember(Value = "Phone")]
|
||||||
|
Phone,
|
||||||
|
|
||||||
|
[EnumMember(Value = "Fax")]
|
||||||
|
Fax
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace AB.Contracts;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AB.Contracts;
|
|
||||||
|
|
||||||
public class ContactPersonDto
|
public class ContactPersonDto
|
||||||
{
|
{
|
||||||
@ -17,5 +11,6 @@ public class ContactPersonDto
|
|||||||
|
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
public string Notes { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AB.Contracts
|
|
||||||
{
|
|
||||||
public enum PreferredCommunicationType
|
|
||||||
{
|
|
||||||
[EnumMember(Value = "Email")]
|
|
||||||
Email,
|
|
||||||
|
|
||||||
[EnumMember(Value = "Postal")]
|
|
||||||
Postal,
|
|
||||||
|
|
||||||
[EnumMember(Value = "Phone")]
|
|
||||||
Phone,
|
|
||||||
|
|
||||||
[EnumMember(Value = "Phone")]
|
|
||||||
Fax
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,4 @@
|
|||||||
using System;
|
using System.Runtime.Serialization;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AB.Contracts;
|
namespace AB.Contracts;
|
||||||
|
|
||||||
@ -11,4 +7,21 @@ public class SupplierDto
|
|||||||
|
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public string Salutation { get; set; }
|
||||||
|
|
||||||
|
public string Name1 { get; set; }
|
||||||
|
|
||||||
|
public string Name2 { get; set; }
|
||||||
|
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
public string PhoneNumber { get; set; }
|
||||||
|
|
||||||
|
public string TaxId { get; set; }
|
||||||
|
|
||||||
|
[DataMember(Name = "PreferredCommunication", EmitDefaultValue = true)]
|
||||||
|
public CommunicationType PreferredCommunication { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<ContactPersonDto> ContactPersons { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ public class SupplierForCreationDto
|
|||||||
public string TaxId { get; set; }
|
public string TaxId { get; set; }
|
||||||
|
|
||||||
[DataMember(Name = "PreferredCommunication", EmitDefaultValue = true)]
|
[DataMember(Name = "PreferredCommunication", EmitDefaultValue = true)]
|
||||||
public PreferredCommunicationType PreferredCommunication { get; set; }
|
public CommunicationType PreferredCommunication { get; set; }
|
||||||
|
|
||||||
public IEnumerable<ContactPersonDto> ContactPersons { get; set; }
|
public IEnumerable<ContactPersonDto> ContactPersons { get; set; }
|
||||||
|
|
||||||
|
11
AB.Domain/Entities/CommunicationType.cs
Normal file
11
AB.Domain/Entities/CommunicationType.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace AB.Domain.Enums
|
||||||
|
{
|
||||||
|
public enum CommunicationType
|
||||||
|
{
|
||||||
|
Email,
|
||||||
|
Postal,
|
||||||
|
Phone,
|
||||||
|
Fax
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
20
AB.Domain/Entities/ContactPerson.cs
Normal file
20
AB.Domain/Entities/ContactPerson.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
namespace AB.Domain.Entities;
|
||||||
|
|
||||||
|
public class ContactPerson
|
||||||
|
{
|
||||||
|
|
||||||
|
public Guid ContactPersonId { get; set; }
|
||||||
|
|
||||||
|
public Guid SupplierId { get; set; }
|
||||||
|
|
||||||
|
public string Salutation { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public string PhoneNumber { get; set; }
|
||||||
|
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
public string Notes { get; set; }
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using AB.Domain.Enums;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -10,4 +11,20 @@ public class Supplier
|
|||||||
{
|
{
|
||||||
|
|
||||||
public Guid SupplierId { get; set; }
|
public Guid SupplierId { get; set; }
|
||||||
|
|
||||||
|
public string Salutation { get; set; }
|
||||||
|
|
||||||
|
public string Name1 { get; set; }
|
||||||
|
|
||||||
|
public string Name2 { get; set; }
|
||||||
|
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
public string PhoneNumber { get; set; }
|
||||||
|
|
||||||
|
public string TaxId { get; set; }
|
||||||
|
|
||||||
|
public CommunicationType PreferredCommunication { get; set; }
|
||||||
|
|
||||||
|
public List<ContactPerson> ContactPersons { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ public sealed class RepoDbContext : DbContext
|
|||||||
|
|
||||||
public DbSet<Supplier> Suppliers { get; set; }
|
public DbSet<Supplier> Suppliers { get; set; }
|
||||||
|
|
||||||
|
public DbSet<ContactPerson> ContactPersons { get; set; }
|
||||||
|
|
||||||
public DbSet<Product> Products { get; set; }
|
public DbSet<Product> Products { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,12 @@ public class SupplierRepository : ISupplierRepository
|
|||||||
|
|
||||||
public async Task<IEnumerable<Supplier>> GetAllAsync(CancellationToken cancellationToken)
|
public async Task<IEnumerable<Supplier>> GetAllAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return await _dbContext.Suppliers.ToListAsync(cancellationToken);
|
return await _dbContext.Suppliers.Include(x => x.ContactPersons).ToListAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Supplier> GetByIdAsync(Guid supplierId, CancellationToken cancellationToken)
|
public async Task<Supplier> GetByIdAsync(Guid supplierId, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return await _dbContext.Suppliers.FirstOrDefaultAsync(x => x.SupplierId == supplierId, cancellationToken);
|
return await _dbContext.Suppliers.Include(x => x.ContactPersons).FirstOrDefaultAsync(x => x.SupplierId == supplierId, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Insert(Supplier supplier)
|
public void Insert(Supplier supplier)
|
||||||
|
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.Exceptions;
|
||||||
using AB.Domain.Repositories;
|
using AB.Domain.Repositories;
|
||||||
using AB.Services.Abstractions;
|
using AB.Services.Abstractions;
|
||||||
using System;
|
using AB.Services.Converter;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AB.Services
|
namespace AB.Services
|
||||||
{
|
{
|
||||||
@ -28,7 +24,14 @@ namespace AB.Services
|
|||||||
{
|
{
|
||||||
var supplier = new Supplier
|
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);
|
_supplierRepository.Insert(supplier);
|
||||||
@ -80,8 +83,18 @@ namespace AB.Services
|
|||||||
var supplierDto = new SupplierDto
|
var supplierDto = new SupplierDto
|
||||||
{
|
{
|
||||||
Id = supplier.SupplierId,
|
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;
|
return supplierDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user