Ejemplo n.º 1
0
        public ActionResult Register(RegisterСonsumptionModel model)
        {
            var strAmount = model.Amount.Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)
                            .Replace(",", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            double am;

            if (double.TryParse(strAmount, out am))
            {
                ViewBag.Done = _storage.RegisterСonsumption(am, model.Currency, model.Description ?? "", _usersHelper.GetCurrentUserId());
                _settings.WriteSettings(SettingsNames.LastUsedCurrency, model.Currency);
                ModelState.Clear();
                model = GetEmptyRegisterModel();
            }
            else
            {
                ViewBag.Done = false;
            }
            var back = Request.QueryString["Return"];

            if (string.IsNullOrEmpty(back))
            {
                back = "Index";
            }
            ViewBag.BackLink   = back;
            ViewBag.Currencies = _storage.CurrenciesList;
            return(View(model));
        }
Ejemplo n.º 2
0
        private RegisterСonsumptionModel GetEmptyRegisterModel()
        {
            var cur = _settings.ReadSetting(SettingsNames.LastUsedCurrency);

            if (string.IsNullOrEmpty(cur))
            {
                var bCur = _storage.GetBaseCurrency();
                if (bCur != null)
                {
                    cur = bCur.Code;
                }
            }
            var model = new RegisterСonsumptionModel
            {
                Amount      = "",
                Currency    = cur,
                Description = ""
            };

            return(model);
        }