Exemplo n.º 1
0
        public ActionResult Edit(CurrencyModel model, bool continueEditing)
        {
            var currency = _currencyService.GetCurrencyById(model.Id);

            if (currency == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                currency = model.ToEntity(currency);
                currency.DomainEndings = string.Join(",", model.DomainEndingsArray ?? new string[0]);

                if (!IsAttachedToStore(currency, _services.StoreService.GetAllStores(), false))
                {
                    _currencyService.UpdateCurrency(currency);

                    UpdateLocales(currency, model);
                    SaveStoreMappings(currency, model.SelectedStoreIds);

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

            model.CreatedOn = _dateTimeHelper.ConvertToUserTime(currency.CreatedOnUtc, DateTimeKind.Utc);

            PrepareCurrencyModel(model, currency, true);

            return(View(model));
        }
Exemplo n.º 2
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);

                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);
            return(View(model));
        }
Exemplo n.º 3
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;
                currency.Locales      = UpdateLocales(currency, model);
                currency.Stores       = model.SelectedStoreIds != null?model.SelectedStoreIds.ToList() : new List <string>();

                _currencyService.InsertCurrency(currency);

                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));
        }
Exemplo n.º 4
0
 public virtual Currency UpdateCurrencyModel(Currency currency, CurrencyModel model)
 {
     currency = model.ToEntity(currency);
     currency.UpdatedOnUtc = DateTime.UtcNow;
     _currencyService.UpdateCurrency(currency);
     return(currency);
 }
        public ActionResult Create(CurrencyModel model, bool continueEditing)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageCurrencies))
            {
                return(AccessDeniedView());
            }

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

                _currencyService.InsertCurrency(currency);

                //locales
                UpdateLocales(currency, model);

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

                NotifySuccess(_services.Localization.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
            PrepareCurrencyModel(model, null, true);

            return(View(model));
        }
Exemplo n.º 6
0
        public virtual async Task <Currency> UpdateCurrencyModel(Currency currency, CurrencyModel model)
        {
            currency = model.ToEntity(currency);
            currency.UpdatedOnUtc = DateTime.UtcNow;
            await _currencyService.UpdateCurrency(currency);

            return(currency);
        }
Exemplo n.º 7
0
        public virtual IActionResult Edit(CurrencyModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCurrencies))
            {
                return(AccessDeniedView());
            }

            var currency = _currencyService.GetCurrencyById(model.Id, false);

            if (currency == null)
            {
                //No currency found with the specified id
                return(RedirectToAction("List"));
            }

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

                currency = model.ToEntity(currency);
                currency.UpdatedOnUtc = DateTime.UtcNow;
                _currencyService.UpdateCurrency(currency);

                //activity log
                _customerActivityService.InsertActivity("EditCurrency",
                                                        string.Format(_localizationService.GetResource("ActivityLog.EditCurrency"), currency.Id), currency);

                //locales
                UpdateLocales(currency, model);
                //Stores
                SaveStoreMappings(currency, model);


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

                if (continueEditing)
                {
                    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));
        }
Exemplo n.º 8
0
        public virtual async Task <IActionResult> Edit(CurrencyModel model, bool continueEditing)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCurrencies))
            {
                return(AccessDeniedView());
            }

            //try to get a currency with the specified id
            var currency = await _currencyService.GetCurrencyByIdAsync(model.Id);

            if (currency == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                //ensure we have at least one published currency
                var allCurrencies = await _currencyService.GetAllCurrenciesAsync();

                if (allCurrencies.Count == 1 && allCurrencies[0].Id == currency.Id && !model.Published)
                {
                    _notificationService.ErrorNotification(await _localizationService.GetResourceAsync("Admin.Configuration.Currencies.PublishedCurrencyRequired"));
                    return(RedirectToAction("Edit", new { id = currency.Id }));
                }

                currency = model.ToEntity(currency);
                currency.UpdatedOnUtc = DateTime.UtcNow;
                await _currencyService.UpdateCurrencyAsync(currency);

                //activity log
                await _customerActivityService.InsertActivityAsync("EditCurrency",
                                                                   string.Format(await _localizationService.GetResourceAsync("ActivityLog.EditCurrency"), currency.Id), currency);

                //locales
                await UpdateLocalesAsync(currency, model);

                //stores
                await SaveStoreMappingsAsync(currency, model);

                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Configuration.Currencies.Updated"));

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

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

            //prepare model
            model = await _currencyModelFactory.PrepareCurrencyModelAsync(model, currency, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 9
0
        public virtual async Task <Currency> InsertCurrencyModel(CurrencyModel model)
        {
            var currency = model.ToEntity();

            currency.CreatedOnUtc = DateTime.UtcNow;
            currency.UpdatedOnUtc = DateTime.UtcNow;
            await _currencyService.InsertCurrency(currency);

            return(currency);
        }
Exemplo n.º 10
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)
            {
                //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;
                currency.Locales      = UpdateLocales(currency, model);
                currency.Stores       = model.SelectedStoreIds != null?model.SelectedStoreIds.ToList() : new List <string>();

                _currencyService.UpdateCurrency(currency);

                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));
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
        public ActionResult Create(CurrencyModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                var currency = model.ToEntity();

                _currencyService.InsertCurrency(currency);

                UpdateLocales(currency, model);
                SaveStoreMappings(currency, model.SelectedStoreIds);

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

            PrepareCurrencyModel(model, null, true);

            return(View(model));
        }
        public virtual IActionResult Create(CurrencyModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCurrencies))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var currency = model.ToEntity <Currency>();
                currency.CreatedOnUtc = DateTime.UtcNow;
                currency.UpdatedOnUtc = DateTime.UtcNow;
                _currencyService.InsertCurrency(currency);

                //activity log
                _customerActivityService.InsertActivity("AddNewCurrency",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewCurrency"), currency.Id), currency);

                //locales
                UpdateLocales(currency, model);

                //stores
                SaveStoreMappings(currency, model);

                _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Configuration.Currencies.Added"));

                if (!continueEditing)
                {
                    return(RedirectToAction("List"));
                }

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

            //prepare model
            model = _currencyModelFactory.PrepareCurrencyModel(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult Edit(CurrencyModel model)
        {
            var currency = _currencyRepository.GetById(model.Id);

            if (ModelState.IsValid)
            {
                //in case of add new, change the IsNew flag to false before saving
                if (model.IsNew == true)
                {
                    model.IsNew = false;
                }
                currency = model.ToEntity(currency);
                _currencyService.UpdateCurrency(currency);

                //notification
                SuccessNotification(_localizationService.GetResource("Record.Saved"));
                return(new NullJsonResult());
            }
            else
            {
                return(Json(new { Errors = ModelState.SerializeErrors() }));
            }
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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);
        }
        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);
        }
        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);
        }