示例#1
0
        public ActionResult Create(CountryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var country = model.ToEntity();
                _countryService.InsertCountry(country);
                //locales
                UpdateLocales(country, model);
                //Stores
                SaveStoreMappings(country, model);

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

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

            //Stores
            PrepareStoresMappingModel(model, null, true);
            return(View(model));
        }
示例#2
0
        public ActionResult Edit(CountryModel model, bool continueEditing)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            var country = _countryService.GetCountryById(model.Id);

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

            if (ModelState.IsValid)
            {
                country = model.ToEntity(country);
                _countryService.UpdateCountry(country);

                UpdateLocales(country, model);

                SaveStoreMappings(country, model);

                NotifySuccess(T("Admin.Configuration.Countries.Updated"));

                return(continueEditing ? RedirectToAction("Edit", new { id = country.Id }) : RedirectToAction("List"));
            }

            PrepareCountryModel(model, country, true);

            return(View(model));
        }
示例#3
0
        public ActionResult Edit(CountryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            var country = _countryService.GetCountryById(model.Id);

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

            if (ModelState.IsValid)
            {
                country = model.ToEntity(country);
                _countryService.UpdateCountry(country);
                //locales
                UpdateLocales(country, model);

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

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#4
0
        public virtual async Task <Country> InsertCountryModel(CountryModel model)
        {
            var country = model.ToEntity();
            await _countryService.InsertCountry(country);

            return(country);
        }
示例#5
0
        public ActionResult Create(CountryModel model, bool continueEditing)
        {
            if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var country = model.ToEntity();
                _countryService.InsertCountry(country);

                UpdateLocales(country, model);

                _storeMappingService.SaveStoreMappings <Country>(country, model.SelectedStoreIds);

                NotifySuccess(T("Admin.Configuration.Countries.Added"));

                return(continueEditing ? RedirectToAction("Edit", new { id = country.Id }) : RedirectToAction("List"));
            }

            PrepareCountryModel(model, null, true);

            return(View(model));
        }
        public ActionResult Edit(CountryModel model, bool continueEditing)
        {
            var country = _countryService.GetCountryById(model.Id);

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

            if (ModelState.IsValid)
            {
                country = model.ToEntity(country);
                _countryService.UpdateCountry(country);

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

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

            PrepareCountryModel(model, country, true);

            return(View(model));
        }
示例#7
0
        public virtual async Task <Country> UpdateCountryModel(Country country, CountryModel model)
        {
            country = model.ToEntity(country);
            await _countryService.UpdateCountry(country);

            return(country);
        }
示例#8
0
        public virtual Country InsertCountryModel(CountryModel model)
        {
            var country = model.ToEntity();

            _countryService.InsertCountry(country);
            return(country);
        }
        public IActionResult create(CountryModel model)
        {
            Country entity = model.ToEntity();

            new LocationsHandler().AddCountry(entity);
            return(RedirectToAction("Manage"));
        }
        public IActionResult Edit(CountryModel model)
        {
            User currentUser = HttpContext.Session.Get <User>(WebUtil.CURRENT_USER);

            if (!(currentUser?.Role?.Id == WebUtil.ADMIN))
            {
                return(RedirectToAction("login", "users", new { Controller = "Country", Action = "addCountry" }));
            }

            new LocationsHandler().UpdateCountry(model.id, model.ToEntity());
            return(RedirectToAction("addCountry"));
        }
示例#11
0
 public IActionResult Put(int id, CountryModel model)
 {
     try
     {
         Country entity = new LocationsHandler().UpdateCountry(id, model.ToEntity());
         return(Ok(entity));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex));
     }
 }
示例#12
0
 public IActionResult Post(CountryModel model)
 {
     try
     {
         Country entity = new LocationsHandler().AddCountry(model.ToEntity());
         return(Created($"/api/Country/{entity.Id}", entity));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex));
     }
 }
示例#13
0
        public virtual IActionResult Edit(CountryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            //try to get a country with the specified id
            var country = _countryService.GetCountryById(model.Id);

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

            if (ModelState.IsValid)
            {
                country = model.ToEntity(country);
                _countryService.UpdateCountry(country);

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

                //locales
                UpdateLocales(country, model);

                //stores
                SaveStoreMappings(country, model);

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

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

                //selected tab
                SaveSelectedTabName();

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

            //prepare model
            model = _countryModelFactory.PrepareCountryModel(model, country, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult CountryUpdate(CountryModel model, GridCommand command)
        {
            if (!ModelState.IsValid)
            {
                var modelStateErrors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage);
                return(Content(modelStateErrors.FirstOrDefault()));
            }

            var country = _countryService.GetCountryById(model.Id);

            country = model.ToEntity(country);
            _countryService.UpdateCountry(country);

            return(CountryList(command));
        }
示例#15
0
        public async Task <ActionResult <Response> > CreateCountry(CountryModel model)
        {
            var country = model.ToEntity();

            if (country.Invalid)
            {
                return(BadRequest(ResponseHelper.CreateResponse("Informações inválidas para cadastrar um país", model)));
            }

            if (await _countryRepository.CountryExist(country))
            {
                return(BadRequest(ResponseHelper.CreateResponse("Esse país já foi cadastrado", model)));
            }

            _countryRepository.Add(country);

            return(Ok(ResponseHelper.CreateResponse("País cadastrado com sucesso!", (CountryModel)country)));
        }
示例#16
0
        public ActionResult Create(CountryModel model, bool continueEditing, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                var country = model.ToEntity();
                _countryService.InsertCountry(country);

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

                Services.EventPublisher.Publish(new ModelBoundEvent(model, country, form));

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

            PrepareCountryModel(model, null, true);

            return(View(model));
        }
示例#17
0
        public ActionResult Edit(CountryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            var country = _countryService.GetCountryById(model.Id);

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

            if (ModelState.IsValid)
            {
                country         = model.ToEntity(country);
                country.Locales = UpdateLocales(country, model);
                country.Stores  = model.SelectedStoreIds != null?model.SelectedStoreIds.ToList() : new List <int>();

                _countryService.UpdateCountry(country);

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

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

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

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

            //Stores
            PrepareStoresMappingModel(model, country, true);
            return(View(model));
        }
示例#18
0
        public virtual IActionResult Create(CountryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var country = model.ToEntity();
                _countryService.InsertCountry(country);

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

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

                SuccessNotification(_localizationService.GetResource("Admin.Configuration.Countries.Added"));

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

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

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

            //Stores
            PrepareStoresMappingModel(model, null, true);
            return(View(model));
        }
示例#19
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> Create(CountryModel model, bool continueEditing)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            if (ModelState.IsValid)
            {
                var country = model.ToEntity <Country>();
                await _countryService.InsertCountryAsync(country);

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

                //locales
                await UpdateLocalesAsync(country, model);

                //Stores
                await SaveStoreMappingsAsync(country, model);

                _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Configuration.Countries.Added"));

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

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

            //prepare model
            model = await _countryModelFactory.PrepareCountryModelAsync(model, null, true);

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
示例#20
0
 public virtual Country UpdateCountryModel(Country country, CountryModel model)
 {
     country = model.ToEntity(country);
     _countryService.UpdateCountry(country);
     return(country);
 }
        public ActionResult Edit(CountryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
                return AccessDeniedView();

            var country = _countryService.GetCountryById(model.Id);
            if (country == null)
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                country = model.ToEntity(country);
                _countryService.UpdateCountry(country);

                UpdateLocales(country, model);

                _storeMappingService.SaveStoreMappings<Country>(country, model.SelectedStoreIds);

                NotifySuccess(_localizationService.GetResource("Admin.Configuration.Countries.Updated"));

                return continueEditing ? RedirectToAction("Edit", new { id = country.Id }) : RedirectToAction("List");
            }

            PrepareCountryModel(model, country, true);

            return View(model);
        }
        public ActionResult Edit(CountryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
                return AccessDeniedView();

            var country = _countryService.GetCountryById(model.Id);
            if (country == null)
                //No country found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                country = model.ToEntity(country);
                _countryService.UpdateCountry(country);
                //locales
                UpdateLocales(country, model);
                //Stores
                SaveStoreMappings(country, model);

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

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

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

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

            //Stores
            PrepareStoresMappingModel(model, country, true);
            return View(model);
        }
        public ActionResult Create(CountryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
                return AccessDeniedView();

            if (ModelState.IsValid)
            {
                var country = model.ToEntity();
                _countryService.InsertCountry(country);
                //locales
                UpdateLocales(country, model);
                //Stores
                SaveStoreMappings(country, model);

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

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

            //Stores
            PrepareStoresMappingModel(model, null, true);
            return View(model);
        }
        public ActionResult Edit(CountryModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
                return AccessDeniedView();

            var country = _countryService.GetCountryById(model.Id);
            if (country == null)
                //No country found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                country = model.ToEntity(country);
                _countryService.UpdateCountry(country);
                //locales
                UpdateLocales(country, model);

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

            //If we got this far, something failed, redisplay form
            return View(model);
        }
 public IActionResult edit(CountryModel model)
 {
     new LocationsHandler().UpdateCountry(model.Id, model.ToEntity());
     return(RedirectToAction("Manage"));
 }