aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services/Services/TechnologyService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/DevHive.Services/Services/TechnologyService.cs')
-rw-r--r--src/DevHive.Services/Services/TechnologyService.cs32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs
index d8b7262..88ed702 100644
--- a/src/DevHive.Services/Services/TechnologyService.cs
+++ b/src/DevHive.Services/Services/TechnologyService.cs
@@ -20,24 +20,28 @@ namespace DevHive.Services.Services
}
#region Create
-
- public async Task<bool> Create(CreateTechnologyServiceModel technologyServiceModel)
+ public async Task<Guid> Create(CreateTechnologyServiceModel technologyServiceModel)
{
if (await this._technologyRepository.DoesTechnologyNameExistAsync(technologyServiceModel.Name))
throw new ArgumentException("Technology already exists!");
Technology technology = this._technologyMapper.Map<Technology>(technologyServiceModel);
- bool result = await this._technologyRepository.AddAsync(technology);
-
- return result;
+ bool success = await this._technologyRepository.AddAsync(technology);
+
+ if (success)
+ {
+ Technology newTechnology = await this._technologyRepository.GetByNameAsync(technologyServiceModel.Name);
+ return newTechnology.Id;
+ }
+ else
+ return Guid.Empty;
}
#endregion
#region Read
-
- public async Task<CreateTechnologyServiceModel> GetTechnologyById(Guid technologyId)
+ public async Task<CreateTechnologyServiceModel> GetTechnologyById(Guid id)
{
- Technology technology = await this._technologyRepository.GetByIdAsync(technologyId);
+ Technology technology = await this._technologyRepository.GetByIdAsync(id);
if (technology == null)
throw new ArgumentException("The technology does not exist");
@@ -47,16 +51,14 @@ namespace DevHive.Services.Services
#endregion
#region Update
-
- public async Task<bool> UpdateTechnology(Guid technologyId, UpdateTechnologyServiceModel updateTechnologyServiceModel)
+ public async Task<bool> UpdateTechnology(UpdateTechnologyServiceModel updateTechnologyServiceModel)
{
- if (!await this._technologyRepository.DoesTechnologyExistAsync(technologyId))
+ if (!await this._technologyRepository.DoesTechnologyExistAsync(updateTechnologyServiceModel.Id))
throw new ArgumentException("Technology does not exist!");
if (await this._technologyRepository.DoesTechnologyNameExistAsync(updateTechnologyServiceModel.Name))
throw new ArgumentException("Technology name already exists!");
- updateTechnologyServiceModel.Id = technologyId;
Technology technology = this._technologyMapper.Map<Technology>(updateTechnologyServiceModel);
bool result = await this._technologyRepository.EditAsync(technology);
@@ -65,12 +67,12 @@ namespace DevHive.Services.Services
#endregion
#region Delete
- public async Task<bool> DeleteTechnology(Guid technologyId)
+ public async Task<bool> DeleteTechnology(Guid id)
{
- if (!await this._technologyRepository.DoesTechnologyExistAsync(technologyId))
+ if (!await this._technologyRepository.DoesTechnologyExistAsync(id))
throw new ArgumentException("Technology does not exist!");
- Technology technology = await this._technologyRepository.GetByIdAsync(technologyId);
+ Technology technology = await this._technologyRepository.GetByIdAsync(id);
bool result = await this._technologyRepository.DeleteAsync(technology);
return result;