public void DeleteCpu(CpuDto cpu)
        {
            var cpuToDelete = this.context.cpus.FirstOrDefault(c => c.model == cpu.model);

            this.context.cpus.Remove(cpuToDelete);

            this.context.SaveChanges();
        }
Пример #2
0
 public IActionResult AddCpu(CpuDto cpu)
 {
     if (ModelState.IsValid)
     {
         componentService.CreateCPU(cpu);
         return(RedirectToAction(nameof(AddCpu)));
     }
     return(View());
 }
Пример #3
0
 public IActionResult AddCpu(CpuDto cpu)
 {
     if (ModelState.IsValid)
     {
         if (componentService.HasTheSameIdInBase(cpu.model))
         {
             return(NotFound("A processor with the same model already exits"));
         }
         componentService.CreateCPU(cpu);
         return(RedirectToAction(nameof(AddCpu)));
     }
     return(View());
 }
Пример #4
0
        private async Task <string> AssignCpu(CpuDto cpuDto, CancellationToken cancellationToken)
        {
            var id       = _idProvider.GetForCpu(cpuDto);
            var cpuModel = await _cpuRepository.GetSingleAsync(id, cancellationToken);

            if (cpuModel == null)
            {
                cpuModel = cpuDto.ToModel(id);
                await _cpuRepository.CreateAsync(cpuModel, cancellationToken);
            }

            return(id);
        }
 public CPU OfCpuDto(CpuDto cpu)
 {
     return(new CPU()
     {
         model = cpu.model,
         socket = cpu.socket,
         frequency = cpu.frequency,
         cores = cpu.cores,
         threads = cpu.threads,
         cpuBrand = cpu.cpuBrand,
         generation = cpu.generation,
         tdp = cpu.tdp,
         price = cpu.price
     });
 }
        public CpuDto GetByCpuId(string id)
        {
            CpuDto cpuDto = new CpuDto();
            CPU    cpu    = this.context.cpus.FirstOrDefault(x => x.model == id);

            cpuDto.model      = cpu.model;
            cpuDto.socket     = cpu.socket;
            cpuDto.frequency  = cpu.frequency;
            cpuDto.cores      = cpu.cores;
            cpuDto.threads    = cpu.threads;
            cpuDto.cpuBrand   = cpu.cpuBrand;
            cpuDto.generation = cpu.generation;
            cpuDto.tdp        = cpu.tdp;
            cpuDto.price      = cpu.price;

            return(cpuDto);
        }
Пример #7
0
        public string GetForCpu(CpuDto cpuDto)
        {
            var builder = new StringBuilder();

            builder.Append(cpuDto.Vendor);
            builder.Append('_');
            builder.Append(cpuDto.Brand);

            foreach (var infoPair in cpuDto.AdditionalInfo.
                     ToArray()
                     .OrderBy(c => c.Key))
            {
                builder.Append('_');
                builder.Append(infoPair.Value);
            }

            return(builder.ToString());
        }
Пример #8
0
        public static CpuModel ToModel(this CpuDto cpuDto, string id)
        {
            if (cpuDto == null)
            {
                throw new ArgumentNullException(nameof(cpuDto));
            }

            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentException("'id' cannot be empty", nameof(id));
            }

            return(new CpuModel
            {
                Id = id,
                Brand = cpuDto.Brand,
                Caches = cpuDto.Caches.Select(c => c.ToModel()).ToList(),
                Features = cpuDto.Features,
                Frequency = cpuDto.Frequency,
                Smt = cpuDto.Smt,
                Vendor = cpuDto.Vendor,
                AdditionalInfo = cpuDto.AdditionalInfo
            });
        }
 public void CreateCPU(CpuDto cpu)
 {
     this.context.cpus.Add(this.OfCpuDto(cpu));
     this.context.SaveChanges();
 }
Пример #10
0
        public IActionResult DeleteCpu(CpuDto component)
        {
            this.componentService.DeleteCpu(component);

            return(RedirectToAction("ShowCpu", "CPU"));
        }