elfisa-pharmacy/src/Elfisa.Core/SettingsStore.cs
Exest c677345ba6 Avalonia: общая корзина, добавление из Прайс-листа, Настройки
- CartService: единая корзина для Прайс-листа и Отправить
- Прайс-лист: выбор позиции + кол-во + «Добавить в заказ», индикатор корзины
- Настройки (диалог ⚙ в шапке): адрес API, тема (свет/тьма, применяется
  сразу), грузополучатель по умолчанию; сохранение в %APPDATA%
- SettingsStore (Core) + AppConfig читает сохранённый API-адрес
- тема применяется на старте

Проверено вживую: добавление из Прайс-листа в корзину, диалог настроек.
Реальная отправка заказа (POST) — собрана и связана, живой заказ по явному «да»
(автозащита блокирует боевую транзакцию без подтверждения).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-08 11:26:53 +03:00

45 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Text.Json;
namespace Elfisa.Core;
public sealed class AppSettings
{
public string? ApiBaseUrl { get; set; }
public string Theme { get; set; } = "Light"; // Light | Dark
public string? DefaultLocationId { get; set; }
public string? Token { get; set; } // сохранённая сессия
public string? Role { get; set; }
public string? Username { get; set; }
}
/// <summary>Настройки приложения в %APPDATA%\ElfisaAvalonia\settings.json.</summary>
public static class SettingsStore
{
private static readonly string Dir =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ElfisaAvalonia");
private static readonly string File = Path.Combine(Dir, "settings.json");
public static AppSettings Current { get; private set; } = Load();
public static AppSettings Load()
{
try
{
if (System.IO.File.Exists(File))
return JsonSerializer.Deserialize<AppSettings>(System.IO.File.ReadAllText(File)) ?? new AppSettings();
}
catch { /* повреждённый файл — начинаем с чистых настроек */ }
return new AppSettings();
}
public static void Save()
{
try
{
Directory.CreateDirectory(Dir);
System.IO.File.WriteAllText(File, JsonSerializer.Serialize(Current, new JsonSerializerOptions { WriteIndented = true }));
}
catch { /* нет прав/диска — молча пропускаем */ }
}
}