public bool updateTool(ToolDTO toolDTO) { var tool = _context.Tools.Where(toolInfo => toolInfo.Status == 1 && toolInfo.ToolId == toolDTO.ToolID).FirstOrDefault(); if (tool == null) { return(false); } tool.ToolName = toolDTO.ToolName; tool.Description = toolDTO.Description; tool.Image = toolDTO.Image; tool.Amount = toolDTO.Amount; tool.Status = toolDTO.Status; try { _context.SaveChanges(); return(true); } catch (DbUpdateException) { throw; } }
public void createNewTool([FromBody] ToolDTO toolDTO) { try { _toolRepo.addNewTool(toolDTO); } catch { BadRequest(); } }
public IActionResult updateTool([FromBody] ToolDTO toolDTO) { bool isSuccess = _toolRepo.updateTool(toolDTO); if (!isSuccess) { return(NotFound("No no no")); } return(Ok("success")); }
public void addNewTool(ToolDTO toolDTO) { Tool tool2add = new Tool { ToolName = toolDTO.ToolName, Description = toolDTO.Description, Image = toolDTO.Image, Amount = toolDTO.Amount, Status = 1, }; _context.Tools.Add(tool2add); try { _context.SaveChanges(); } catch (DbUpdateException) { throw; } }