public async Task <IHttpActionResult> UpdateTool([FromBody] UpdateToolModel data) { Code status = default(Code); dynamic response = null; var dbObj = store .Tools .Where(t => t.ToolID == data.id) .FirstOrDefault(); int userID = UserSessionState.UserID(data.token).Value; if (dbObj != null) { dbObj.Name = data.name; dbObj.Cell = data.cell; dbObj.Count += data.count; if (data.count > 0) { store.Audits.Add(new Audit() { Action = (int)ToolAction.Add, Count = data.count, Readed = false, ToolID = dbObj.ToolID, WorkerID = store.Users.FirstOrDefault(u => u.WorkerID == userID).WorkerID, CreationDate = DateTimeOffset.UtcNow.DateTime, }); } if (data.low.HasValue) { dbObj.LowCount = data.low.Value; } if (data.lower.HasValue) { dbObj.LowerCount = data.lower.Value; } store.SaveChanges(); response = new { id = dbObj.ToolID, name = dbObj.Name, cell = dbObj.Cell, low = dbObj.LowCount, lower = dbObj.LowerCount, toolscount = dbObj.Count, toolsinuse = Math.Abs(ToolsHelper.ToolStatByToolID(store, dbObj.ToolID)), }; } else { status = Code.NotFound; } return(Ok(ApiResponseManager.CreateResponse(new Status(status), response))); }
public IActionResult Post(UpdateToolModel model) { var tool = _mapper.Map <Tool>(model); try { _toolService.Create(tool); return(Ok()); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }
public IActionResult Update(int id, [FromBody] UpdateToolModel model) { var tool = _mapper.Map <Tool>(model); tool.Id = id; try { _toolService.Update(tool); return(Ok()); } catch (AppException ex) { return(BadRequest(new { message = ex.Message })); } }