Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Service / PCC.Services / PartsService.cs
blob: c9021319a5fdd0838ee5157bb55c9c3415d782d4 (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
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)
        {
            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<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;
        }
    }
}