aboutsummaryrefslogtreecommitdiffstats
path: root/Software
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-08-06 12:51:10 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-08-06 12:51:10 +0300
commit265e4bcf4b21b2317a88171b3326f65e58515d9c (patch)
treeac41d914f2d0643265afcec2f48b7930cd24124a /Software
parente86fe2e8cf34343cf3ebbf4640b2be5e85899615 (diff)
downloadTango-265e4bcf4b21b2317a88171b3326f65e58515d9c.tar.gz
Tango-265e4bcf4b21b2317a88171b3326f65e58515d9c.zip
v2 Added Contact,Address
Added Indices...
Diffstat (limited to 'Software')
-rw-r--r--Software/Visual_Studio_v2/Tango.BLL/IMapper.cs15
-rw-r--r--Software/Visual_Studio_v2/Tango.BLL/Mappers/AddressToAddressModelMapper.cs45
-rw-r--r--Software/Visual_Studio_v2/Tango.BLL/Mappers/ContactToContactModelMapper.cs44
-rw-r--r--Software/Visual_Studio_v2/Tango.BLL/Mappers/OrganizationToOrganizationEntityMapper.cs39
-rw-r--r--Software/Visual_Studio_v2/Tango.BLL/Objects/Address.cs16
-rw-r--r--Software/Visual_Studio_v2/Tango.BLL/Objects/Contact.cs15
-rw-r--r--Software/Visual_Studio_v2/Tango.BLL/Objects/Organization.cs8
-rw-r--r--Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs14
-rw-r--r--Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoIndex.cs17
-rw-r--r--Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoRepository.cs24
-rw-r--r--Software/Visual_Studio_v2/Tango.DAL.Mongo/Tango.DAL.Mongo.csproj1
-rw-r--r--Software/Visual_Studio_v2/Tango.DAL/Attributes/CollectionAttribute.cs (renamed from Software/Visual_Studio_v2/Tango.DAL/Attributes/MongoCollectionAttribute.cs)6
-rw-r--r--Software/Visual_Studio_v2/Tango.DAL/Attributes/UniqueAttribute.cs12
-rw-r--r--Software/Visual_Studio_v2/Tango.DAL/Entities/OrganizationEntity.cs15
-rw-r--r--Software/Visual_Studio_v2/Tango.DAL/Models/AddressModel.cs16
-rw-r--r--Software/Visual_Studio_v2/Tango.DAL/Models/ContactModel.cs16
-rw-r--r--Software/Visual_Studio_v2/Tango.UnitTests/DAL/Mongo.cs8
-rw-r--r--Software/Visual_Studio_v2/Tango.UnitTests/Tango.UnitTests.csproj3
-rw-r--r--Software/Visual_Studio_v2/Tango.UnitTests/packages.config1
19 files changed, 299 insertions, 16 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;
}
diff --git a/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoIndex.cs b/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoIndex.cs
new file mode 100644
index 000000000..c98543dd2
--- /dev/null
+++ b/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoIndex.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Tango.DAL.Mongo
+{
+ public class MongoIndex
+ {
+ public int v { get; set; }
+
+ public string name { get; set; }
+
+ public string ns { get; set; }
+
+ public Dictionary<object, object> key { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoRepository.cs b/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoRepository.cs
index d268f434d..864bb17cc 100644
--- a/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoRepository.cs
+++ b/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoRepository.cs
@@ -6,6 +6,8 @@ using System.Reflection;
using Tango.DAL.Attributes;
using System.Linq.Expressions;
using MongoDB.Driver.Linq;
+using System.Linq;
+using Newtonsoft.Json;
namespace Tango.DAL.Mongo
{
@@ -25,7 +27,27 @@ namespace Tango.DAL.Mongo
{
if (_collection == null)
{
- _collection = _database.GetCollection<T>(typeof(T).GetCustomAttribute<MongoCollectionAttribute>().Name);
+ _collection = _database.GetCollection<T>(typeof(T).GetCustomAttribute<CollectionAttribute>().Name);
+
+ foreach (var prop in typeof(T).GetProperties())
+ {
+ if (prop.GetCustomAttribute<UniqueAttribute>() != null)
+ {
+ var indices = _collection.Indexes.List().ToList().Select(x => JsonConvert.DeserializeObject<MongoIndex>(x.ToString())).ToList();
+
+ if (!indices.Exists(x => x.name == prop.Name))
+ {
+ var builder = Builders<T>.IndexKeys;
+ var indexModel = new CreateIndexModel<T>(builder.Ascending(prop.Name), new CreateIndexOptions()
+ {
+ Unique = true,
+ Name = prop.Name,
+ });
+
+ _collection.Indexes.CreateOne(indexModel);
+ }
+ }
+ }
}
return _collection;
diff --git a/Software/Visual_Studio_v2/Tango.DAL.Mongo/Tango.DAL.Mongo.csproj b/Software/Visual_Studio_v2/Tango.DAL.Mongo/Tango.DAL.Mongo.csproj
index 7f0e7a2f0..a2f036e9d 100644
--- a/Software/Visual_Studio_v2/Tango.DAL.Mongo/Tango.DAL.Mongo.csproj
+++ b/Software/Visual_Studio_v2/Tango.DAL.Mongo/Tango.DAL.Mongo.csproj
@@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.8.1" />
+ <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>
<ItemGroup>
diff --git a/Software/Visual_Studio_v2/Tango.DAL/Attributes/MongoCollectionAttribute.cs b/Software/Visual_Studio_v2/Tango.DAL/Attributes/CollectionAttribute.cs
index 50b585698..0de137c21 100644
--- a/Software/Visual_Studio_v2/Tango.DAL/Attributes/MongoCollectionAttribute.cs
+++ b/Software/Visual_Studio_v2/Tango.DAL/Attributes/CollectionAttribute.cs
@@ -5,11 +5,11 @@ using System.Text;
namespace Tango.DAL.Attributes
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
- public class MongoCollectionAttribute : Attribute
+ public class CollectionAttribute : Attribute
{
- public String Name { get; set; }
+ public string Name { get; set; }
- public MongoCollectionAttribute(String name)
+ public CollectionAttribute(string name)
{
Name = name;
}
diff --git a/Software/Visual_Studio_v2/Tango.DAL/Attributes/UniqueAttribute.cs b/Software/Visual_Studio_v2/Tango.DAL/Attributes/UniqueAttribute.cs
new file mode 100644
index 000000000..eb8576e51
--- /dev/null
+++ b/Software/Visual_Studio_v2/Tango.DAL/Attributes/UniqueAttribute.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Tango.DAL.Attributes
+{
+ [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
+ public class UniqueAttribute : Attribute
+ {
+
+ }
+}
diff --git a/Software/Visual_Studio_v2/Tango.DAL/Entities/OrganizationEntity.cs b/Software/Visual_Studio_v2/Tango.DAL/Entities/OrganizationEntity.cs
index b17cd34c9..5d4a419ba 100644
--- a/Software/Visual_Studio_v2/Tango.DAL/Entities/OrganizationEntity.cs
+++ b/Software/Visual_Studio_v2/Tango.DAL/Entities/OrganizationEntity.cs
@@ -1,11 +1,22 @@
-using System;
+using MongoDB.Bson.Serialization.Attributes;
+using System;
using Tango.DAL.Attributes;
+using Tango.DAL.Models;
namespace Tango.DAL.Entities
{
- [MongoCollection("Organizations")]
+ [Collection("Organizations")]
public class OrganizationEntity : Entity
{
+ [Unique]
public string Name { get; set; }
+ public ContactModel Contact { get; set; }
+ public AddressModel Address { get; set; }
+
+ public OrganizationEntity()
+ {
+ Contact = new ContactModel();
+ Address = new AddressModel();
+ }
}
}
diff --git a/Software/Visual_Studio_v2/Tango.DAL/Models/AddressModel.cs b/Software/Visual_Studio_v2/Tango.DAL/Models/AddressModel.cs
new file mode 100644
index 000000000..58b8584bb
--- /dev/null
+++ b/Software/Visual_Studio_v2/Tango.DAL/Models/AddressModel.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Tango.DAL.Models
+{
+ public class AddressModel
+ {
+ 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.DAL/Models/ContactModel.cs b/Software/Visual_Studio_v2/Tango.DAL/Models/ContactModel.cs
new file mode 100644
index 000000000..3b986c826
--- /dev/null
+++ b/Software/Visual_Studio_v2/Tango.DAL/Models/ContactModel.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Tango.DAL.Models
+{
+ public class ContactModel
+ {
+ public string FirstName { get; set; }
+ public string LastName { get; set; }
+ public string FullName { 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.UnitTests/DAL/Mongo.cs b/Software/Visual_Studio_v2/Tango.UnitTests/DAL/Mongo.cs
index 8a2314858..d15b1c7a9 100644
--- a/Software/Visual_Studio_v2/Tango.UnitTests/DAL/Mongo.cs
+++ b/Software/Visual_Studio_v2/Tango.UnitTests/DAL/Mongo.cs
@@ -25,6 +25,14 @@ namespace Tango.UnitTests.DAL
repo.Insert(org1).GetAwaiter().GetResult();
+ OrganizationEntity orgDuplicate = new OrganizationEntity();
+ orgDuplicate.Name = org1.Name;
+
+ Assert.ThrowsException<MongoDB.Driver.MongoWriteException>(() =>
+ {
+ repo.Insert(orgDuplicate).GetAwaiter().GetResult();
+ });
+
Assert.IsNotNull(org1.ID);
var org2 = repo.GetAsync(x => x.ID == org1.ID).GetAwaiter().GetResult().FirstOrDefault();
diff --git a/Software/Visual_Studio_v2/Tango.UnitTests/Tango.UnitTests.csproj b/Software/Visual_Studio_v2/Tango.UnitTests/Tango.UnitTests.csproj
index bcdb3c11f..e79ce12ae 100644
--- a/Software/Visual_Studio_v2/Tango.UnitTests/Tango.UnitTests.csproj
+++ b/Software/Visual_Studio_v2/Tango.UnitTests/Tango.UnitTests.csproj
@@ -57,6 +57,9 @@
<Reference Include="MongoDB.Driver.Core, Version=2.8.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Driver.Core.2.8.1\lib\net452\MongoDB.Driver.Core.dll</HintPath>
</Reference>
+ <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
diff --git a/Software/Visual_Studio_v2/Tango.UnitTests/packages.config b/Software/Visual_Studio_v2/Tango.UnitTests/packages.config
index 9852f98c8..e5905a49c 100644
--- a/Software/Visual_Studio_v2/Tango.UnitTests/packages.config
+++ b/Software/Visual_Studio_v2/Tango.UnitTests/packages.config
@@ -6,6 +6,7 @@
<package id="MongoDB.Driver.Core" version="2.8.1" targetFramework="net461" />
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net461" />
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net461" />
+ <package id="Newtonsoft.Json" version="12.0.2" targetFramework="net461" />
<package id="System.Buffers" version="4.4.0" targetFramework="net461" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
</packages> \ No newline at end of file