public void MassCreateComputers()
        {
            var fakeComputers = new List <ComputerViewModel>();

            for (int i = 1; i < 6; i++)
            {
                var computer = new ComputerViewModel()
                {
                    ComputerCode        = $"CCODE{i}",
                    ComputerName        = $"ComputerName {i}",
                    ComputerDescription = $"ComputerDesription {i}",
                    ComputerTypeId      = i,
                    DeparmentTypeId     = i,
                    ProducerTypeId      = i,
                    IsBusyNow           = false,
                    Status = true
                };
                fakeComputers.Add(computer);
            }

            foreach (var computerViewModel in fakeComputers)
            {
                Model.Models.Computer newComputer = new Model.Models.Computer();
                newComputer.UpdateComputer(computerViewModel);

                _computerService.Add(newComputer);
                _computerService.Save();
            }
        }
        public IActionResult Add(Computer computer)
        {
            var result = _computerService.Add(computer);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
        public async Task <ActionResult <ComputerModel> > PostComputer(GenericComputer computer)
        {
            if (computer == null)
            {
                return(BadRequest());
            }

            ComputerModel cp;

            switch (computer.TypeName)
            {
            case "Desktop":
                PCComputer newPC = new PCComputer {
                    Id            = Guid.NewGuid(),
                    TypeName      = computer.TypeName,
                    Brand         = computer.Brand,
                    ProcessorName = computer.ProcessorName,
                    Quantity      = computer.Quantity,
                    UsbPorts      = computer.UsbPorts,
                    RamSlots      = computer.RamSlots,
                    ImageUrl      = computer.ImageUrl,
                };
                cp = newPC;
                break;

            case "Laptop":
                LaptopComputer newLP = new LaptopComputer {
                    Id            = Guid.NewGuid(),
                    TypeName      = computer.TypeName,
                    Brand         = computer.Brand,
                    ProcessorName = computer.ProcessorName,
                    Quantity      = computer.Quantity,
                    ImageUrl      = computer.ImageUrl,
                    ScreenSize    = computer.ScreenSize
                };
                cp = newLP;
                break;

            default:
                return(BadRequest());
            }

            await _computerService.Add(cp);

            return(cp);
        }
Exemple #4
0
        public HttpResponseMessage Post(HttpRequestMessage request, ComputerViewModel computerVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage errorResponse;
                if (AddUpdateComputerValidation(request, computerVm, out errorResponse))
                {
                    return errorResponse;
                }

                var newComputer = new Model.Models.Computer();
                newComputer.UpdateComputer(computerVm);

                var computer = _computerService.Add(newComputer);
                _computerService.Save();

                var response = request.CreateResponse(HttpStatusCode.Created, computer);
                return response;
            }));
        }