Ejemplo n.º 1
0
        public virtual ActionResult Index(BillSettingsModel model)
        {
            if (model.EuroToRuble <= 0)
            {
                ModelState.AddModelError("EuroToRuble", @"EUR/RUB must have positive value");
            }

            if (model.VAT <= 0)
            {
                ModelState.AddModelError("VAT", @"VAT must have positive value");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var data = _serializer.Serialize(new BillSettings
            {
                Accountant                = model.Accountant,
                Bank                      = model.BankDetails.Bank,
                BIC                       = model.BankDetails.BIC,
                CorrespondentAccount      = model.BankDetails.CorrespondentAccount,
                CurrentAccount            = model.BankDetails.CurrentAccount,
                Head                      = model.Head,
                HeaderText                = model.HeaderText,
                Payee                     = model.BankDetails.Payee,
                Shipper                   = model.Shipper,
                TaxRegistrationReasonCode = model.BankDetails.TaxRegistrationReasonCode,
                TIN                       = model.BankDetails.TIN,
                VAT                       = (decimal)model.VAT / 100,
                EuroToRuble               = model.EuroToRuble,
                SourceUrl                 = model.SourceUrl,
                AutoUpdatePeriod          = model.AutoUpdatePeriodHours.HasValue
                                        ? TimeSpan.FromHours(model.AutoUpdatePeriodHours.Value)
                                        : (TimeSpan?)null
            });

            try
            {
                _settings.AddOrReplace(new Setting
                {
                    Data       = data,
                    RowVersion = model.Version,
                    Type       = SettingType.Bill
                });
            }
            catch (UpdateConflictException)
            {
                ModelState.AddModelError("Version", @"Outdated data, refresh the page and try again");

                return(View(model));
            }

            return(RedirectToAction(MVC.Admin.BillSettings.Index()));
        }
Ejemplo n.º 2
0
 private void Update(Setting data)
 {
     try
     {
         _settings.AddOrReplace(data);
     }
     catch (UpdateConflictException)
     {
     }
 }