using AutoMapperConfiguration; using PCC.Data; using PCC.Data.Models; using PCC.Data.Models.Parts; using PCC.Services.Models.Parts; using System; using System.Threading.Tasks; namespace PCC.Services { public class PartsService : IPartsService { private readonly PCCDbContext pCCDbContext; public PartsService(PCCDbContext pCCDbContext) { this.pCCDbContext = pCCDbContext; } public async Task CreateProcessorPart(ProcessorServiceModel processorServiceModel) { if (string.IsNullOrEmpty(processorServiceModel.Brand)) { // TODO: Move message to constant // Refactor this throw new ArgumentException("Processor Brand cannot be null or empty!"); } Processor processorEntity = processorServiceModel.To(); processorEntity.Id = Guid.NewGuid().ToString(); bool result = await this.pCCDbContext.AddAsync(processorEntity) != null; await this.pCCDbContext.SaveChangesAsync(); return result; } public async Task CreateGPUPart(GPUServiceModel gPUServiceModel) { GPU gPUEntity = gPUServiceModel.To(); gPUEntity.Id = Guid.NewGuid().ToString(); bool result = await this.pCCDbContext.AddAsync(gPUEntity) != null; await this.pCCDbContext.SaveChangesAsync(); return result; } public async Task CreateRAMPart(RAMServiceModel rAMServiceModel) { RAM rAMEntity = rAMServiceModel.To(); rAMEntity.Id = Guid.NewGuid().ToString(); bool result = await this.pCCDbContext.AddAsync(rAMEntity) != null; await this.pCCDbContext.SaveChangesAsync(); return result; } public async Task CreateMotherboardPart(MotherboardServiceModel motherboardServiceModel) { Motherboard motherboardEntity = motherboardServiceModel.To(); motherboardEntity.Id = Guid.NewGuid().ToString(); bool result = await this.pCCDbContext.AddAsync(motherboardEntity) != null; await this.pCCDbContext.SaveChangesAsync(); return result; } public async Task CreateHardDiskPart(HardDiskServiceModel hardDiskServiceModel) { HardDisk hardDiskEntity = hardDiskServiceModel.To(); hardDiskEntity.Id = Guid.NewGuid().ToString(); bool result = await this.pCCDbContext.AddAsync(hardDiskEntity) != null; await this.pCCDbContext.SaveChangesAsync(); return result; } public async Task CreatePowerSupplyPart(PowerSupplyServiceModel powerSupplyServiceModel) { PowerSupply powerSupplyEntity = powerSupplyServiceModel.To(); powerSupplyEntity.Id = Guid.NewGuid().ToString(); bool result = await this.pCCDbContext.AddAsync(powerSupplyEntity) != null; await this.pCCDbContext.SaveChangesAsync(); return result; } } }