aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services/Services/TechnologyService.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-21 22:13:16 +0200
committertranstrike <transtrike@gmail.com>2021-01-21 22:13:16 +0200
commit13a2ceda912f961a232c87236f1b29aa29bb6160 (patch)
tree59f8d2bf63b03bacc76f98114d2aed78e420ddcd /src/DevHive.Services/Services/TechnologyService.cs
parenta47ea20ab91017da53437f750ed8e0f939f5cdba (diff)
parentbda98b96433d7a9952524fab4ec65f96998b55de (diff)
downloadDevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.tar
DevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.tar.gz
DevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.zip
Merge branch 'refactor_user_updating' into dev
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;