public void DeletePcCase(PcCaseDto pcCase)
        {
            var pcCaseToDelete = this.context.cases.FirstOrDefault(c => c.model == pcCase.model);

            this.context.cases.Remove(pcCaseToDelete);

            this.context.SaveChanges();
        }
 public PcCase OfPcCaseDto(PcCaseDto pcCase)
 {
     return(new PcCase()
     {
         model = pcCase.model,
         formfactor = pcCase.formfactor,
         price = pcCase.price
     });
 }
        public PcCaseDto GetPcCaseById(string id)
        {
            PcCaseDto pcCaseDto = new PcCaseDto();
            PcCase    pcCase    = this.context.cases.FirstOrDefault(x => x.model == id);


            pcCaseDto.model      = pcCase.model;
            pcCaseDto.formfactor = pcCase.formfactor;
            pcCaseDto.price      = pcCase.price;

            return(pcCaseDto);
        }
 public IActionResult AddPcCase(PcCaseDto pcCase)
 {
     if (ModelState.IsValid)
     {
         componentService.CreatePcCase(pcCase);
         return(RedirectToAction(nameof(AddPcCase)));
     }
     else
     {
         return(View("The component exists"));
     }
 }
Example #5
0
 public void CreatePcCase(PcCaseDto pcCase)
 {
     this.context.cases.Add(this.OfPcCaseDto(pcCase));
     foreach (var caseModel in context.cases)
     {
         if (caseModel.model == pcCase.model)
         {
             break;
         }
         this.context.SaveChanges();
     }
 }
 public IActionResult AddPcCase(PcCaseDto pcCase)
 {
     if (ModelState.IsValid)
     {
         if (componentService.HasTheSameIdInBase(pcCase.model))
         {
             return(NotFound("A case with the same model already exits"));
         }
         componentService.CreatePcCase(pcCase);
         return(RedirectToAction(nameof(AddPcCase)));
     }
     return(View());
 }
 public void CreatePcCase(PcCaseDto pcCase)
 {
     this.context.cases.Add(this.OfPcCaseDto(pcCase));
     this.context.SaveChanges();
 }
        public IActionResult DeletePcCase(PcCaseDto pcCase)
        {
            this.componentService.DeletePcCase(pcCase);

            return(RedirectToAction("ShowPcCases", "PcCase"));
        }