added COA packages, added mapping profiles, updated creditor fields
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="10.0.0" />
|
||||
<PackageReference Include="DataObjects" Version="20.10.2.3-alpha" />
|
||||
<PackageReference Include="StructureMap" Version="4.7.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using COA.EnterpriseServices.DataAccess.Helpers;
|
||||
using AutoMapper;
|
||||
using COA.EnterpriseServices.DataAccess.Helpers;
|
||||
using StructureMap;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess
|
||||
@ -23,6 +24,8 @@ namespace COA.EnterpriseServices.DataAccess
|
||||
c.For(typeof(IDataAccess<>)).Singleton();
|
||||
c.For(typeof(DataAccessManager<>)).Singleton();
|
||||
|
||||
c.For<IMapper>().Singleton().Use(() => Mapping.GetMapper());
|
||||
|
||||
c.For<ClientHelper>().Singleton();
|
||||
c.For<CreditorHelper>().Singleton();
|
||||
});
|
||||
|
@ -12,5 +12,6 @@ namespace COA.EnterpriseServices.DataAccess.Entities
|
||||
public string ClientLastName { get; set; }
|
||||
public int CurrentCreditorProfileId { get; set; }
|
||||
public int OriginalCreditorProfileId { get; set; }
|
||||
public string AccountNumber { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,22 @@
|
||||
using COA.EnterpriseServices.DataAccess.Entities;
|
||||
using AutoMapper;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess.Helpers
|
||||
{
|
||||
public class ClientHelper
|
||||
{
|
||||
private readonly DataAccessManager<Client> clientDataAccess;
|
||||
private readonly DataAccessManager<Entities.Client> clientDataAccess;
|
||||
|
||||
public ClientHelper(DataAccessManager<Client> clientDataAccess)
|
||||
public ClientHelper(DataAccessManager<Entities.Client> clientDataAccess, IMapper mapper)
|
||||
{
|
||||
this.clientDataAccess = clientDataAccess;
|
||||
}
|
||||
|
||||
public ICollection<Client> FindByEmail(string email)
|
||||
public ICollection<Entities.Client> FindByEmail(string email)
|
||||
{
|
||||
return clientDataAccess.Get(c => c.Email.Equals(email));
|
||||
var client = clientDataAccess.Get(c => c.Email.Equals(email));
|
||||
|
||||
return client;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
using COA.EnterpriseServices.DataAccess.Entities;
|
||||
using System.Collections.Generic;
|
||||
using AutoMapper;
|
||||
using COA.EnterpriseServices.DataAccess.Entities;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess.Helpers
|
||||
{
|
||||
@ -7,16 +7,21 @@ namespace COA.EnterpriseServices.DataAccess.Helpers
|
||||
{
|
||||
private readonly DataAccessManager<Creditor> creditorDataAccess;
|
||||
private readonly DataAccessManager<SettlementAttempt> settlementAttemptDataAccess;
|
||||
private readonly IMapper mapper;
|
||||
|
||||
public CreditorHelper(DataAccessManager<Creditor> creditorDataAccess, DataAccessManager<SettlementAttempt> settlementAttemptDataAccess)
|
||||
public CreditorHelper(DataAccessManager<Creditor> creditorDataAccess, DataAccessManager<SettlementAttempt> settlementAttemptDataAccess, IMapper mapper)
|
||||
{
|
||||
this.creditorDataAccess = creditorDataAccess;
|
||||
this.settlementAttemptDataAccess = settlementAttemptDataAccess;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public Creditor GetCreditor(int id)
|
||||
public Creditors.Creditor GetCreditor(int id)
|
||||
{
|
||||
return creditorDataAccess.Get(id);
|
||||
var creditor = creditorDataAccess.Get(id);
|
||||
|
||||
// map EF => domain type
|
||||
return mapper.Map<Creditors.Creditor>(creditor);
|
||||
}
|
||||
|
||||
public SettlementAttempt GetSettlementAttempt(int id)
|
||||
@ -24,32 +29,18 @@ namespace COA.EnterpriseServices.DataAccess.Helpers
|
||||
return settlementAttemptDataAccess.Get(id);
|
||||
}
|
||||
|
||||
public ICollection<Creditor> FindByName(string name)
|
||||
public bool AddCreditor(Creditors.Creditor creditor)
|
||||
{
|
||||
// TODO: use AutoMapper to return mapped domain objects!
|
||||
var creditorEntity = mapper.Map<Creditor>(creditor);
|
||||
|
||||
return creditorDataAccess.Get(c => c.ClientFirstName.Contains(name) || c.ClientLastName.Contains(name));
|
||||
}
|
||||
|
||||
public ICollection<Creditor> FindByStatus(string status)
|
||||
{
|
||||
// TODO: use AutoMapper to return mapped domain objects!
|
||||
|
||||
return creditorDataAccess.Get(c => c.Status == status);
|
||||
}
|
||||
|
||||
public bool AddCreditor(Creditor creditor)
|
||||
{
|
||||
// TODO: use AutoMapper to pass in mapped domain object!
|
||||
|
||||
return creditorDataAccess.Add(creditor);
|
||||
return creditorDataAccess.Add(creditorEntity);
|
||||
}
|
||||
|
||||
public bool UpdateCreditor(Creditor creditor)
|
||||
{
|
||||
// TODO: use AutoMapper to pass in mapped domain object!
|
||||
var creditorEntity = mapper.Map<Creditor>(creditor);
|
||||
|
||||
return creditorDataAccess.Update(creditor);
|
||||
return creditorDataAccess.Update(creditorEntity);
|
||||
}
|
||||
|
||||
public bool SetCreditorStatus(int creditorId, string status)
|
||||
|
20
COA.EnterpriseServices.DataAccess/Mapping.cs
Normal file
20
COA.EnterpriseServices.DataAccess/Mapping.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using AutoMapper;
|
||||
using AutoMapper.Configuration;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess
|
||||
{
|
||||
public static class Mapping
|
||||
{
|
||||
public static IMapper GetMapper()
|
||||
{
|
||||
var cfg = new MapperConfigurationExpression();
|
||||
cfg.AddProfile<MappingProfile>();
|
||||
|
||||
//Mapper.Initialize(cfg);
|
||||
// or
|
||||
var mapperConfig = new MapperConfiguration(cfg);
|
||||
|
||||
return new Mapper(mapperConfig);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using AutoMapper;
|
||||
using COA.EnterpriseServices.Creditors;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess
|
||||
{
|
||||
@ -6,7 +7,23 @@ namespace COA.EnterpriseServices.DataAccess
|
||||
{
|
||||
public MappingProfile()
|
||||
{
|
||||
// add mappings between domain and entity objects here
|
||||
#region EF => Domain
|
||||
|
||||
CreateMap<Entities.Creditor, Creditor>()
|
||||
.ForMember(d => d.creditorStatus, o => o.MapFrom(s => s.Status));
|
||||
|
||||
CreateMap<Entities.Client, Client.Client>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Domain => EF
|
||||
|
||||
CreateMap<Creditor, Entities.Creditor>()
|
||||
.ForMember(d => d.Status, o => o.MapFrom(s => s.creditorStatus));
|
||||
|
||||
CreateMap<Client.Client, Entities.Client>();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user