src/ZKEACMS/Currency/CurrencyStateProvider.cs

(完整代码) 1KB

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using Easy;
using Easy.Mvc.StateProviders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZKEACMS.Currency;
using ZKEACMS.Setting;

namespace ZKEACMS.Currency
{
    public class CurrencyStateProvider : IApplicationContextStateProvider
    {
        private readonly ICurrencyService _currencyService;
        private readonly IApplicationSettingService _applicationSettingService;

        public CurrencyStateProvider(ICurrencyService currencyService, IApplicationSettingService applicationSettingService)
        {
            _currencyService = currencyService;
            _applicationSettingService = applicationSettingService;
        }

        public string Name => "Currency";

        public Func<IApplicationContext, T> Get<T>()
        {
            var currencyOption = _applicationSettingService.Get<CurrencyOption>();
            CurrencyEntry currency = null;
            if (currencyOption.CurrencyID > 0)
            {
                currency = _currencyService.Get(currencyOption.CurrencyID);
            }
            else
            {
                currency = _currencyService.Get(m => m.Code == "CNY").FirstOrDefault();
            }
            if (currency == null)
            {
                currency = new CurrencyEntry
                {
                    Title = "Chinese Renmenbi",
                    Code = "CNY",
                    Symbol = "¥"
                };
            }
            currencyOption.CurrencyID = currency.ID;
            currencyOption.Name = currency.Title;
            currencyOption.Code = currency.Code;
            currencyOption.Symbol = currency.Symbol;
            return (context) =>
            {
                return (T)(object)currencyOption;
            };
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。