public IActionResult ReplaceLine(string id, Guid lineId, [FromBody] TimecardLine line) { Timecard timeCard = Database.Find(id); // if timecard not found, or line not in timecard, return not found if (timeCard == null || !timeCard.HasLine(lineId)) { return(NotFound()); } // if timecard isn't a draft, it can't be edited else if (timeCard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } else if (!timeCard.HasLine(lineId)) { return(NotFound()); } // This now completely replaces the existing line with // all of the input from POST parameter, so everything except // the ID changes. User must remember to change all parameters // since unincluded parameters are set to 0. TimecardLine resultLine = timeCard.ReplaceLine(lineId, line); return(Ok(resultLine)); }
public IActionResult UpdateLine(Guid id, Guid line_id, [FromBody] DocumentLine documentLine) { logger.LogInformation($"Looking for timesheet {id}"); Timecard timecard = repository.Find(id); if (timecard != null) { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } if (timecard.HasLine(documentLine) == false) { return(StatusCode(409, new InvalidLineUpdateError() { })); } var annotatedLine = timecard.UpdateLine(documentLine); repository.Update(timecard); return(Ok(annotatedLine)); } else { return(NotFound()); } }
public IActionResult UpdateLine(Guid id, Guid lineID, [FromBody] DocumentLine newline) { logger.LogInformation($"Looking for timesheet ID {id}"); Timecard tc = repository.Find(id); if (tc == null) { return(NotFound()); } if (tc.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } logger.LogInformation($"Looking for timecard line ID {lineID}"); if (tc.HasLine(lineID)) { var updatedLine = tc.UpdateLine(lineID, newline); repository.Update(tc); return(Ok(updatedLine)); } else { return(NotFound()); } }
public IActionResult GetLine(Guid timecardId, Guid lineId) { Timecard timecard = timesheetRepository.Find(timecardId); if (timecard == null) { logger.LogInformation($"timecard {timecardId} wasn't found"); return(NotFound()); } if (timecard.HasLine(lineId) == false) { // this might be better served by using some other 4xx error // because there's actually a problem with both the resource // we're updating and the request logger.LogInformation($"no matching lines found in collection"); return(NotFound()); } var line = timecard.Lines.First(l => l.UniqueIdentifier == lineId); if (line == null) { logger.LogInformation($"line {lineId} not found in timecard {timecardId}"); return(NotFound()); } // set the line's current status to the current timecard status // (timecard itself doesn't carry a current status and it's not // possible for the lines to have a persistent status, so...) line.TimecardStatus = timecard.Status; return(Ok(line)); }
public IActionResult UpdateLine(Guid timecardId, Guid lineId, [FromBody] dynamic timecardLine) { Timecard timecard = timesheetRepository.Find(timecardId); if (timecard == null) { return(NotFound()); } if (timecard.HasLine(lineId) == false) { // this might be better served by using some other 4xx error // because there's actually a problem with both the resource // we're updating and the request return(NotFound()); } if (CallerIdentity != timecard.Employee) { return(StatusCode(400, new InvalidIdentityError() { })); } var result = timecard.ReplaceLine(lineId, timecardLine); return(Ok(result)); }
public IActionResult UpdateLine(Guid id, Guid lineId, [FromBody] DocumentLine documentLine) { logger.LogInformation($"Looking for timesheet {id}"); Timecard timecard = repository.Find(id); if (timecard != null) { logger.LogInformation($"Looking for line {lineId}"); if (timecard.HasLine(lineId)) { var updatedLine = timecard.UpdatedLine(lineId, documentLine); repository.Update(timecard); return(Ok(updatedLine)); } else { return(NotFound()); } } else { return(NotFound()); } }
public IActionResult UpdateLine(Guid timesheetId, Guid lineId, [FromBody] DocumentLine documentLine) { logger.LogInformation($"Looking for timesheet {timesheetId} with line {lineId}"); Timecard timecard = repository.Find(timesheetId); if (timecard != null) { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } if (!timecard.HasLine(lineId)) { return(StatusCode(409, new LineNotFoundError() { })); } var updatedLine = timecard.updateLine(lineId, documentLine); repository.Update(timecard); return(Ok(updatedLine)); } else { return(NotFound()); } }
public IActionResult UpdateLine(Guid id, [FromBody] DocumentLine documentLine, Guid lineId) { logger.LogInformation($"Looking for timesheet {id} and line {lineId}"); Timecard timecard = repository.Find(id); if (timecard != null) { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } //update line if (timecard.HasLine(lineId)) { var updatedLine = timecard.UpdateLine(documentLine, lineId); repository.Update(timecard); return(Ok(updatedLine)); } } return(NotFound()); }
public IActionResult UpdateLine(string id, Guid lineId, [FromBody] JObject line) { Timecard timeCard = Database.Find(id); // if timecard not found, or line not in timecard, return not found if (timeCard == null || !timeCard.HasLine(lineId)) { return(NotFound()); } // if timecard isn't a draft, it can't be edited else if (timeCard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } else if (!timeCard.HasLine(lineId)) { return(NotFound()); } // This now tries to update only the parts of the line that are in // the PATCH parameters while trying to leave other fields unchanged // but if there's an error while parsing then return a 409. TimecardLine resultLine = new TimecardLine(); try { resultLine = timeCard.ReplaceLine(lineId, line); } catch (Exception e) { return(StatusCode(409, new InvalidStateError() { })); } return(Ok(resultLine)); }
public IActionResult UpdateLine(string timecardId, Guid lineId, [FromBody] dynamic timecardLine) { Timecard timecard = Database.Find(timecardId); if (timecard == null) { return(NotFound()); } if (timecard.HasLine(lineId) == false) { // this might be better served by using some other 4xx error // because there's actually a problem with both the resource // we're updating and the request return(NotFound()); } var result = timecard.ReplaceLine(lineId, timecardLine); return(Ok(result)); }
public IActionResult ReplaceLine(Guid timecardId, Guid lineId, [FromBody] DocumentLine documentLine) { logger.LogInformation($"Looking for timesheet {timecardId}"); Timecard timecard = repository.Find(timecardId); if (timecard != null) { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } logger.LogInformation($"Looking for the line {lineId}"); var getLineId = timecard.HasLine(lineId); if (!getLineId) { return(StatusCode(409, new LineNotFoundError() { })); } timecard.deleteLine(lineId); repository.Update(timecard); return(AddLine(timecardId, documentLine)); } else { return(NotFound()); } }
public IActionResult ReplaceLine(Guid id, [FromBody] DocumentLine documentLine, Guid lineId) { logger.LogInformation($"Looking for timesheet {id} and line {lineId}"); Timecard timecard = repository.Find(id); if (timecard != null) { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } //replace line if (timecard.HasLine(lineId)) { //remove the line if (timecard.RemoveLine(lineId)) { repository.Update(timecard); //add the new line return(AddLine(id, documentLine)); } else { //unable to remove line return(StatusCode(409, new RemoveLineError() { })); } } } return(NotFound()); }