From 77b7ff6ca840866605204e5d501fe23dd184bd5c Mon Sep 17 00:00:00 2001 From: "ivaylo.zhelev" Date: Sun, 24 Jan 2021 09:25:15 +0200 Subject: Initial Commit - Add all project files --- src/Web/PCC.Web/Controllers/PartsController.cs | 112 +++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/Web/PCC.Web/Controllers/PartsController.cs (limited to 'src/Web/PCC.Web/Controllers/PartsController.cs') diff --git a/src/Web/PCC.Web/Controllers/PartsController.cs b/src/Web/PCC.Web/Controllers/PartsController.cs new file mode 100644 index 0000000..a96328b --- /dev/null +++ b/src/Web/PCC.Web/Controllers/PartsController.cs @@ -0,0 +1,112 @@ +using AutoMapperConfiguration; +using Microsoft.AspNetCore.Mvc; +using PCC.Services; +using PCC.Services.Models.Parts; +using PCC.Web.Models.Binding; +using System.Threading.Tasks; + +namespace PCC.Web.Controllers +{ + public class PartsController : Controller + { + private readonly ICloudinaryService cloudinaryService; + + private readonly IPartsService partsService; + + public PartsController(ICloudinaryService cloudinaryService, IPartsService partsService) + { + this.cloudinaryService = cloudinaryService; + this.partsService = partsService; + } + + [HttpGet] + public IActionResult Create() + { + return View(); + } + + [HttpPost("/Parts/Create/Processor")] + public async Task CreateProcessor(CreateProcessorBindingModel createProcessorBindingModel) + { + ProcessorServiceModel serviceModel = createProcessorBindingModel.To(); + + string url = await this.cloudinaryService.UploadImage(createProcessorBindingModel.FileUpload); + + serviceModel.ImageUrl = url; + + bool result = await this.partsService.CreateProcessorPart(serviceModel); + + return Redirect("/"); + } + + [HttpPost("/Parts/Create/GPU")] + public async Task CreateGPU(CreateGPUBindingModel createGPUBindingModel) + { + GPUServiceModel serviceModel = createGPUBindingModel.To(); + + string url = await this.cloudinaryService.UploadImage(createGPUBindingModel.FileUpload); + + serviceModel.ImageUrl = url; + + bool result = await this.partsService.CreateGPUPart(serviceModel); + + return Redirect("/"); + } + + [HttpPost("/Parts/Create/RAM")] + public async Task CreateRAM(CreateRAMBindingModel createRAMBindingModel) + { + RAMServiceModel serviceModel = createRAMBindingModel.To(); + + string url = await this.cloudinaryService.UploadImage(createRAMBindingModel.FileUpload); + + serviceModel.ImageUrl = url; + + bool result = await this.partsService.CreateRAMPart(serviceModel); + + return Redirect("/"); + } + + [HttpPost("/Parts/Create/Motherboard")] + public async Task CreateMotherboard(CreateMotherboardBindingModel createMotherboardBindingModel) + { + MotherboardServiceModel serviceModel = createMotherboardBindingModel.To(); + + string url = await this.cloudinaryService.UploadImage(createMotherboardBindingModel.FileUpload); + + serviceModel.ImageUrl = url; + + bool result = await this.partsService.CreateMotherboardPart(serviceModel); + + return Redirect("/"); + } + + [HttpPost("/Parts/Create/HardDrive")] + public async Task CreateHardDrive(CreateHardDiskBindingModel createHardDiskBindingModel) + { + HardDiskServiceModel serviceModel = createHardDiskBindingModel.To(); + + string url = await this.cloudinaryService.UploadImage(createHardDiskBindingModel.FileUpload); + + serviceModel.ImageUrl = url; + + bool result = await this.partsService.CreateHardDiskPart(serviceModel); + + return Redirect("/"); + } + + [HttpPost("/Parts/Create/PowerSupply")] + public async Task CreatePowerSupply(CreatePowerSupplyBindingModel createPowerSupplyBindingModel) + { + PowerSupplyServiceModel serviceModel = createPowerSupplyBindingModel.To(); + + string url = await this.cloudinaryService.UploadImage(createPowerSupplyBindingModel.FileUpload); + + serviceModel.ImageUrl = url; + + bool result = await this.partsService.CreatePowerSupplyPart(serviceModel); + + return Redirect("/"); + } + } +} -- cgit v1.3.1-26-gb76a