Пример #1
0
 public static Tool Map(InToolDTO toolDTO)
 {
     return(new Tool
     {
         Name = toolDTO.Name,
         SerialNumber = toolDTO.SerialNumber,
         Comment = toolDTO.Comment
     });
 }
Пример #2
0
        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)));
        }
Пример #3
0
        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));
            }
        }
Пример #4
0
        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));
            }
        }
Пример #5
0
        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);
        }
Пример #6
0
        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
            });
        }
Пример #7
0
        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)));
        }
Пример #8
0
 public static void Update(this Tool tool, InToolDTO toolDTO)
 {
     tool.Name         = toolDTO.Name;
     tool.SerialNumber = toolDTO.SerialNumber;
     tool.Comment      = toolDTO.Comment;
 }