コード例 #1
0
        public IActionResult Edit([FromRoute] string id)
        {
            MeditationLoggerApi api = ApiBridge.Instance;

            Log log;

            if (Guid.TryParse(id, out Guid guid))
            {
                log = api.LogBook.TryGetLog(guid);
            }
            else
            {
                log = null;
            }

            var model = new LogModel(
                Api: api,
                Log: log,
                InfoMessage: this.TempData[infoMessageKey]?.ToString() ?? string.Empty,
                ErrorMessage: this.TempData[errorMessageKey]?.ToString() ?? string.Empty
                );

            ViewData["Title"] = "Editing: " + log.ToTitleString(api.Settings.DateTimeSettings);
            return(View(model));
        }
コード例 #2
0
        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}"));
        }
コード例 #3
0
        [HttpPost] // <- Delete is not supported by forms.  So use a POST.
        public IActionResult DeleteLog([FromRoute] string id)
        {
            MeditationLoggerApi api = ApiBridge.Instance;

            Log    log         = null;
            string errorString = string.Empty;

            try
            {
                if (Guid.TryParse(id, out Guid guid))
                {
                    log = api.LogBook.DeleteLog(guid);
                }

                if (log is null)
                {
                    this.TempData[errorMessageKey] = "Could not delete log, ID not found.";
                }
            }
            catch (Exception e)
            {
                this.TempData[errorMessageKey] = e.Message;
            }

            // When a log is deleted, we want to go back to the main
            // logbook page, as there is no log to redirect to.
            if (log is not null)
            {
                this.TempData[infoMessageKey] = $"Deleted log: {log.ToTitleString( api.Settings.DateTimeSettings )}";
            }

            return(RedirectToAction(nameof(Index)));
        }
コード例 #4
0
 /// <summary>
 /// Creates the single instance of the bridge to the API.
 /// </summary>
 /// <exception cref="InvalidOperationException">Called if called when an instance already exists.</exception>
 public static void CreateInstance(string databaseLocation, string settingsFile)
 {
     if (Instance != null)
     {
         throw new InvalidOperationException("Instance already created!");
     }
     Instance = new MeditationLoggerApi(databaseLocation, settingsFile);
 }
コード例 #5
0
        // ---------------- Functions ----------------

        public IActionResult Index()
        {
            ViewData["Title"] = "Logbook";

            MeditationLoggerApi api = ApiBridge.Instance;

            var model = new LogBookModel(
                Api: api,
                InfoMessage: this.TempData[infoMessageKey]?.ToString() ?? string.Empty,
                ErrorMessage: this.TempData[errorMessageKey]?.ToString() ?? string.Empty
                );

            return(View(model));
        }