public IActionResult EditLog([FromRoute] string id, [FromForm] EditLogSettings settings) { MeditationLoggerApi api = ApiBridge.Instance; try { if (Guid.TryParse(id, out Guid guid)) { api.LogBook.EditLog(guid, settings); this.TempData[infoMessageKey] = "Log has been updated successfully."; } else { this.TempData[errorMessageKey] = $"Invalid ID: {id}."; } } catch (KeyNotFoundException e) { this.TempData[errorMessageKey] = e.Message; } catch (Exception e) { this.TempData[errorMessageKey] = e.Message; // Some other exception while editing happened, // but we know the key, so return to the edit page. return(Redirect($"/LogBook/Edit/{id}")); } return(Redirect($"/LogBook/Log/{id}")); }
public void EditLog(Guid id, EditLogSettings settings) { if (settings.TryValidate(out string errorString) == false) { throw new ValidationException(errorString); } lock (this.list) { if (this.logTable.ContainsKey(id) == false) { throw new KeyNotFoundException( $"Can not find log with ID {id}, can not edit." ); } Log log = this.logTable[id]; log.EditLog(settings); this.col.Update(log); // Need to rebuild our cache. // There's probably a more efficent way to do this. this.RefreshNoLock(); } }
public static bool TryValidate(this EditLogSettings settings, out string errorString) { bool success = true; StringBuilder builder = new StringBuilder(); if (settings.StartTime > settings.EndTime) { success = false; builder.AppendLine("Start Time can not be greater than the End Time."); } errorString = builder.ToString(); return(success); }
internal static void EditLog(this Log log, EditLogSettings settings) { log.StartTime = settings.StartTime; log.EndTime = settings.EndTime; log.Comments = settings.Comments; log.Technique = settings.Technique; if (settings.RemoveLocation) { log.Latitude = null; log.Longitude = null; } log.EditTime = DateTime.UtcNow; }