public IActionResult UpdateItem(string id, int lineNum, [FromBody] TimecardLine line) { // API to update the line item/items. var timecard = Database.Find(id); if (timecard != null) { /* * The patch here takes into account those values which are not default values anymore. * However, the day can be changed back to sunday even though it is a default value. * The update works based on the line number. * For partial update I could also use JSON Patch which would be perfect in these situations * but was not sure since it would require the installation of a library. */ if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } var annotatedLine = timecard.updateLineItem(line, lineNum); return(Ok(annotatedLine)); } else { return(NotFound()); } }
public IActionResult ReplaceLineById(Guid id, Guid lineid, [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() { })); } var line = timecard.Lines .Where(l => l.UniqueIdentifier == lineid) .FirstOrDefault(); timecard.Lines.Remove(line); TimecardLine newLine = timecard.AddLine(documentLine); repository.Update(timecard); return(Ok(newLine)); } else { return(NotFound()); } }
public IActionResult AddLine(string id, int resourceID, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(id); if (timecard != null) { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } if (timecard.Resource != resourceID) { return(StatusCode(409, new InvalidAccessError() { })); } var annotatedLine = timecard.AddLine(timecardLine); return(Ok(annotatedLine)); } else { return(NotFound()); } }
public IActionResult ReplaceALine(string id, string lineUniqueId, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(id); if (timecard == null) { return(NotFound()); } else { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } var lineInTimeCard = timecard.FindALine(new Guid(lineUniqueId)); if (lineInTimeCard == null) { return(NotFound()); } else { lineInTimeCard.ReplaceALine(timecardLine); return(Ok(lineInTimeCard)); } } }
public IActionResult ReplaceLines(string id, string lineId, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(id); if (timecard != null) { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } var annotatedLine = timecard.GetLine(new Guid(lineId)); if (annotatedLine != null) { annotatedLine.ReplaceLineInfo(timecardLine); return(Ok(annotatedLine)); } else { return(NotFound()); } } 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 replaceLine = timecard.Lines.Where(t => t.UniqueIdentifier.ToString() == lineId).FirstOrDefault(); if (replaceLine == null) { return(NotFound()); } var annotatedLine = timecard.ReplaceLine(replaceLine, timecardLine); return(Ok(annotatedLine)); } else { return(NotFound()); } }
//Path a entry in the line for the given line id from the specified timesheet public IActionResult PatchLine(Guid id, Guid lineId, [FromBody] DocumentLine documentLine) { logger.LogInformation($"Looking for timesheet {id}"); logger.LogInformation($"Looking for Line {lineId}"); logger.LogInformation($"Looking for Doc Line {documentLine}"); Timecard timecard = repository.Find(id); if (timecard != null) { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } TimecardLine line = timecard.Lines .FirstOrDefault(l => l.UniqueIdentifier == lineId); if (line == null) { return(NotFound()); } if (documentLine.Week != 0) { line.Week = documentLine.Week; } if (documentLine.Year != 0) { line.Year = documentLine.Year; } if (documentLine.Hours != 0.0) { line.Hours = documentLine.Hours; } if (documentLine.Day != DayOfWeek.Sunday) { line.Day = documentLine.Day; } if (documentLine.Project.Length != 0) { line.Project = documentLine.Project; } repository.Update(timecard); return(Ok(line)); } else { return(NotFound()); } }
public IActionResult UpdateLine(string timecardId, string lineId, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(timecardId); if (timecard == null) { return(NotFound()); } return(Ok()); }
//need to removed before final submission public TimecardLine FindLine(Guid id) { TimecardLine timecardlines = null; using (var database = new LiteDatabase(DATABASE_FILE)) { var timelines = database.GetCollection <TimecardLine>("timeslines"); timecardlines = timelines .FindOne(t => t.UniqueIdentifier == id); } return(timecardlines); }
public IActionResult UpdateLine(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) { timecard.UpdateLine(timecard.Lines.IndexOf(match), timecardLine); } else { return(StatusCode(409, new MissingLineError() { })); } //FIXME: UpdateLine updates all fields to match those passed into the request, so later versions should // allow for some fields to be left blank. null cases are also not accounted for in this version. // The likely next iteration might include some kind of overloading and/or checking each field // in timecardLine, and flagging (with a -1, perhaps) and checking for that flag upon setting, // where nulls would be flagged as -1 as well, so as not to be updated. Removal of information // is not possible in this scheme. } if (timecard.Lines.Count < 1) { return(StatusCode(409, new EmptyTimecardError() { })); } return(Ok()); }
public IActionResult GetLine(Guid id, Guid lineId) { logger.LogInformation($"Looking for timesheet {id}"); Timecard timecard = repository.Find(id); if (timecard != null) { TimecardLine line = timecard.FindLine(lineId); if (line != null) { return(Ok(line)); } } 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 Update(Guid id, string lineId, [FromBody] TimecardLine tcl) { Timecard timecard = repository.Find(id); if (timecard == null) { return(NotFound()); } if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } var update = tcl.ReplaceLine(lineId, tcl); return(Ok(update)); }
public IActionResult ReplaceLine(string timecardId, Guid lineId, [FromBody] TimecardLine 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(string id, int ArrayIndex, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(id); if (timecard != null) { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } var annotatedLine = timecard.ReplaceLine(ArrayIndex, timecardLine); return(Ok(annotatedLine)); } else { return(NotFound()); } }
public IActionResult ReplaceLine(string id, int lineNum, [FromBody] TimecardLine timecardLine) { // API to replace a line completely. var timecard = Database.Find(id); if (timecard != null) { if (timecard.Status != TimecardStatus.Draft) { return(StatusCode(409, new InvalidStateError() { })); } var annotatedLine = timecard.replaceLine(timecardLine, lineNum); return(Ok(annotatedLine)); } else { return(NotFound()); } }
// replace (POST) a complete line item public IActionResult Update(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.UpdateLine(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 UpdateLine(string timecardId, string lineId, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(timecardId); if (timecard == null) { return(NotFound()); } else { if (timecard.Status == TimecardStatus.Draft) { return(Ok(timecard.UpdateLine(timecardLine, lineId))); } else { return(StatusCode(409, new InvalidStateError() { })); } } }
//Get a single line for the line id freom the specified timesheet public IActionResult GetLine(Guid id, Guid lineId) { logger.LogInformation($"Looking for Line {lineId}"); Timecard timecard = repository.Find(id); if (timecard != null) { TimecardLine line = timecard.Lines .SingleOrDefault(l => l.UniqueIdentifier == lineId); if (line == null) { return(NotFound()); } return(Ok(line)); } else { return(NotFound()); } }
//[ProducesResponseType(typeof(InvalidStateError), 409)] public IActionResult UpdateLineItem(Guid id, Guid lineid, [FromBody] JObject documentLine) { logger.LogInformation($"Looking for lineid {lineid}"); Timecard timecard = repository.Find(id); TimecardLine annotatedLine = null; if (timecard != null) { // TBD: Need to handle the case when the lineid is invalid foreach (var line in timecard.Lines) { if (line.UniqueIdentifier == lineid) { annotatedLine = line.Update(documentLine); } } // Invalid lineid if (annotatedLine != null) { repository.Update(timecard); return(Ok(annotatedLine)); } else { return(NotFound(string.Format("Timecard line {0}.", lineid))); } } else { // Timecard not found return(NotFound()); } }
public IActionResult UpdateLine(string timecardId, string lineId, int resourceID, [FromBody] TimecardLine timecardLine) { Timecard timecard = Database.Find(timecardId); if (timecard == null) { return(NotFound()); } // checking if resource is authorized if (timecard.Resource != resourceID) { return(StatusCode(409, new InvalidAccessError() { })); } //updating/replacing the line entry in timecard var annotatedLine = timecard.UpdateLine(lineId, timecardLine); if (annotatedLine == null) { return(NotFound()); } else { return(Ok(annotatedLine)); } }