diff options
Initial Commit - Add all project files
13 files changed, 296 insertions, 0 deletions
diff --git a/src/Service/PCC.Services.Models/PCC.Services.Models.csproj b/src/Service/PCC.Services.Models/PCC.Services.Models.csproj new file mode 100644 index 0000000..f58b7f2 --- /dev/null +++ b/src/Service/PCC.Services.Models/PCC.Services.Models.csproj @@ -0,0 +1,12 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>netcoreapp3.1</TargetFramework> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="..\..\Common\AutoMapperConfiguration\AutoMapperConfiguration.csproj" /> + <ProjectReference Include="..\..\Data\PCC.Data.Models\PCC.Data.Models.csproj" /> + </ItemGroup> + +</Project> diff --git a/src/Service/PCC.Services.Models/Parts/GPUServiceModel.cs b/src/Service/PCC.Services.Models/Parts/GPUServiceModel.cs new file mode 100644 index 0000000..914594d --- /dev/null +++ b/src/Service/PCC.Services.Models/Parts/GPUServiceModel.cs @@ -0,0 +1,14 @@ +using AutoMapperConfiguration; +using PCC.Data.Models.Parts; + +namespace PCC.Services.Models.Parts +{ + public class GPUServiceModel : PartServiceModel, IMapFrom<GPU>, IMapTo<GPU> + { + public long Memory { get; set; } + + public long Clockspeed { get; set; } + + public string Generation { get; set; } + } +} diff --git a/src/Service/PCC.Services.Models/Parts/HardDiskServiceModel.cs b/src/Service/PCC.Services.Models/Parts/HardDiskServiceModel.cs new file mode 100644 index 0000000..e13bbdc --- /dev/null +++ b/src/Service/PCC.Services.Models/Parts/HardDiskServiceModel.cs @@ -0,0 +1,14 @@ +using AutoMapperConfiguration; +using PCC.Data.Models.Parts; + +namespace PCC.Services.Models.Parts +{ + public class HardDiskServiceModel : PartServiceModel, IMapFrom<HardDisk>, IMapTo<HardDisk> + { + public long Capacity { get; set; } + + public long Speed { get; set; } + + public bool IsSSD { get; set; } + } +} diff --git a/src/Service/PCC.Services.Models/Parts/MotherboardServiceModel.cs b/src/Service/PCC.Services.Models/Parts/MotherboardServiceModel.cs new file mode 100644 index 0000000..aa9d3a2 --- /dev/null +++ b/src/Service/PCC.Services.Models/Parts/MotherboardServiceModel.cs @@ -0,0 +1,12 @@ +using AutoMapperConfiguration; +using PCC.Data.Models.Parts; + +namespace PCC.Services.Models.Parts +{ + public class MotherboardServiceModel : PartServiceModel, IMapFrom<Motherboard>, IMapTo<Motherboard> + { + public string CPUSupport { get; set; } + + public string MemorySupport { get; set; } + } +} diff --git a/src/Service/PCC.Services.Models/Parts/PartServiceModel.cs b/src/Service/PCC.Services.Models/Parts/PartServiceModel.cs new file mode 100644 index 0000000..4315e23 --- /dev/null +++ b/src/Service/PCC.Services.Models/Parts/PartServiceModel.cs @@ -0,0 +1,17 @@ +namespace PCC.Services.Models.Parts +{ + public abstract class PartServiceModel + { + public string Id { get; set; } + + public string Brand { get; set; } + + public string Model { get; set; } + + public decimal Price { get; set; } + + public int ElectricalPowerConsumption { get; set; } + + public string ImageUrl { get; set; } + } +} diff --git a/src/Service/PCC.Services.Models/Parts/PowerSupplyServiceModel.cs b/src/Service/PCC.Services.Models/Parts/PowerSupplyServiceModel.cs new file mode 100644 index 0000000..b490ea6 --- /dev/null +++ b/src/Service/PCC.Services.Models/Parts/PowerSupplyServiceModel.cs @@ -0,0 +1,10 @@ +using AutoMapperConfiguration; +using PCC.Data.Models.Parts; + +namespace PCC.Services.Models.Parts +{ + public class PowerSupplyServiceModel : PartServiceModel, IMapFrom<PowerSupply>, IMapTo<PowerSupply> + { + public int SupportedElectricalPowerConsumption { get; set; } + } +} diff --git a/src/Service/PCC.Services.Models/Parts/ProcessorServiceModel.cs b/src/Service/PCC.Services.Models/Parts/ProcessorServiceModel.cs new file mode 100644 index 0000000..35c1210 --- /dev/null +++ b/src/Service/PCC.Services.Models/Parts/ProcessorServiceModel.cs @@ -0,0 +1,14 @@ +using AutoMapperConfiguration; +using PCC.Data.Models; + +namespace PCC.Services.Models.Parts +{ + public class ProcessorServiceModel : PartServiceModel, IMapFrom<Processor>, IMapTo<Processor> + { + public int Cores { get; set; } + + public long Clockspeed { get; set; } + + public string Socket { get; set; } + } +} diff --git a/src/Service/PCC.Services.Models/Parts/RAMServiceModel.cs b/src/Service/PCC.Services.Models/Parts/RAMServiceModel.cs new file mode 100644 index 0000000..513092a --- /dev/null +++ b/src/Service/PCC.Services.Models/Parts/RAMServiceModel.cs @@ -0,0 +1,14 @@ +using AutoMapperConfiguration; +using PCC.Data.Models.Parts; + +namespace PCC.Services.Models.Parts +{ + public class RAMServiceModel : PartServiceModel, IMapFrom<RAM>, IMapTo<RAM> + { + public long Capacity { get; set; } + + public string Type { get; set; } + + public long Speed { get; set; } + } +} diff --git a/src/Service/PCC.Services/CloudinaryService.cs b/src/Service/PCC.Services/CloudinaryService.cs new file mode 100644 index 0000000..a1cad2f --- /dev/null +++ b/src/Service/PCC.Services/CloudinaryService.cs @@ -0,0 +1,44 @@ +using CloudinaryDotNet; +using CloudinaryDotNet.Actions; +using Microsoft.AspNetCore.Http; +using System; +using System.IO; +using System.Threading.Tasks; + +namespace PCC.Services +{ + public class CloudinaryService : ICloudinaryService + { + private readonly Cloudinary cloudinary; + + public CloudinaryService(string cloudName, string apiKey, string apiSecret) + { + this.cloudinary = new Cloudinary(new Account(cloudName, apiKey, apiSecret)); + } + + public async Task<string> UploadImage(IFormFile formFile) + { + string formFileId = Guid.NewGuid().ToString(); + + if (formFile.Length > 0) + { + using (var ms = new MemoryStream()) + { + formFile.CopyTo(ms); + byte[] formBytes = ms.ToArray(); + + ImageUploadParams imageUploadParams = new ImageUploadParams + { + File = new FileDescription(formFileId, new MemoryStream(formBytes)), + PublicId = formFileId + }; + + ImageUploadResult uploadResult = await this.cloudinary.UploadAsync(imageUploadParams); + return uploadResult.Url.AbsoluteUri; + } + } + + return null; + } + } +} diff --git a/src/Service/PCC.Services/ICloudinaryService.cs b/src/Service/PCC.Services/ICloudinaryService.cs new file mode 100644 index 0000000..809c7b8 --- /dev/null +++ b/src/Service/PCC.Services/ICloudinaryService.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Http; +using System.Threading.Tasks; + +namespace PCC.Services +{ + public interface ICloudinaryService + { + Task<string> UploadImage(IFormFile formFile); + } +} diff --git a/src/Service/PCC.Services/IPartsService.cs b/src/Service/PCC.Services/IPartsService.cs new file mode 100644 index 0000000..38e1c06 --- /dev/null +++ b/src/Service/PCC.Services/IPartsService.cs @@ -0,0 +1,20 @@ +using PCC.Services.Models.Parts; +using System.Threading.Tasks; + +namespace PCC.Services +{ + public interface IPartsService + { + Task<bool> CreateProcessorPart(ProcessorServiceModel processorServiceModel); + + Task<bool> CreateGPUPart(GPUServiceModel gPUServiceModel); + + Task<bool> CreateRAMPart(RAMServiceModel rAMServiceModel); + + Task<bool> CreateMotherboardPart(MotherboardServiceModel motherboardServiceModel); + + Task<bool> CreateHardDiskPart(HardDiskServiceModel hardDiskServiceModel); + + Task<bool> CreatePowerSupplyPart(PowerSupplyServiceModel powerSupplyServiceModel); + } +} diff --git a/src/Service/PCC.Services/PCC.Services.csproj b/src/Service/PCC.Services/PCC.Services.csproj new file mode 100644 index 0000000..67a37fc --- /dev/null +++ b/src/Service/PCC.Services/PCC.Services.csproj @@ -0,0 +1,17 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>netcoreapp3.1</TargetFramework> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="CloudinaryDotNet" Version="1.14.0" /> + <PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.2" /> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\..\Data\PCC.Data\PCC.Data.csproj" /> + <ProjectReference Include="..\PCC.Services.Models\PCC.Services.Models.csproj" /> + </ItemGroup> + +</Project> diff --git a/src/Service/PCC.Services/PartsService.cs b/src/Service/PCC.Services/PartsService.cs new file mode 100644 index 0000000..4c48ca2 --- /dev/null +++ b/src/Service/PCC.Services/PartsService.cs @@ -0,0 +1,98 @@ +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<bool> CreateProcessorPart(ProcessorServiceModel processorServiceModel) + { + Processor processorEntity = processorServiceModel.To<Processor>(); + + processorEntity.Id = Guid.NewGuid().ToString(); + + bool result = await this.pCCDbContext.AddAsync(processorEntity) != null; + + await this.pCCDbContext.SaveChangesAsync(); + + return result; + } + + public async Task<bool> CreateGPUPart(GPUServiceModel gPUServiceModel) + { + GPU gPUEntity = gPUServiceModel.To<GPU>(); + + gPUEntity.Id = Guid.NewGuid().ToString(); + + bool result = await this.pCCDbContext.AddAsync(gPUEntity) != null; + + await this.pCCDbContext.SaveChangesAsync(); + + return result; + } + + public async Task<bool> CreateRAMPart(RAMServiceModel rAMServiceModel) + { + RAM rAMEntity = rAMServiceModel.To<RAM>(); + + rAMEntity.Id = Guid.NewGuid().ToString(); + + bool result = await this.pCCDbContext.AddAsync(rAMEntity) != null; + + await this.pCCDbContext.SaveChangesAsync(); + + return result; + } + + public async Task<bool> CreateMotherboardPart(MotherboardServiceModel motherboardServiceModel) + { + Motherboard motherboardEntity = motherboardServiceModel.To<Motherboard>(); + + motherboardEntity.Id = Guid.NewGuid().ToString(); + + bool result = await this.pCCDbContext.AddAsync(motherboardEntity) != null; + + await this.pCCDbContext.SaveChangesAsync(); + + return result; + } + + public async Task<bool> CreateHardDiskPart(HardDiskServiceModel hardDiskServiceModel) + { + HardDisk hardDiskEntity = hardDiskServiceModel.To<HardDisk>(); + + hardDiskEntity.Id = Guid.NewGuid().ToString(); + + bool result = await this.pCCDbContext.AddAsync(hardDiskEntity) != null; + + await this.pCCDbContext.SaveChangesAsync(); + + return result; + } + + public async Task<bool> CreatePowerSupplyPart(PowerSupplyServiceModel powerSupplyServiceModel) + { + PowerSupply powerSupplyEntity = powerSupplyServiceModel.To<PowerSupply>(); + + powerSupplyEntity.Id = Guid.NewGuid().ToString(); + + bool result = await this.pCCDbContext.AddAsync(powerSupplyEntity) != null; + + await this.pCCDbContext.SaveChangesAsync(); + + return result; + } + } +} |