Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Web / PCC.Web / Controllers / PartsController.cs
blob: a96328bfc5d74275a9243088973efb1a1c4832a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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<IActionResult> CreateProcessor(CreateProcessorBindingModel createProcessorBindingModel)
        {
            ProcessorServiceModel serviceModel = createProcessorBindingModel.To<ProcessorServiceModel>();
            
            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<IActionResult> CreateGPU(CreateGPUBindingModel createGPUBindingModel)
        {
            GPUServiceModel serviceModel = createGPUBindingModel.To<GPUServiceModel>();

            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<IActionResult> CreateRAM(CreateRAMBindingModel createRAMBindingModel)
        {
            RAMServiceModel serviceModel = createRAMBindingModel.To<RAMServiceModel>();

            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<IActionResult> CreateMotherboard(CreateMotherboardBindingModel createMotherboardBindingModel)
        {
            MotherboardServiceModel serviceModel = createMotherboardBindingModel.To<MotherboardServiceModel>();

            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<IActionResult> CreateHardDrive(CreateHardDiskBindingModel createHardDiskBindingModel)
        {
            HardDiskServiceModel serviceModel = createHardDiskBindingModel.To<HardDiskServiceModel>();

            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<IActionResult> CreatePowerSupply(CreatePowerSupplyBindingModel createPowerSupplyBindingModel)
        {
            PowerSupplyServiceModel serviceModel = createPowerSupplyBindingModel.To<PowerSupplyServiceModel>();

            string url = await this.cloudinaryService.UploadImage(createPowerSupplyBindingModel.FileUpload);

            serviceModel.ImageUrl = url;

            bool result = await this.partsService.CreatePowerSupplyPart(serviceModel);

            return Redirect("/");
        }
    }
}