aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Services/Services/TechnologyService.cs
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2020-12-18 10:12:07 +0200
committertranstrike <transtrike@gmail.com>2020-12-18 10:12:07 +0200
commitc50dd1608bff971cd052b375a3c2e618bc98f1c2 (patch)
tree0b9903a1ae284048569c9aa97c5e994e85ead894 /src/DevHive.Services/Services/TechnologyService.cs
parent12408f43a7a954042358196ee080439aa7aed700 (diff)
parent7acec816fe021db4a3922b70ce9b3f50e7600c79 (diff)
downloadDevHive-c50dd1608bff971cd052b375a3c2e618bc98f1c2.tar
DevHive-c50dd1608bff971cd052b375a3c2e618bc98f1c2.tar.gz
DevHive-c50dd1608bff971cd052b375a3c2e618bc98f1c2.zip
Merge branch 'dev' of github.com:Team-Kaleidoscope/DevHive into dev
Diffstat (limited to 'src/DevHive.Services/Services/TechnologyService.cs')
-rw-r--r--src/DevHive.Services/Services/TechnologyService.cs67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs
new file mode 100644
index 0000000..246ad2c
--- /dev/null
+++ b/src/DevHive.Services/Services/TechnologyService.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Threading.Tasks;
+using AutoMapper;
+using DevHive.Data.Models;
+using DevHive.Data.Repositories;
+using DevHive.Services.Models.Technology;
+
+namespace DevHive.Services.Services
+{
+ public class TechnologyService
+ {
+ private readonly TechnologyRepository _technologyRepository;
+ private readonly IMapper _technologyMapper;
+
+ public TechnologyService(DevHiveContext context, IMapper technologyMapper)
+ {
+ this._technologyRepository = new TechnologyRepository(context);
+ this._technologyMapper = technologyMapper;
+ }
+
+ public async Task<bool> Create(TechnologyServiceModel technologyServiceModel)
+ {
+ if (!await this._technologyRepository.DoesTechnologyNameExist(technologyServiceModel.Name))
+ throw new ArgumentException("Technology already exists!");
+
+ Technology technology = this._technologyMapper.Map<Technology>(technologyServiceModel);
+ bool result = await this._technologyRepository.AddAsync(technology);
+
+ return result;
+ }
+
+ public async Task<TechnologyServiceModel> GetTechnologyById(Guid id)
+ {
+ Technology technology = await this._technologyRepository.GetByIdAsync(id);
+
+ if(technology == null)
+ throw new ArgumentException("The technology does not exist");
+
+ return this._technologyMapper.Map<TechnologyServiceModel>(technology);
+ }
+
+ public async Task<bool> UpdateTechnology(UpdateTechnologyServiceModel updateTechnologyServiceModel)
+ {
+ if (!await this._technologyRepository.DoesTechnologyExist(updateTechnologyServiceModel.Id))
+ throw new ArgumentException("Technology does not exist!");
+
+ if (!await this._technologyRepository.DoesTechnologyNameExist(updateTechnologyServiceModel.Name))
+ throw new ArgumentException("Technology name already exists!");
+
+ Technology technology = this._technologyMapper.Map<Technology>(updateTechnologyServiceModel);
+ bool result = await this._technologyRepository.EditAsync(technology);
+
+ return result;
+ }
+
+ public async Task<bool> DeleteTechnology(Guid id)
+ {
+ if (!await this._technologyRepository.DoesTechnologyExist(id))
+ throw new ArgumentException("Technology does not exist!");
+
+ Technology technology = await this._technologyRepository.GetByIdAsync(id);
+ bool result = await this._technologyRepository.DeleteAsync(technology);
+
+ return result;
+ }
+ }
+} \ No newline at end of file