public static Machine InDtoToMachine(InMachineDTO machineDTO) { var machine = new Machine { MachineName = machineDTO.Name, Description = machineDTO.Description, Active = machineDTO.Active }; return(machine); }
public static InMachineDTO MachineToInDto(Machine machine) { var machineDTO = new InMachineDTO { Name = machine.MachineName, Description = machine.Description, MachineType = machine.MachineType.Id, Active = machine.Active }; return(machineDTO); }
public async Task <OutMachineDTO> CreatMachineAsync(InMachineDTO machineDto) { var newMachine = MachineMapping.InDtoToMachine(machineDto); newMachine.MachineType = await _machineTypeRepository.GetById(machineDto.MachineType); var machine = await _machineRepository.Create(newMachine); var outMachineDto = MachineMapping.MachineToOutDto(machine); return(outMachineDto); }
public async Task <IActionResult> Put(int id, [FromBody] InMachineDTO inMachineDto) { try { await _machineService.UpdateMachineAsync(id, inMachineDto); return(StatusCode(200)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public async Task <IActionResult> Create([FromBody] InMachineDTO inMachineDto) { try { var machine = await _machineService.CreatMachineAsync(inMachineDto); return(Created(nameof(Create), machine)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public async Task <OutMachineDTO> UpdateMachineAsync(int id, InMachineDTO machineDto) { var machine = await _machineRepository.GetById(id); if (machine != null) { Machine machineMapping = MachineMapping.InDtoToMachine(machineDto); machine.Description = machineMapping.Description; machine.MachineName = machineMapping.MachineName; var machineType = await _machineTypeRepository.GetById(machineDto.MachineType); machine.MachineType = machineType; machine.Active = machineMapping.Active; } var createdMachine = await _machineRepository.Update(machine); var outMachineDto = MachineMapping.MachineToOutDto(createdMachine); return(outMachineDto); }
/// <summary> /// /// </summary> /// <exception cref="factory.api.client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="inMachineDTO"></param> /// <returns>Task of ApiResponse</returns> public async System.Threading.Tasks.Task <factory.api.client.Client.ApiResponse <Object> > MachinesCreateAsyncWithHttpInfo(InMachineDTO inMachineDTO) { // verify the required parameter 'inMachineDTO' is set if (inMachineDTO == null) { throw new factory.api.client.Client.ApiException(400, "Missing required parameter 'inMachineDTO' when calling MachinesApi->MachinesCreate"); } factory.api.client.Client.RequestOptions requestOptions = new factory.api.client.Client.RequestOptions(); String[] @contentTypes = new String[] { "application/json" }; // to determine the Accept header String[] @accepts = new String[] { "application/json" }; foreach (var contentType in @contentTypes) { requestOptions.HeaderParameters.Add("Content-Type", contentType); } foreach (var accept in @accepts) { requestOptions.HeaderParameters.Add("Accept", accept); } requestOptions.Data = inMachineDTO; // make the HTTP request var response = await this.AsynchronousClient.PostAsync <Object>("/api/v1/machines", requestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception exception = this.ExceptionFactory("MachinesCreate", response); if (exception != null) { throw exception; } } return(response); }
/// <summary> /// /// </summary> /// <exception cref="factory.api.client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="inMachineDTO"></param> /// <returns>Task of void</returns> public async System.Threading.Tasks.Task MachinesCreateAsync(InMachineDTO inMachineDTO) { await MachinesCreateAsyncWithHttpInfo(inMachineDTO); }
/// <summary> /// /// </summary> /// <exception cref="factory.api.client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="inMachineDTO"></param> /// <returns>ApiResponse of Object(void)</returns> public factory.api.client.Client.ApiResponse <Object> MachinesCreateWithHttpInfo(InMachineDTO inMachineDTO) { // verify the required parameter 'inMachineDTO' is set if (inMachineDTO == null) { throw new factory.api.client.Client.ApiException(400, "Missing required parameter 'inMachineDTO' when calling MachinesApi->MachinesCreate"); } factory.api.client.Client.RequestOptions requestOptions = new factory.api.client.Client.RequestOptions(); String[] @contentTypes = new String[] { "application/json" }; // to determine the Accept header String[] @accepts = new String[] { "application/json" }; var localVarContentType = factory.api.client.Client.ClientUtils.SelectHeaderContentType(@contentTypes); if (localVarContentType != null) { requestOptions.HeaderParameters.Add("Content-Type", localVarContentType); } var localVarAccept = factory.api.client.Client.ClientUtils.SelectHeaderAccept(@accepts); if (localVarAccept != null) { requestOptions.HeaderParameters.Add("Accept", localVarAccept); } requestOptions.Data = inMachineDTO; // make the HTTP request var response = this.Client.Post <Object>("/api/v1/machines", requestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception exception = this.ExceptionFactory("MachinesCreate", response); if (exception != null) { throw exception; } } return(response); }
/// <summary> /// /// </summary> /// <exception cref="factory.api.client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="inMachineDTO"></param> /// <returns></returns> public void MachinesCreate(InMachineDTO inMachineDTO) { MachinesCreateWithHttpInfo(inMachineDTO); }
/// <summary> /// /// </summary> /// <exception cref="factory.api.client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id"></param> /// <param name="inMachineDTO"></param> /// <returns>Task of ApiResponse (System.IO.Stream)</returns> public async System.Threading.Tasks.Task <factory.api.client.Client.ApiResponse <System.IO.Stream> > MachinesPutAsyncWithHttpInfo(int id, InMachineDTO inMachineDTO) { // verify the required parameter 'id' is set if (id == null) { throw new factory.api.client.Client.ApiException(400, "Missing required parameter 'id' when calling MachinesApi->MachinesPut"); } // verify the required parameter 'inMachineDTO' is set if (inMachineDTO == null) { throw new factory.api.client.Client.ApiException(400, "Missing required parameter 'inMachineDTO' when calling MachinesApi->MachinesPut"); } factory.api.client.Client.RequestOptions requestOptions = new factory.api.client.Client.RequestOptions(); String[] @contentTypes = new String[] { "application/json" }; // to determine the Accept header String[] @accepts = new String[] { "application/octet-stream" }; foreach (var contentType in @contentTypes) { requestOptions.HeaderParameters.Add("Content-Type", contentType); } foreach (var accept in @accepts) { requestOptions.HeaderParameters.Add("Accept", accept); } if (id != null) { requestOptions.PathParameters.Add("id", factory.api.client.Client.ClientUtils.ParameterToString(id)); // path parameter } requestOptions.Data = inMachineDTO; // make the HTTP request var response = await this.AsynchronousClient.PutAsync <System.IO.Stream>("/api/v1/machines/{id}", requestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception exception = this.ExceptionFactory("MachinesPut", response); if (exception != null) { throw exception; } } return(response); }
/// <summary> /// /// </summary> /// <exception cref="factory.api.client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id"></param> /// <param name="inMachineDTO"></param> /// <returns>Task of System.IO.Stream</returns> public async System.Threading.Tasks.Task <System.IO.Stream> MachinesPutAsync(int id, InMachineDTO inMachineDTO) { factory.api.client.Client.ApiResponse <System.IO.Stream> localVarResponse = await MachinesPutAsyncWithHttpInfo(id, inMachineDTO); return(localVarResponse.Data); }
/// <summary> /// /// </summary> /// <exception cref="factory.api.client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id"></param> /// <param name="inMachineDTO"></param> /// <returns>ApiResponse of System.IO.Stream</returns> public factory.api.client.Client.ApiResponse <System.IO.Stream> MachinesPutWithHttpInfo(int id, InMachineDTO inMachineDTO) { // verify the required parameter 'id' is set if (id == null) { throw new factory.api.client.Client.ApiException(400, "Missing required parameter 'id' when calling MachinesApi->MachinesPut"); } // verify the required parameter 'inMachineDTO' is set if (inMachineDTO == null) { throw new factory.api.client.Client.ApiException(400, "Missing required parameter 'inMachineDTO' when calling MachinesApi->MachinesPut"); } factory.api.client.Client.RequestOptions requestOptions = new factory.api.client.Client.RequestOptions(); String[] @contentTypes = new String[] { "application/json" }; // to determine the Accept header String[] @accepts = new String[] { "application/octet-stream" }; var localVarContentType = factory.api.client.Client.ClientUtils.SelectHeaderContentType(@contentTypes); if (localVarContentType != null) { requestOptions.HeaderParameters.Add("Content-Type", localVarContentType); } var localVarAccept = factory.api.client.Client.ClientUtils.SelectHeaderAccept(@accepts); if (localVarAccept != null) { requestOptions.HeaderParameters.Add("Accept", localVarAccept); } if (id != null) { requestOptions.PathParameters.Add("id", factory.api.client.Client.ClientUtils.ParameterToString(id)); // path parameter } requestOptions.Data = inMachineDTO; // make the HTTP request var response = this.Client.Put <System.IO.Stream>("/api/v1/machines/{id}", requestOptions, this.Configuration); if (this.ExceptionFactory != null) { Exception exception = this.ExceptionFactory("MachinesPut", response); if (exception != null) { throw exception; } } return(response); }
/// <summary> /// /// </summary> /// <exception cref="factory.api.client.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="id"></param> /// <param name="inMachineDTO"></param> /// <returns>System.IO.Stream</returns> public System.IO.Stream MachinesPut(int id, InMachineDTO inMachineDTO) { factory.api.client.Client.ApiResponse <System.IO.Stream> localVarResponse = MachinesPutWithHttpInfo(id, inMachineDTO); return(localVarResponse.Data); }