예제 #1
0
        public SystemCurrencySettingViewModel UpdateSystemCurrency(SystemCurrencySettingViewModel model)
        {
            ConditionFilter <Setting, long> condition = new ConditionFilter <Setting, long>
            {
                Query = (x => x.Key == "SystemCurrency")
            };
            var entity = this._SettingsRepository.Get(condition).ToList().FirstOrDefault();

            entity.Value = model.SystemCurrency = model.CurrencyId.ToString();
            entity       = this._SettingsRepository.Update(entity);
            this._unitOfWork.Commit();


            ConditionFilter <Currency, long> currencyCondition = new ConditionFilter <Currency, long>
            {
                Query = (x =>
                         x.Id == model.CurrencyId)
            };
            var currency = this._currencysRepository.Get(currencyCondition).FirstOrDefault();

            if (currency != null)
            {
                model.Currency = currency.ToLightModel();
            }

            return(model);
        }
예제 #2
0
        /// <summary>
        /// For posting
        /// </summary>
        /// <param name="origenalAmount"></param>
        /// <param name="currency"></param>
        /// <param name="systemCurrency"></param>
        /// <returns></returns>
        public LatestCurrencyRate GetLatestCurrencyRate(decimal origenalAmount, Currency currency,
                                                        SystemCurrencySettingViewModel systemCurrency)
        {
            LatestCurrencyRate latestCurrencyRate = new LatestCurrencyRate
            {
                NewAmount = origenalAmount
            };

            if (currency.Id != systemCurrency.CurrencyId)
            {
                var lates = this._CurrencyRatesRepository.Get(null)
                            .OrderByDescending(x => x.Date)
                            .Where(x => x.CurrencyId == currency.Id &&
                                   x.ExchangeCurrencyId == systemCurrency.CurrencyId)
                            //.ToList();
                            .FirstOrDefault();

                //CurrencyRate lates = null;
                //if (latesList != null) lates = latesList.FirstOrDefault();

                if (lates != null)
                {
                    latestCurrencyRate.NewAmount = origenalAmount * lates.Price;
                }

                var sysCurrency = this._currencysRepository.Get(systemCurrency.CurrencyId.Value);

                if (currency != null && lates != null && sysCurrency != null)
                {
                    latestCurrencyRate.AppendedDescriptionAr = $" [1 {currency.ChildTranslatedCurrencys.FirstOrDefault(x => x.Language == Language.Arabic)?.Name} = {lates.Price} {sysCurrency.ChildTranslatedCurrencys.FirstOrDefault(x => x.Language == Language.Arabic)?.Name}]";
                    latestCurrencyRate.AppendedDescriptionEn = $" [1 {currency.ChildTranslatedCurrencys.FirstOrDefault(x => x.Language == Language.English)?.Name} = {lates.Price} {sysCurrency.ChildTranslatedCurrencys.FirstOrDefault(x => x.Language == Language.English)?.Name}]";
                }
            }

            return(latestCurrencyRate);
        }
예제 #3
0
        /// <summary>
        /// عملة النظام
        /// </summary>
        /// <returns></returns>
        public SystemCurrencySettingViewModel GetSystemCurrency()
        {
            var keys   = this._SettingsRepository.Get().ToList();
            var result = new SystemCurrencySettingViewModel
            {
                SystemCurrency = keys.FirstOrDefault(k => k.Key == "SystemCurrency").Value,
            };

            if (string.IsNullOrEmpty(result.SystemCurrency) == false)
            {
                try
                {
                    result.CurrencyId = long.Parse(result.SystemCurrency);
                }
                catch (Exception ex)
                {
                }
            }

            if (result.CurrencyId.HasValue)
            {
                ConditionFilter <Currency, long> condition = new ConditionFilter <Currency, long>
                {
                    Query = (x =>
                             x.Id == result.CurrencyId)
                };
                var currency = this._currencysRepository.Get(condition).FirstOrDefault();

                if (currency != null)
                {
                    result.Currency = currency.ToLightModel();
                }
            }

            return(result);
        }