protected void UpdateLocales(Currency currency, CurrencyModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(currency,
                                                        x => x.Name,
                                                        localized.Name,
                                                        localized.LanguageId);
     }
 }
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCurrencies))
                return AccessDeniedView();

            var model = new CurrencyModel();
            //locales
            AddLocales(_languageService, model.Locales);
            //default values
            model.Published = true;
            model.Rate = 1;
            return View(model);
        }
        protected virtual void PrepareStoresMappingModel(CurrencyModel model, Currency currency, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            model.AvailableStores = _storeService
                .GetAllStores()
                .Select(s => s.ToModel())
                .ToList();
            if (!excludeProperties)
            {
                if (currency != null)
                {
                    model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(currency);
                }
            }
        }
        protected virtual void PrepareStoresMappingModel(CurrencyModel model, Currency currency, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            if (!excludeProperties && currency != null)
                model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(currency).ToList();

            var allStores = _storeService.GetAllStores();
            foreach (var store in allStores)
            {
                model.AvailableStores.Add(new SelectListItem
                {
                    Text = store.Name,
                    Value = store.Id.ToString(),
                    Selected = model.SelectedStoreIds.Contains(store.Id)
                });
            }
        }
Esempio n. 5
0
		public ApplicationAdminModel()
		{
			Currency = new CurrencyModel();
		}
        public async Task <bool> Validate()
        {
            if (string.IsNullOrEmpty(this.Name))
            {
                await DialogHelper.ShowMessage(Resources.InventoryNameRequired);

                return(false);
            }

            InventoryModel dupeInventory = ChannelSession.Settings.Inventory.Values.FirstOrDefault(c => c.Name.Equals(this.Name));

            if (dupeInventory != null && (this.inventory == null || !this.inventory.ID.Equals(dupeInventory.ID)))
            {
                await DialogHelper.ShowMessage(Resources.InventoryNameDuplicate);

                return(false);
            }

            CurrencyModel dupeCurrency = ChannelSession.Settings.Currency.Values.FirstOrDefault(c => c.Name.Equals(this.Name));

            if (dupeCurrency != null)
            {
                await DialogHelper.ShowMessage(Resources.CurrencyRankNameDuplicate);

                return(false);
            }

            if (this.DefaultItemMaxAmount <= 0)
            {
                await DialogHelper.ShowMessage(Resources.DefaultMaxGreaterThanZero);

                return(false);
            }

            if (this.Items.Count() == 0)
            {
                await DialogHelper.ShowMessage(Resources.OneItemRequired);

                return(false);
            }

            if (this.ShopEnabled)
            {
                if (string.IsNullOrEmpty(this.ShopCommandText))
                {
                    await DialogHelper.ShowMessage(Resources.CommandNameRequiredForShop);

                    return(false);
                }

                if (this.SelectedShopCurrency == null)
                {
                    await DialogHelper.ShowMessage(Resources.ShopCurrencyRequired);

                    return(false);
                }
            }

            if (this.TradeEnabled)
            {
                if (string.IsNullOrEmpty(this.TradeCommandText))
                {
                    await DialogHelper.ShowMessage(Resources.TradingCommandRequired);

                    return(false);
                }
            }

            return(true);
        }
Esempio n. 7
0
 public static Currency ToEntity(this CurrencyModel model)
 {
     return(model.MapTo <CurrencyModel, Currency>());
 }
Esempio n. 8
0
 public CurrencyRequirementViewModel(CurrencyModel currency, RankModel rank, bool mustEqual = false)
 {
     this.CurrencyID = currency.ID;
     this.RankName   = rank.Name;
     this.MustEqual  = mustEqual;
 }
Esempio n. 9
0
 public CurrencyRequirementViewModel(CurrencyModel currency, int minimumAmount, int maximumAmount)
     : this(currency, CurrencyRequirementTypeEnum.MinimumAndMaximum, minimumAmount)
 {
     this.MaximumAmount = maximumAmount;
 }
        public TreasureDefenseGameEditorControl(CurrencyModel currency)
        {
            InitializeComponent();

            this.viewModel = new TreasureDefenseGameEditorControlViewModel(currency);
        }
        public async Task <ActionResult <TransactionEntity> > NewTransaction(TransactionModel transaction)
        {
            _logger.LogInformation($"Invoking TransactionController.NewTransaction: {JsonConvert.SerializeObject(transaction)}");

            if (transaction.CurrencyCode == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorModel(_logger, "CurrencyCode cannot be null.")));
            }

            if (transaction.Amount <= 0)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorModel(_logger, "Amount must to be more than 0.")));
            }

            CurrencyRepository currencyRepository = CurrencyRepository.GetCurrencyRepositoryByISO(transaction.CurrencyCode);

            if (currencyRepository == null)
            {
                return(StatusCode(StatusCodes.Status501NotImplemented, new ErrorModel(_logger, "Sorry, the currency specified is not implemented yet.")));
            }

            // get selected currency
            CurrencyModel currencyModel = await currencyRepository.GetCurrency();

            if (currencyModel == null)
            {
                return(StatusCode(StatusCodes.Status501NotImplemented, new ErrorModel(_logger, "Sorry, the currency specified is unavailable.")));
            }

            // find user
            UserEntity user = this._context.Users.AsNoTracking().Include(u => u.Transactions)
                              .Where(u => u.Id == transaction.UserId).FirstOrDefault();

            if (user == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorModel(_logger, "User not found.")));
            }

            decimal  currentAmountPurchased = transaction.Amount / currencyModel.PurchasePrice;
            DateTime lastMonth = DateTime.Now.AddMonths(-1);
            decimal  userTotalPurchasesFromLastMonth = user.Transactions
                                                       .Where(t => t.CreatedAt >= lastMonth)
                                                       .Where(t => t.CurrencyCode == currencyModel.ISO)
                                                       .Sum(t => t.AmountPurchased);

            if ((userTotalPurchasesFromLastMonth + currentAmountPurchased) >= currencyRepository.GetPurchaseLimit())
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorModel(_logger, $"You cannot purchase more than {currencyRepository.GetPurchaseLimit()} {currencyRepository.GetISO()} per month.")));
            }

            TransactionEntity trans = new TransactionEntity();

            trans.Amount          = transaction.Amount;
            trans.AmountPurchased = currentAmountPurchased;
            trans.CurrencyCode    = currencyModel.ISO;
            trans.CreatedAt       = DateTime.Now;
            trans.UserId          = transaction.UserId;

            this._context.Transactions.Add(trans);
            this._context.SaveChanges();

            return(trans);
        }
 public RankRequirementModel(CurrencyModel rankSystem, RankModel rank, RankRequirementMatchTypeEnum matchType = RankRequirementMatchTypeEnum.GreaterThanOrEqualTo)
 {
     this.RankSystemID = rankSystem.ID;
     this.RankName     = rank.Name;
     this.MatchType    = matchType;
 }
Esempio n. 13
0
        public WalletPage()
        {
            db = DataAccess.GetDB;

            wallet = db.GetWalletEntries();

            currencies        = db.GetAllCurrency();
            euroC             = Utils.GetEuroCurrency(currencies);
            mainC             = Utils.GetMainCurrency(currencies);
            mainCurrencyIndex = Utils.GetMainCurrencyIndex(currencies);
            selectedC         = currencies[mainCurrencyIndex];

            colors = CreateColorsList();

            // Calculate Total Wallet Value

            UpdateWalletValue();

            Title = "Wallet";

            mainLayout = new StackLayout()
            {
            };

            header = new Label
            {
                Text = "Wallet Value: " + string.Format("{0:0.00}", walletValue) + " " + mainC.code,
                Font = Font.BoldSystemFontOfSize(20),
                HorizontalOptions = LayoutOptions.Center
            };

            currencyPicker = new Picker();
            Device.OnPlatform(
                Android: () => currencyPicker = new Picker()
            {
                Title             = "Currency",
                WidthRequest      = 100,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
            },
                WinPhone: () => currencyPicker = new Picker()
            {
                Title             = "Currency",
                WidthRequest      = 100,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center
            }
                );

            foreach (CurrencyModel c in currencies)
            {
                currencyPicker.Items.Add(c.code);
            }

            currencyPicker.SelectedIndex         = mainCurrencyIndex;
            currencyPicker.SelectedIndexChanged += OnCurrencyPickerChanged;

            UpdateChart();

            ToolbarItem addRemoveToolbarItem = new ToolbarItem();

            Device.OnPlatform(
                Android: () => addRemoveToolbarItem = new ToolbarItem()
            {
                Text  = "Add/Remove Currency",
                Order = ToolbarItemOrder.Secondary
            },
                WinPhone: () => addRemoveToolbarItem = new ToolbarItem()
            {
                Text  = "Add/Remove Currency",
                Order = ToolbarItemOrder.Secondary
            }
                );
            addRemoveToolbarItem.Clicked += OnClickedAddRemoveToolbarItem;

            ToolbarItem ratesToolbarItem = new ToolbarItem();

            Device.OnPlatform(
                Android: () => ratesToolbarItem = new ToolbarItem()
            {
                Text  = "Currency Rates",
                Order = ToolbarItemOrder.Primary
            },
                WinPhone: () => ratesToolbarItem = new ToolbarItem()
            {
                Text  = "Currency Rates",
                Order = ToolbarItemOrder.Secondary
            }
                );
            ratesToolbarItem.Clicked += OnClickedRatesToolbarItem;

            ToolbarItems.Add(addRemoveToolbarItem);
            ToolbarItems.Add(ratesToolbarItem);

            mainLayout.Children.Add(currencyPicker);
            mainLayout.Children.Add(header);
            mainLayout.Children.Add(chart);

            Content = mainLayout;
        }
Esempio n. 14
0
        private void UpdateChart()
        {
            chart = new StackLayout()
            {
            };

            chart.Orientation       = StackOrientation.Vertical;
            chart.VerticalOptions   = LayoutOptions.CenterAndExpand;
            chart.HorizontalOptions = LayoutOptions.CenterAndExpand;

            StackLayout bars = new StackLayout()
            {
            };

            bars.Orientation = StackOrientation.Horizontal;

            bars.HeightRequest = 250;

            for (int i = 0; i < wallet.Count; i++)
            {
                CurrencyModel walletCurrency = GetWalletCurrency(wallet[i]);

                Debug.WriteLine("Percentagem de " + walletCurrency.code + ": " + Math.Round(250 * ((wallet[i].amount / Utils.ConvertValue(euroC, mainC, walletCurrency)) / walletValue)));

                BoxView box = new BoxView();
                Device.OnPlatform(
                    Android: () => box = new BoxView()
                {
                    Color           = colors[i],
                    WidthRequest    = 260 / wallet.Count,
                    HeightRequest   = Math.Round(250 * ((wallet[i].amount / Utils.ConvertValue(euroC, mainC, walletCurrency)) / walletValue)),
                    VerticalOptions = LayoutOptions.End
                },
                    WinPhone: () => box = new BoxView()
                {
                    Color           = colors[i],
                    WidthRequest    = 600 / wallet.Count,
                    HeightRequest   = Math.Round(250 * ((wallet[i].amount / Utils.ConvertValue(euroC, mainC, walletCurrency)) / walletValue)),
                    VerticalOptions = LayoutOptions.End
                }
                    );

                bars.Children.Add(box);
            }

            StackLayout walletAmounts = new StackLayout()
            {
            };

            walletAmounts.Orientation = StackOrientation.Horizontal;

            for (int i = 0; i < wallet.Count; i++)
            {
                Label amountLabel = new Label();
                Device.OnPlatform(
                    Android: () => amountLabel = new Label()
                {
                    Text                    = "" + wallet[i].amount,
                    WidthRequest            = 260 / wallet.Count,
                    HeightRequest           = 20,
                    HorizontalTextAlignment = TextAlignment.Center,
                    Font                    = Font.SystemFontOfSize(NamedSize.Micro),
                },
                    WinPhone: () => amountLabel = new Label()
                {
                    Text                    = "" + wallet[i].amount,
                    WidthRequest            = 600 / wallet.Count,
                    HeightRequest           = 20,
                    HorizontalTextAlignment = TextAlignment.Center
                }
                    );

                walletAmounts.Children.Add(amountLabel);
            }

            StackLayout barsLabels = new StackLayout()
            {
            };

            barsLabels.Orientation = StackOrientation.Horizontal;

            for (int i = 0; i < wallet.Count; i++)
            {
                Font barLabelFont;

                if (wallet.Count == 11)
                {
                    barLabelFont = Font.SystemFontOfSize(NamedSize.Micro);
                }
                else
                {
                    barLabelFont = Font.SystemFontOfSize(NamedSize.Small);
                }

                Label boxLabel = new Label();
                Device.OnPlatform(
                    Android: () => boxLabel = new Label()
                {
                    Text                    = wallet[i].code,
                    WidthRequest            = 260 / wallet.Count,
                    HeightRequest           = 20,
                    HorizontalTextAlignment = TextAlignment.Center,
                    Font                    = barLabelFont,
                },
                    WinPhone: () => boxLabel = new Label()
                {
                    Text                    = wallet[i].code,
                    WidthRequest            = 600 / wallet.Count,
                    HeightRequest           = 20,
                    HorizontalTextAlignment = TextAlignment.Center
                }
                    );

                barsLabels.Children.Add(boxLabel);
            }

            BoxView divider = new BoxView();

            Device.OnPlatform(
                Android: () => {
                divider = new BoxView()
                {
                    Color = Color.FromHex("#3498DB"), WidthRequest = 260, HeightRequest = 2
                };
            },
                WinPhone: () =>
            {
                divider = new BoxView()
                {
                    Color = Color.Black, WidthRequest = 600, HeightRequest = 2
                };
            }
                );

            StackLayout convertedLabels = new StackLayout()
            {
            };

            convertedLabels.Orientation = StackOrientation.Horizontal;

            for (int i = 0; i < wallet.Count; i++)
            {
                CurrencyModel walletCurrency = GetWalletCurrency(wallet[i]);

                Label convertedLabel = new Label();
                Device.OnPlatform(
                    Android: () => convertedLabel = new Label()
                {
                    Text                    = string.Format("{0:0.00}", wallet[i].amount / Utils.ConvertValue(euroC, mainC, walletCurrency)),
                    WidthRequest            = 260 / wallet.Count,
                    HeightRequest           = 20,
                    HorizontalTextAlignment = TextAlignment.Center,
                    Font                    = Font.SystemFontOfSize(NamedSize.Micro),
                },
                    WinPhone: () => convertedLabel = new Label()
                {
                    Text                    = string.Format("{0:0.00}", wallet[i].amount / Utils.ConvertValue(euroC, mainC, walletCurrency)),
                    WidthRequest            = 600 / wallet.Count,
                    HeightRequest           = 20,
                    HorizontalTextAlignment = TextAlignment.Center
                }
                    );

                convertedLabels.Children.Add(convertedLabel);
            }

            StackLayout selectedCurrencyLabels = new StackLayout()
            {
            };

            selectedCurrencyLabels.Orientation = StackOrientation.Horizontal;

            for (int i = 0; i < wallet.Count; i++)
            {
                Font selectedLabelFont;

                if (wallet.Count == 11)
                {
                    selectedLabelFont = Font.SystemFontOfSize(NamedSize.Micro);
                }
                else
                {
                    selectedLabelFont = Font.SystemFontOfSize(NamedSize.Small);
                }

                Label selectedLabel = new Label();
                Device.OnPlatform(
                    Android: () => selectedLabel = new Label()
                {
                    Text                    = currencies[currencyPicker.SelectedIndex].code,
                    WidthRequest            = 260 / wallet.Count,
                    HeightRequest           = 20,
                    HorizontalTextAlignment = TextAlignment.Center,
                    Font                    = selectedLabelFont,
                },
                    WinPhone: () => selectedLabel = new Label()
                {
                    Text                    = currencies[currencyPicker.SelectedIndex].code,
                    WidthRequest            = 600 / wallet.Count,
                    HeightRequest           = 20,
                    HorizontalTextAlignment = TextAlignment.Center
                }
                    );

                selectedCurrencyLabels.Children.Add(selectedLabel);
            }

            chart.Children.Add(bars);
            chart.Children.Add(walletAmounts);
            chart.Children.Add(barsLabels);
            chart.Children.Add(divider);
            chart.Children.Add(convertedLabels);
            chart.Children.Add(selectedCurrencyLabels);
        }
Esempio n. 15
0
        public ActionResult CreateCurrnecy()
        {
            var currency = new CurrencyModel();

            return(View(currency));
        }
Esempio n. 16
0
 public void Update(CurrencyModel product)
 {
     _currencyService.Update(product);
 }
Esempio n. 17
0
 public void Create(CurrencyModel product)
 {
     _currencyService.Create(product);
 }
Esempio n. 18
0
 public IActionResult ExchangeMoney([FromRoute] int id, MoneyModel money, CurrencyModel to)
 {
     _user.ExchangeMoney(id, money, to);
     return(Ok());
 }
Esempio n. 19
0
        public RouletteGameEditorControl(CurrencyModel currency)
        {
            InitializeComponent();

            this.viewModel = new RouletteGameEditorControlViewModel(currency);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CurrenciesModel"/> class.
 /// </summary>
 /// <param name="selectedCurrency">The selected currency.</param>
 /// <param name="currencies">The currencies.</param>
 public CurrenciesModel(string selectedCurrency, CurrencyModel[] currencies)
 {
     SelectedCurrency = selectedCurrency;
     Currencies = currencies;
 }
        public void ProcessData(CurrencyModel currency, CurrencyModel rank)
        {
            this.Requirements = new RequirementViewModel();

            if (this.Cooldown > 0)
            {
                this.Requirements.Cooldown = new CooldownRequirementViewModel(CooldownTypeEnum.Individual, this.Cooldown);
            }

            if (!string.IsNullOrEmpty(this.Permission))
            {
                switch (this.Permission)
                {
                case "Subscriber":
                    this.Requirements.Role = new RoleRequirementViewModel(UserRoleEnum.Subscriber);
                    break;

                case "Moderator":
                    this.Requirements.Role = new RoleRequirementViewModel(UserRoleEnum.Mod);
                    break;

                case "Editor":
                    this.Requirements.Role = new RoleRequirementViewModel(UserRoleEnum.ChannelEditor);
                    break;

                case "Min_Points":
                    this.Requirements.Role = new RoleRequirementViewModel(UserRoleEnum.User);
                    if (!string.IsNullOrEmpty(this.PermInfo) && int.TryParse(this.PermInfo, out int cost))
                    {
                        this.Requirements.Currency = new CurrencyRequirementViewModel(currency, cost);
                    }
                    break;

                case "Min_Rank":
                    this.Requirements.Role = new RoleRequirementViewModel(UserRoleEnum.User);
                    if (!string.IsNullOrEmpty(this.PermInfo))
                    {
                        RankModel minRank = rank.Ranks.FirstOrDefault(r => r.Name.ToLower().Equals(this.PermInfo.ToLower()));
                        if (minRank != null)
                        {
                            this.Requirements.Rank = new CurrencyRequirementViewModel(rank, minRank);
                        }
                    }
                    break;

                default:
                    this.Requirements.Role = new RoleRequirementViewModel(UserRoleEnum.User);
                    break;
                }
            }

            this.Response = SpecialIdentifierStringBuilder.ConvertStreamlabsChatBotText(this.Response);

            int readCount = 1;

            this.Response = this.GetRegexEntries(this.Response, ReadLineRegexHeaderPattern, (string entry) =>
            {
                string si = "read" + readCount;
                this.Actions.Add(new FileAction(FileActionTypeEnum.ReadFromFile, si, entry));
                readCount++;
                return("$" + si);
            });

            this.Response = this.GetRegexEntries(this.Response, ReadRandomLineRegexHeaderPattern, (string entry) =>
            {
                string si = "read" + readCount;
                this.Actions.Add(new FileAction(FileActionTypeEnum.ReadRandomLineFromFile, si, entry));
                readCount++;
                return("$" + si);
            });

            this.Response = this.GetRegexEntries(this.Response, ReadRandomLineRegexHeaderPattern, (string entry) =>
            {
                string si = "read" + readCount;

                string[] splits        = entry.Split(new char[] { ',' });
                FileAction action      = new FileAction(FileActionTypeEnum.ReadSpecificLineFromFile, si, splits[0]);
                action.LineIndexToRead = splits[1];
                this.Actions.Add(action);

                readCount++;
                return("$" + si);
            });

            int webRequestCount = 1;

            this.Response = this.GetRegexEntries(this.Response, ReadAPIRegexHeaderPattern, (string entry) =>
            {
                string si = "webrequest" + webRequestCount;
                this.Actions.Add(WebRequestAction.CreateForSpecialIdentifier(entry, si));
                webRequestCount++;
                return("$" + si);
            });

            this.Response = this.GetRegexEntries(this.Response, SaveToFileRegexHeaderPattern, (string entry) =>
            {
                string[] splits        = entry.Split(new char[] { ',' });
                FileAction action      = new FileAction(FileActionTypeEnum.AppendToFile, splits[1], splits[0]);
                action.LineIndexToRead = splits[1];
                this.Actions.Add(action);
                return(string.Empty);
            });

            this.Response = this.GetRegexEntries(this.Response, OverwriteFileRegexHeaderPattern, (string entry) =>
            {
                string[] splits        = entry.Split(new char[] { ',' });
                FileAction action      = new FileAction(FileActionTypeEnum.SaveToFile, splits[1], splits[0]);
                action.LineIndexToRead = splits[1];
                this.Actions.Add(action);
                return(string.Empty);
            });

            ChatAction chat = new ChatAction(this.Response);

            if (!string.IsNullOrEmpty(this.Usage) && this.Usage.Equals("SW"))
            {
                chat.IsWhisper = true;
            }
            this.Actions.Add(chat);
        }
Esempio n. 22
0
 protected void SaveStoreMappings(Currency currency, CurrencyModel model)
 {
     var existingStoreMappings = _storeMappingService.GetStoreMappings(currency);
     var allStores = _storeService.GetAllStores();
     foreach (var store in allStores)
     {
         if (model.SelectedStoreIds != null && model.SelectedStoreIds.Contains(store.Id))
         {
             //new role
             if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0)
                 _storeMappingService.InsertStoreMapping(currency, store.Id);
         }
         else
         {
             //removed role
             var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id);
             if (storeMappingToDelete != null)
                 _storeMappingService.DeleteStoreMapping(storeMappingToDelete);
         }
     }
 }
 public void Update(CurrencyModel item)
 {
     throw new NotImplementedException();
 }
Esempio n. 24
0
 public CurrencyRequirementViewModel(CurrencyModel currency, int amount)
     : this(currency, CurrencyRequirementTypeEnum.RequiredAmount, amount)
 {
 }
Esempio n. 25
0
        protected virtual List<LocalizedProperty> UpdateLocales(Currency currency, CurrencyModel model)
        {
            List<LocalizedProperty> localized = new List<LocalizedProperty>();
            foreach (var local in model.Locales)
            {

                localized.Add(new LocalizedProperty()
                {
                    LanguageId = local.LanguageId,
                    LocaleKey = "Name",
                    LocaleValue = local.Name
                });
            }
            return localized;
        }
Esempio n. 26
0
 public CurrencyRequirementViewModel(CurrencyModel currency, CurrencyRequirementTypeEnum requirementType, int amount)
 {
     this.CurrencyID      = currency.ID;
     this.RequiredAmount  = amount;
     this.RequirementType = requirementType;
 }
 public override void Init()
 {
     _currentCurrency = new CurrencyModel(DataHolder._data.GetCurrencyData());
     Publish();
 }
Esempio n. 28
0
        private static async Task UpdateCurrencies(IList <Currency> existingCurrencies, CurrencyModel currencyData)
        {
            await CreateOrUpdateCurrency(existingCurrencies, currencyData.Base, 1).ConfigureAwait(false);

            foreach (var rate in currencyData.Rates)
            {
                await CreateOrUpdateCurrency(existingCurrencies, rate.Key, rate.Value).ConfigureAwait(false);
            }

            await CurrencyCore.UpdateAsync(existingCurrencies).ConfigureAwait(false);
        }
Esempio n. 29
0
        public IHttpActionResult EditCurrency([FromBody] CurrencyModel CurrencyModel)
        {
            var reurnCurrency = _CurrencyFacade.EditCurrency(Mapper.Map <CurrencyDto>(CurrencyModel), UserId, TenantId);

            return(Ok(reurnCurrency));
        }
Esempio n. 30
0
 public static Currency ToEntity(this CurrencyModel model, Currency destination)
 {
     return(model.MapTo(destination));
 }
Esempio n. 31
0
 public StealGameEditorControlViewModel(CurrencyModel currency)
 {
     this.SuccessOutcomeCommand = this.CreateBasicChatCommand("@$username stole $gamepayout " + currency.Name + " from @$targetusername!");
     this.FailOutcomeCommand    = this.CreateBasicChatCommand("@$username was unable to steal from @$targetusername...");
 }
Esempio n. 32
0
		public ApplicationSenderModel()
		{
			Currency = new CurrencyModel();
		}
        public ActionResult Edit(CurrencyModel model, bool continueEditing)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageCurrencies))
                return AccessDeniedView();

            var currency = _currencyService.GetCurrencyById(model.Id);
            if (currency == null)
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                currency = model.ToEntity(currency);

                if (!IsAttachedToStore(currency, _services.StoreService.GetAllStores(), false))
                {
                    currency.UpdatedOnUtc = DateTime.UtcNow;

                    _currencyService.UpdateCurrency(currency);

                    //locales
                    UpdateLocales(currency, model);

                    //Stores
                    _storeMappingService.SaveStoreMappings<Currency>(currency, model.SelectedStoreIds);

                    NotifySuccess(_services.Localization.GetResource("Admin.Configuration.Currencies.Updated"));
                    return continueEditing ? RedirectToAction("Edit", new { id = currency.Id }) : RedirectToAction("List");
                }
            }

            //If we got this far, something failed, redisplay form
            model.CreatedOn = _dateTimeHelper.ConvertToUserTime(currency.CreatedOnUtc, DateTimeKind.Utc);

            //Stores
            PrepareCurrencyModel(model, currency, true);

            return View(model);
        }
Esempio n. 34
0
		public ApplicationClientModel()
		{
			Currency = new CurrencyModel();
		}
Esempio n. 35
0
        public ActionResult CurrencySelector()
        {
            var availableCurrencies = _cacheManager.Get(string.Format(ModelCacheEventConsumer.AVAILABLE_CURRENCIES_MODEL_KEY, _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id), () =>
            {
                var result = _currencyService
                    .GetAllCurrencies(storeId: _storeContext.CurrentStore.Id)
                    .Select(x =>
                    {
                        //currency char
                        var currencySymbol = "";
                        if (!string.IsNullOrEmpty(x.DisplayLocale))
                            currencySymbol = new RegionInfo(x.DisplayLocale).CurrencySymbol;
                        else
                            currencySymbol = x.CurrencyCode;
                        //model
                        var currencyModel = new CurrencyModel
                        {
                            Id = x.Id,
                            Name = x.GetLocalized(y => y.Name),
                            CurrencySymbol = currencySymbol
                        };
                        return currencyModel;
                    })
                    .ToList();
                return result;
            });

            var model = new CurrencySelectorModel
            {
                CurrentCurrencyId = _workContext.WorkingCurrency.Id,
                AvailableCurrencies = availableCurrencies
            };

            if (model.AvailableCurrencies.Count == 1)
                Content("");

            return PartialView(model);
        }
Esempio n. 36
0
 public static Currency ToEntity(this CurrencyModel model)
 {
     return(Mapper.Map <CurrencyModel, Currency>(model));
 }
        public ActionResult Edit(CurrencyModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCurrencies))
                return AccessDeniedView();

            var currency = _currencyService.GetCurrencyById(model.Id);
            if (currency == null)
                //No currency found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                //ensure we have at least one published language
                var allCurrencies = _currencyService.GetAllCurrencies();
                if (allCurrencies.Count == 1 && allCurrencies[0].Id == currency.Id &&
                    !model.Published)
                {
                    ErrorNotification("At least one published currency is required.");
                    return RedirectToAction("Edit", new { id = currency.Id });
                }

                currency = model.ToEntity(currency);
                currency.UpdatedOnUtc = DateTime.UtcNow;
                _currencyService.UpdateCurrency(currency);
                //locales
                UpdateLocales(currency, model);
                //Stores
                SaveStoreMappings(currency, model);

                SuccessNotification(_localizationService.GetResource("Admin.Configuration.Currencies.Updated"));

                if (continueEditing)
                {
                    //selected tab
                    SaveSelectedTabIndex();

                    return RedirectToAction("Edit", new {id = currency.Id});
                }
                return RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form
            model.CreatedOn = _dateTimeHelper.ConvertToUserTime(currency.CreatedOnUtc, DateTimeKind.Utc);

            //Stores
            PrepareStoresMappingModel(model, currency, true);

            return View(model);
        }
Esempio n. 38
0
        protected override string GetSubUnitCurrencyText(long num, CurrencyModel currency, bool useShort)
        {
            var textType = GetTextType(num);

            return(currency.SubUnitCurrency.Names[textType - 1]);
        }
Esempio n. 39
0
 public static Currency ToEntity(this CurrencyModel model, Currency destination)
 {
     return(Mapper.Map(model, destination));
 }
        private void PrepareCurrencyModel(CurrencyModel model, Currency currency, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            var allStores = _services.StoreService.GetAllStores();

            model.AvailableStores = allStores.Select(s => s.ToModel()).ToList();

            if (currency != null)
            {
                model.PrimaryStoreCurrencyStores = allStores
                    .Where(x => x.PrimaryStoreCurrencyId == currency.Id)
                    .Select(x => new SelectListItem
                    {
                        Text = x.Name,
                        Value = Url.Action("Edit", "Store", new { id = x.Id })
                    })
                    .ToList();

                model.PrimaryExchangeRateCurrencyStores = allStores
                    .Where(x => x.PrimaryExchangeRateCurrencyId == currency.Id)
                    .Select(x => new SelectListItem
                    {
                        Text = x.Name,
                        Value = Url.Action("Edit", "Store", new { id = x.Id })
                    })
                    .ToList();
            }

            if (!excludeProperties)
            {
                model.SelectedStoreIds = (currency == null ? new int[0] : _storeMappingService.GetStoresIdsWithAccess(currency));
            }
        }
Esempio n. 41
0
 protected virtual string GetChildCurrencyText(long num, CurrencyModel currency)
 {
     return(num > 1 ? currency.ChildCurrency.Names[1] : currency.ChildCurrency.Names[0]);
 }
Esempio n. 42
0
 public UserConsumableEditorViewModel(UserDataModel user, CurrencyModel currency)
     : this(user)
 {
     this.currency = currency;
 }
 protected override string GetUnitSeparator(CurrencyModel currency, bool addAndAsUnitSeparator)
 {
     return(" ከ ");
 }
Esempio n. 44
0
        public ActionResult Edit(CurrencyModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCurrencies))
                return AccessDeniedView();

            var currency = _currencyService.GetCurrencyById(model.Id);
            if (currency == null)
                //No currency found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                currency = model.ToEntity(currency);
                currency.UpdatedOnUtc = DateTime.UtcNow;
                _currencyService.UpdateCurrency(currency);
                //locales
                UpdateLocales(currency, model);
                //Stores
                SaveStoreMappings(currency, model);

                SuccessNotification(_localizationService.GetResource("Admin.Configuration.Currencies.Updated"));
                return continueEditing ? RedirectToAction("Edit", new { id = currency.Id }) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form
            model.CreatedOn = _dateTimeHelper.ConvertToUserTime(currency.CreatedOnUtc, DateTimeKind.Utc);

            //Stores
            PrepareStoresMappingModel(model, currency, true);

            return View(model);
        }
Esempio n. 45
0
        public async Task PerformShopCommand(UserViewModel user, IEnumerable <string> arguments = null, StreamingPlatformTypeEnum platform = StreamingPlatformTypeEnum.None)
        {
            try
            {
                if (ChannelSession.Services.Chat != null && ChannelSession.Settings.Currency.ContainsKey(this.ShopCurrencyID))
                {
                    CurrencyModel currency = ChannelSession.Settings.Currency[this.ShopCurrencyID];

                    if (arguments != null && arguments.Count() > 0)
                    {
                        string arg1 = arguments.ElementAt(0);
                        if (arguments.Count() == 1 && arg1.Equals("list", StringComparison.InvariantCultureIgnoreCase))
                        {
                            List <string> items = new List <string>();
                            foreach (UserInventoryItemModel item in this.Items.Values)
                            {
                                if (item.HasBuyAmount || item.HasSellAmount)
                                {
                                    items.Add(item.Name);
                                }
                            }
                            await ChannelSession.Services.Chat.SendMessage("Items Available to Buy/Sell: " + string.Join(", ", items));

                            return;
                        }
                        else if (arguments.Count() >= 2 &&
                                 (arg1.Equals("buy", StringComparison.InvariantCultureIgnoreCase) || arg1.Equals("sell", StringComparison.InvariantCultureIgnoreCase)))
                        {
                            int amount = 1;

                            IEnumerable <string>   itemArgs = arguments.Skip(1);
                            UserInventoryItemModel item     = this.GetItem(string.Join(" ", itemArgs));
                            if (item == null && itemArgs.Count() > 1)
                            {
                                itemArgs = itemArgs.Take(itemArgs.Count() - 1);
                                item     = this.GetItem(string.Join(" ", itemArgs));
                                if (item != null)
                                {
                                    if (!int.TryParse(arguments.Last(), out amount) || amount <= 0)
                                    {
                                        await ChannelSession.Services.Chat.SendMessage("A valid amount greater than 0 must be specified");

                                        return;
                                    }
                                }
                            }

                            if (item == null)
                            {
                                await ChannelSession.Services.Chat.SendMessage("The item you specified does not exist");

                                return;
                            }

                            int           totalcost = 0;
                            CustomCommand command   = null;
                            if (arg1.Equals("buy", StringComparison.InvariantCultureIgnoreCase))
                            {
                                if (item.HasBuyAmount)
                                {
                                    int itemMaxAmount = (item.HasMaxAmount) ? item.MaxAmount : this.DefaultMaxAmount;
                                    if ((this.GetAmount(user.Data, item) + amount) <= itemMaxAmount)
                                    {
                                        totalcost = item.BuyAmount * amount;
                                        if (currency.HasAmount(user.Data, totalcost))
                                        {
                                            currency.SubtractAmount(user.Data, totalcost);
                                            this.AddAmount(user.Data, item, amount);
                                            command = this.ItemsBoughtCommand;
                                        }
                                        else
                                        {
                                            await ChannelSession.Services.Chat.SendMessage(string.Format("You do not have the required {0} {1} to purchase this item", totalcost, currency.Name));
                                        }
                                    }
                                    else
                                    {
                                        await ChannelSession.Services.Chat.SendMessage(string.Format("You can only have {0} {1} in total", itemMaxAmount, item.Name));
                                    }
                                }
                                else
                                {
                                    await ChannelSession.Services.Chat.SendMessage("This item is not available for buying");
                                }
                            }
                            else if (arg1.Equals("sell", StringComparison.InvariantCultureIgnoreCase))
                            {
                                if (item.HasSellAmount)
                                {
                                    totalcost = item.SellAmount * amount;
                                    if (this.HasAmount(user.Data, item, amount))
                                    {
                                        this.SubtractAmount(user.Data, item, amount);
                                        currency.AddAmount(user.Data, totalcost);
                                        command = this.ItemsSoldCommand;
                                    }
                                    else
                                    {
                                        await ChannelSession.Services.Chat.SendMessage(string.Format("You do not have the required {0} {1} to sell", amount, item.Name));
                                    }
                                }
                                else
                                {
                                    await ChannelSession.Services.Chat.SendMessage("This item is not available for selling");
                                }
                            }
                            else
                            {
                                await ChannelSession.Services.Chat.SendMessage("You must specify either \"buy\" & \"sell\"");
                            }

                            if (command != null)
                            {
                                Dictionary <string, string> specialIdentifiers = new Dictionary <string, string>();
                                specialIdentifiers["itemtotal"]    = amount.ToString();
                                specialIdentifiers["itemname"]     = item.Name;
                                specialIdentifiers["itemcost"]     = totalcost.ToString();
                                specialIdentifiers["currencyname"] = currency.Name;
                                await command.Perform(user, arguments : arguments, extraSpecialIdentifiers : specialIdentifiers);
                            }
                            return;
                        }
                        else
                        {
                            UserInventoryItemModel item = this.GetItem(string.Join(" ", arguments));
                            if (item != null)
                            {
                                if (item.HasBuyAmount || item.HasSellAmount)
                                {
                                    StringBuilder itemInfo = new StringBuilder();
                                    itemInfo.Append(item.Name + ": ");
                                    if (item.HasBuyAmount)
                                    {
                                        itemInfo.Append(string.Format("Buy = {0} {1}", item.BuyAmount, currency.Name));
                                    }
                                    if (item.HasBuyAmount && item.HasSellAmount)
                                    {
                                        itemInfo.Append(string.Format(", "));
                                    }
                                    if (item.HasSellAmount)
                                    {
                                        itemInfo.Append(string.Format("Sell = {0} {1}", item.SellAmount, currency.Name));
                                    }

                                    await ChannelSession.Services.Chat.SendMessage(itemInfo.ToString());
                                }
                                else
                                {
                                    await ChannelSession.Services.Chat.SendMessage("This item is not available to buy/sell");
                                }
                            }
                            else
                            {
                                await ChannelSession.Services.Chat.SendMessage("The item you specified does not exist");
                            }
                            return;
                        }
                    }

                    StringBuilder storeHelp = new StringBuilder();
                    storeHelp.Append(this.ShopCommand + " list = Lists all the items available for buying/selling ** ");
                    storeHelp.Append(this.ShopCommand + " <ITEM NAME> = Lists the buying/selling price for the item ** ");
                    storeHelp.Append(this.ShopCommand + " buy <ITEM NAME> [AMOUNT] = Buys 1 or the amount specified of the item ** ");
                    storeHelp.Append(this.ShopCommand + " sell <ITEM NAME> [AMOUNT] = Sells 1 or the amount specified of the item");
                    await ChannelSession.Services.Chat.SendMessage(storeHelp.ToString());
                }
            }
            catch (Exception ex) { Logger.Log(ex); }
        }
Esempio n. 46
0
        public ActionResult Create(CurrencyModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCurrencies))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                var currency = model.ToEntity();
                currency.CreatedOnUtc = DateTime.UtcNow;
                currency.UpdatedOnUtc = DateTime.UtcNow;
                _currencyService.InsertCurrency(currency);
                //locales
                UpdateLocales(currency, model);
                //Stores
                SaveStoreMappings(currency, model);

                SuccessNotification(_localizationService.GetResource("Admin.Configuration.Currencies.Added"));
                return continueEditing ? RedirectToAction("Edit", new { id = currency.Id }) : RedirectToAction("List");
            }

            //If we got this far, something failed, redisplay form

            //Stores
            PrepareStoresMappingModel(model, null, true);

            return View(model);
        }
Esempio n. 47
0
 protected virtual string GetChildCurrencyText(long num, CurrencyModel currency) 
 {
     return num > 1 ? currency.ChildCurrency.Names[1] : currency.ChildCurrency.Names[0];
 }