aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs')
-rw-r--r--Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs44
1 files changed, 41 insertions, 3 deletions
diff --git a/Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs b/Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs
index c18c57eba..a502849e3 100644
--- a/Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs
+++ b/Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs
@@ -13,21 +13,59 @@ namespace Tango.BLL.Services
public class OrganizationsService : ServiceBase<Organization>
{
private IRepository<OrganizationEntity> _repository;
+ private OrganizationToOrganizationEntityMapper _mapper;
public OrganizationsService(IRepository<OrganizationEntity> repository)
{
_repository = repository;
+ _mapper = new OrganizationToOrganizationEntityMapper();
}
public async Task<List<Organization>> GetAllOrganizations()
{
var entities = await _repository.GetAllAsync();
- OrganizationToOrganizationEntityMapper mapper = new OrganizationToOrganizationEntityMapper();
-
- var organizations = entities.Select(x => mapper.Create(x)).ToList();
+ var organizations = entities.Select(x => _mapper.Create(x)).ToList();
return organizations;
}
+
+ public Task<long> DeleteAllOrganizations()
+ {
+ return _repository.DeleteAsync(x => true);
+ }
+
+ public async Task<Organization> AddOrganization(Organization organization)
+ {
+ OrganizationEntity entity = _mapper.Create(organization);
+
+ entity = await _repository.Insert(entity);
+
+ _mapper.Map(entity, organization);
+
+ return organization;
+ }
+
+ public async Task<Organization> GetOrganizationByID(String id)
+ {
+ var entity = (await _repository.GetAsync(x => x.ID == id)).ToList().SingleOrDefault();
+
+ if (entity == null)
+ {
+ throw new KeyNotFoundException($"Could not find organization with id {id}.");
+ }
+
+ return _mapper.Create(entity);
+ }
+
+ public async Task<long> DeleteOrganizationByID(String id)
+ {
+ return await _repository.DeleteAsync(x => x.ID == id);
+ }
+
+ public async Task<long> Count()
+ {
+ return await _repository.Count();
+ }
}
}