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 ReplaceLine(Guid id, Guid lineId, [FromQuery] int reqid, [FromBody] DocumentLine documentLine) { logger.LogInformation($"Looking for timesheet {id}"); Timecard timecard = repository.Find(id); if (timecard != null) { if (reqid != timecard.Employee) { return(StatusCode(403, new TimecardPersonError() { })); } if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } var annotatedLine = timecard.ReplaceLine(lineId, documentLine); repository.Update(timecard); return(Ok(annotatedLine)); } else { return(NotFound()); } }
public IActionResult UpdateLine(Guid id, string doclineId, [FromBody] DocumentLine documentLine) { Timecard timecard = repository.Find(id); if (timecard != null) { //CHECK ROLES if (timecard.Employee != documentLine.Employee) { return(StatusCode(403, new UnauthorizedAccess() { })); } if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } // REPLACE LINE var updatedLine = timecard.ReplaceLine(doclineId, documentLine); repository.Update(timecard); return(Ok(updatedLine)); } else { return(NotFound()); } }
public IActionResult ReplaceLine(string timecardId, string lineId, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(timecardId); if (timecard != null) { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } var existingLine = timecard.Lines.Where(t => t.UniqueIdentifier.ToString() == lineId).FirstOrDefault(); if (existingLine == null) { return(NotFound()); } var annotatedLine = timecard.ReplaceLine(existingLine, timecardLine); return(Ok(annotatedLine)); } else { return(NotFound()); } }
public IActionResult ReplaceLine(string timecardId, int lineId, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(timecardId); // Verify timecard exists if (timecard == null) { return(NotFound()); } // Verify state allows this action if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } // Perform the replacement var updatedLine = timecard.ReplaceLine(timecardLine, lineId); // Verify line was found and replacement occurred if (updatedLine == null) { return(NotFound()); } return(Ok(updatedLine)); }
public IActionResult ReplaceLine(Guid id, [FromBody] DocumentLine documentLine, Guid lineId) { 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(lineId)) { return(NotFound("Line Not Found")); } var annotatedLine = timecard.ReplaceLine(documentLine, lineId); repository.Update(timecard); return(Ok(annotatedLine)); } else { return(NotFound()); } }
public IActionResult Replace(string id, [FromBody] TimecardLine timecardLine, Guid uniqueIdentifier) { Timecard timecard = Database.Find(id); if (timecard != null) { if (timecard.Resource != timecardLine.Resource) { return(StatusCode(408, new InvalidResource() { })); } if (timecard.Status == TimecardStatus.Draft || timecard.Status == TimecardStatus.Cancelled) { var old_line = new AnnotatedTimecardLine(timecard.Lines .FirstOrDefault(t => t.UniqueIdentifier == uniqueIdentifier)); var annotatedLine = timecard.ReplaceLine(old_line, timecardLine, uniqueIdentifier); return(Ok(annotatedLine)); } else { return(StatusCode(409, new InvalidStateError() { })); } } else { return(NotFound()); } }
public IActionResult ReplaceLine(string id, [FromBody] TimecardPutLine timecardLine) { Timecard timecard = Database.Find(id); if (timecard != null) { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } var annotatedLine = timecard.ReplaceLine(timecard, timecardLine); if (annotatedLine == null) { return(NotFound()); } return(Ok(annotatedLine)); } else { return(NotFound()); } }
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, string docId, [FromBody] DocumentLine documentLine) { Timecard timecard = repository.Find(id); if (timecard.Employee != documentLine.Employee) { return(StatusCode(403, new UnauthorizedUserError() { })); } if (timecard == null) { return(NotFound(new NotFoundError())); } if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } //replacing old line with new line var newLine = timecard.ReplaceLine(docId, documentLine); repository.Update(timecard); return(Ok(newLine)); }
public IActionResult UpdateLine(string timecardId, string lineId, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(timecardId); if (timecard == null) { return(NotFound()); } if (timecard.Lines != null) { return(Ok(timecard.ReplaceLine(lineId, timecardLine))); } return(NotFound()); }
public IActionResult ReplaceLine(string timecardId, string lineId, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(timecardId); if (timecard == null) { return(NotFound()); } var annotatedLine = timecard.ReplaceLine(lineId, timecardLine); if (annotatedLine == null) { return(NotFound()); } else { return(Ok(annotatedLine)); } }
public IActionResult ReplaceLine(string timecardId, string lineId, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(timecardId); if (timecard == null) { return(NotFound()); } else if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new UpdateError() { })); } else { //find the line that matches lineId var match = timecard.Lines.FirstOrDefault(x => x.LineNumber.ToString() == lineId); if (match != null) { int index = (timecard.Lines.IndexOf(match)); timecard.ReplaceLine(index, timecardLine); } else { return(StatusCode(409, new MissingLineError() { })); } // var annotatedLine = timecard.(timecardLine); } if (timecard.Lines.Count < 1) { return(StatusCode(409, new EmptyTimecardError() { })); } return(Ok()); }
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)); }
// replace (POST) a complete line item public IActionResult Replace(string timecardId, string lineId, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(timecardId); if (timecard == null) { return(NotFound()); } if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } var Guid = new Guid(lineId); var oldLine = timecard.FindLineIndex(Guid); var annotatedLine = timecard.ReplaceLine(Guid, timecardLine); return(Ok(annotatedLine)); }
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 ReplaceLine(string timecardId, string lineId, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(timecardId); if (timecard == null) { return(NotFound()); } else { if (timecard.Status == TimecardStatus.Draft) { timecard.ReplaceLine(timecardLine, lineId); } else { return(StatusCode(409, new InvalidStateError() { })); } } return(Ok()); }