/// <summary> /// Changes an existing Tool object in the Database /// </summary> /// <param name="toolId">The id of the Tool to change</param> /// <param name="toolEdit">The new Tool, with id, to replace existing Tool</param> /// <returns></returns> public IHttpActionResult Put(int toolId, ToolEdit toolEdit) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateToolService(); if (!service.EditToolItem(toolId, toolEdit)) { return(InternalServerError()); } return(Ok()); }
public bool EditToolItem(int toolEditId, ToolEdit toolEdit) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Tools .Single(e => e.ToolID == toolEditId); entity.DailyRate = toolEdit.DailyRate; entity.HourlyRate = toolEdit.HourlyRate; entity.ToolCondition = toolEdit.ToolCondition; bool returnbool = false; int result = ctx.SaveChanges(); if (result == 1) { returnbool = true; } return(returnbool); } }