diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-08-06 12:51:10 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-08-06 12:51:10 +0300 |
| commit | 265e4bcf4b21b2317a88171b3326f65e58515d9c (patch) | |
| tree | ac41d914f2d0643265afcec2f48b7930cd24124a /Software/Visual_Studio_v2/Tango.BLL | |
| parent | e86fe2e8cf34343cf3ebbf4640b2be5e85899615 (diff) | |
| download | Tango-265e4bcf4b21b2317a88171b3326f65e58515d9c.tar.gz Tango-265e4bcf4b21b2317a88171b3326f65e58515d9c.zip | |
v2 Added Contact,Address
Added Indices...
Diffstat (limited to 'Software/Visual_Studio_v2/Tango.BLL')
8 files changed, 186 insertions, 10 deletions
diff --git a/Software/Visual_Studio_v2/Tango.BLL/IMapper.cs b/Software/Visual_Studio_v2/Tango.BLL/IMapper.cs new file mode 100644 index 000000000..cb4a85e3d --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.BLL/IMapper.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Tango.DAL; + +namespace Tango.BLL +{ + public interface IMapper<T1, T2> where T1 : class where T2 : class + { + void Map(T1 source, T2 target); + void Map(T2 source, T1 target); + T2 Create(T1 source); + T1 Create(T2 source); + } +} diff --git a/Software/Visual_Studio_v2/Tango.BLL/Mappers/AddressToAddressModelMapper.cs b/Software/Visual_Studio_v2/Tango.BLL/Mappers/AddressToAddressModelMapper.cs new file mode 100644 index 000000000..0811a3c73 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.BLL/Mappers/AddressToAddressModelMapper.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Tango.BLL.Objects; +using Tango.DAL.Models; + +namespace Tango.BLL.Mappers +{ + public class AddressToAddressModelMapper : IMapper<Address, AddressModel> + { + public void Map(Address source, AddressModel target) + { + target.AddressString = source.AddressString; + target.City = source.City; + target.CountryCode = source.CountryCode; + target.Locality = source.Locality; + target.PostalCode = source.PostalCode; + target.State = source.State; + } + + public void Map(AddressModel source, Address target) + { + target.AddressString = source.AddressString; + target.City = source.City; + target.CountryCode = source.CountryCode; + target.Locality = source.Locality; + target.PostalCode = source.PostalCode; + target.State = source.State; + } + + public AddressModel Create(Address source) + { + var model = new AddressModel(); + Map(source, model); + return model; + } + + public Address Create(AddressModel source) + { + Address address = new Address(); + Map(source, address); + return address; + } + } +} diff --git a/Software/Visual_Studio_v2/Tango.BLL/Mappers/ContactToContactModelMapper.cs b/Software/Visual_Studio_v2/Tango.BLL/Mappers/ContactToContactModelMapper.cs new file mode 100644 index 000000000..caf1b70de --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.BLL/Mappers/ContactToContactModelMapper.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Tango.BLL.Objects; +using Tango.DAL.Models; + +namespace Tango.BLL.Mappers +{ + public class ContactToContactModelMapper : IMapper<Contact,ContactModel> + { + public void Map(Contact source, ContactModel target) + { + target.Email = source.Email; + target.Fax = source.Fax; + target.FirstName = source.FirstName; + target.FullName = source.FirstName + " " + source.LastName; + target.LastName = source.LastName; + target.PhoneNumber = source.PhoneNumber; + } + + public void Map(ContactModel source, Contact target) + { + target.Email = source.Email; + target.Fax = source.Fax; + target.FirstName = source.FirstName; + target.LastName = source.LastName; + target.PhoneNumber = source.PhoneNumber; + } + + public ContactModel Create(Contact source) + { + ContactModel model = new ContactModel(); + Map(source, model); + return model; + } + + public Contact Create(ContactModel source) + { + Contact contact = new Contact(); + Map(source, contact); + return contact; + } + } +} diff --git a/Software/Visual_Studio_v2/Tango.BLL/Mappers/OrganizationToOrganizationEntityMapper.cs b/Software/Visual_Studio_v2/Tango.BLL/Mappers/OrganizationToOrganizationEntityMapper.cs new file mode 100644 index 000000000..741b2f0e8 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.BLL/Mappers/OrganizationToOrganizationEntityMapper.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Tango.BLL.Objects; +using Tango.DAL.Entities; + +namespace Tango.BLL.Mappers +{ + public class OrganizationToOrganizationEntityMapper : IMapper<Organization, OrganizationEntity> + { + public void Map(Organization source, OrganizationEntity target) + { + target.ID = source.ID; + new AddressToAddressModelMapper().Map(source.Address, target.Address); + new ContactToContactModelMapper().Map(source.Contact, target.Contact); + } + + public void Map(OrganizationEntity source, Organization target) + { + target.ID = source.ID; + new AddressToAddressModelMapper().Map(source.Address, target.Address); + new ContactToContactModelMapper().Map(source.Contact, target.Contact); + } + + public OrganizationEntity Create(Organization source) + { + OrganizationEntity entity = new OrganizationEntity(); + Map(source, entity); + return entity; + } + + public Organization Create(OrganizationEntity source) + { + Organization organization = new Organization(); + Map(source, organization); + return organization; + } + } +} diff --git a/Software/Visual_Studio_v2/Tango.BLL/Objects/Address.cs b/Software/Visual_Studio_v2/Tango.BLL/Objects/Address.cs new file mode 100644 index 000000000..90787402c --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.BLL/Objects/Address.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tango.BLL.Objects +{ + public class Address : ObjectBase + { + public string AddressString { get; set; } + public string Locality { get; set; } + public string City { get; set; } + public string State { get; set; } + public string CountryCode { get; set; } + public string PostalCode { get; set; } + } +} diff --git a/Software/Visual_Studio_v2/Tango.BLL/Objects/Contact.cs b/Software/Visual_Studio_v2/Tango.BLL/Objects/Contact.cs new file mode 100644 index 000000000..e360fbdb1 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.BLL/Objects/Contact.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tango.BLL.Objects +{ + public class Contact : ObjectBase + { + public string FirstName { get; set; } + public string LastName { get; set; } + public string Email { get; set; } + public string PhoneNumber { get; set; } + public string Fax { get; set; } + } +} diff --git a/Software/Visual_Studio_v2/Tango.BLL/Objects/Organization.cs b/Software/Visual_Studio_v2/Tango.BLL/Objects/Organization.cs index 3750fb909..7f60ad3a8 100644 --- a/Software/Visual_Studio_v2/Tango.BLL/Objects/Organization.cs +++ b/Software/Visual_Studio_v2/Tango.BLL/Objects/Organization.cs @@ -8,5 +8,13 @@ namespace Tango.BLL.Objects { public string ID { get; set; } public string Name { get; set; } + public Address Address { get; set; } + public Contact Contact { get; set; } + + public Organization() + { + Address = new Address(); + Contact = new Contact(); + } } } diff --git a/Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs b/Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs index a65952846..c18c57eba 100644 --- a/Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs +++ b/Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs @@ -6,6 +6,7 @@ using Tango.BLL.Objects; using Tango.DAL; using Tango.DAL.Entities; using System.Linq; +using Tango.BLL.Mappers; namespace Tango.BLL.Services { @@ -18,20 +19,13 @@ namespace Tango.BLL.Services _repository = repository; } - public async Task<List<Organization>> GetAll() + public async Task<List<Organization>> GetAllOrganizations() { var entities = await _repository.GetAllAsync(); - List<Organization> organizations = new List<Organization>(); + OrganizationToOrganizationEntityMapper mapper = new OrganizationToOrganizationEntityMapper(); - foreach (var entity in entities) - { - Organization organization = new Organization(); - organization.ID = entity.ID; - organization.Name = entity.Name; - - organizations.Add(organization); - } + var organizations = entities.Select(x => mapper.Create(x)).ToList(); return organizations; } |
