public static Tool Map(InToolDTO toolDTO) { return(new Tool { Name = toolDTO.Name, SerialNumber = toolDTO.SerialNumber, Comment = toolDTO.Comment }); }
public async Task <IActionResult> CreateAsync([FromBody] InToolDTO toolDTO) { var tool = ToolMapper.Map(toolDTO); tool = _repositoryManager.ToolRepository.Create(tool); await _repositoryManager.SaveAsync(); return(Ok(ToolMapper.Map(tool))); }
public async Task <IActionResult> Put(string name, [FromBody] InToolDTO inToolDto) { try { await _toolService.UpdateToolAsync(name, inToolDto); return(NoContent()); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public async Task <IActionResult> Post([FromBody] InToolDTO inToolDto) { try { var tool = await _toolService.CreateToolAsync(inToolDto); return(Created(nameof(Post), tool)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public async Task <OutToolDTO> CreateToolAsync(InToolDTO inToolDto) { var tool = await _toolRepository.Create(new Tool() { Name = inToolDto.Tool }); var outToolDto = new OutToolDTO() { Tool = tool.Name }; return(outToolDto); }
public async Task <OutToolDTO> UpdateToolAsync(string toolName, InToolDTO inToolDto) { var tool = await _toolRepository.GetByName(toolName); if (tool != null) { tool.Name = inToolDto.Tool; } var updatedtool = await _toolRepository.Update(tool); return(new OutToolDTO() { Tool = updatedtool.Name }); }
public async Task <IActionResult> UpdateAsync([FromRoute] int id, [FromBody] InToolDTO toolDTO) { var tool = await _repositoryManager.ToolRepository.GetAsync(id); if (tool == null) { return(NotFound()); } tool.Update(toolDTO); _repositoryManager.ToolRepository.Update(tool); await _repositoryManager.SaveAsync(); return(Ok(ToolMapper.Map(tool))); }
public static void Update(this Tool tool, InToolDTO toolDTO) { tool.Name = toolDTO.Name; tool.SerialNumber = toolDTO.SerialNumber; tool.Comment = toolDTO.Comment; }