public async Task <Machine> CreateMachine(MachineDTO machineDTO) { var machineTypeId = Guid.Parse(machineDTO.MachineType); var machineType = await _machineTypeService.getMachineType(machineTypeId); var machineBrand = new MachineBrand(machineDTO.MachineBrand); var machineModel = new MachineModel(machineDTO.MachineModel); var machineLocation = new MachineLocation(machineDTO.MachineLocation); var machine = new Machine(machineType, machineBrand, machineModel, machineLocation); await _machineRepository.Create(machine); return(machine); }
public List <Machine> GetAllMachinesForCustomerId(string customerId) { var result = _listMachineService.GetAllMachinesForCustomerId(new GetAllMachinesForCustomerIdRequest { CUNO = customerId }); var listMachine = new List <Machine>(); if (result?.allMachinesOut == null) { return(listMachine); } foreach (var t in result.allMachinesOut) { var componentAttrs = t.componentAttributes; if (componentAttrs == null) { continue; } var groupNew = new MachineGroup { Id = componentAttrs.CmIndividType?.smdid ?? "0", Key = componentAttrs.CmIndividType?.smdkey ?? "0", Name = componentAttrs.CmIndividType?.Text?.Length > 0 ? componentAttrs.CmIndividType?.Text[0] : "Ingen kategori" }; var images = t.image; var machineImages = images?.Select(image => new MachineImage { FileName = image.CmFilename?.Text?.Length > 0 ? image.CmFilename?.Text[0] : string.Empty, Name = image.CmName?.Text?.Length > 0 ? image.CmName?.Text[0] : string.Empty, Id = image.SysId?.Text?.Length > 0 ? image.SysId?.Text[0] : string.Empty, ImageType = image.CmImageType?.Text != null && image.CmImageType.Text.Length > 0 ? image.CmImageType.Text[0] : string.Empty }); var brand = new MachineBrand { Id = componentAttrs.CmOE?.smdkey != null ? componentAttrs.CmOE?.smdid : string.Empty, Key = componentAttrs.CmOE?.smdkey ?? string.Empty, Name = componentAttrs.CmOE?.Text?.Length > 0 ? (componentAttrs.CmOE.Text[0] != "Annan" ? componentAttrs.CmOE.Text[0] : string.Empty) : string.Empty }; var model = new MachineModel { Id = componentAttrs.CmModels?.smdkey != null ? componentAttrs.CmModels?.smdid : string.Empty, Key = componentAttrs.CmModels?.smdkey ?? string.Empty, Name = componentAttrs.CmModels?.Text?.Length > 0 ? (componentAttrs.CmModels?.Text[0] != "Annan" ? componentAttrs.CmModels.Text[0] : string.Empty) : string.Empty }; var machine = new Machine { LegalRegNumber = componentAttrs.MvxSAREBE?.Text?.Length > 0 ? componentAttrs.MvxSAREBE?.Text[0] : string.Empty, SerialNumber = componentAttrs.MvxSASERI?.Text?.Length > 0 ? componentAttrs.MvxSASERI?.Text[0] : string.Empty, Id = componentAttrs.SysId?.Text?.Length > 0 ? componentAttrs.SysId.Text[0] : string.Empty, ModelDescription = componentAttrs.MvxSAMODE?.Text?.Length > 0 ? componentAttrs.MvxSAMODE.Text[0] : componentAttrs.CmSubHeader?.Text?.Length > 0 ? componentAttrs.CmSubHeader?.Text[0] : string.Empty, IndividualNumber = componentAttrs.MvxSAINNO?.Text?.Length > 0 ? componentAttrs.MvxSAINNO.Text[0] : string.Empty, DescriptionBrand = componentAttrs.CmHeader?.Text?.Length > 0 ? componentAttrs.CmHeader.Text[0] : string.Empty, Brand = brand, Group = groupNew, Model = model, Images = machineImages?.ToList() ?? new List <MachineImage>() }; listMachine.Add(machine); } return(listMachine); }