protected void UpdateLocales(StateProvince stateProvince, StateProvinceModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(stateProvince,
                                                        x => x.Name,
                                                        localized.Name,
                                                        localized.LanguageId);
     }
 }
        public virtual IActionResult StateCreatePopup(StateProvinceModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

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

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

            if (ModelState.IsValid)
            {
                var sp = model.ToEntity <StateProvince>();

                _stateProvinceService.InsertStateProvince(sp);

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

                UpdateLocales(sp, model);

                ViewBag.RefreshPage = true;

                return(View(model));
            }

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

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 3
0
        public virtual async Task <StateProvince> UpdateStateProvinceModel(StateProvince sp, StateProvinceModel model)
        {
            sp = model.ToEntity(sp);
            await _countryService.UpdateStateProvince(sp, model.CountryId);

            return(sp);
        }
Exemplo n.º 4
0
 public static StateProvince ToEntity(this StateProvinceModel model, StateProvince destination)
 {
     return(Mapper.Map(model, destination));
 }
Exemplo n.º 5
0
 public static StateProvince ToEntity(this StateProvinceModel model)
 {
     return(Mapper.Map <StateProvinceModel, StateProvince>(model));
 }
        public ActionResult StateEditPopup(string btnId, string formId, StateProvinceModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
                return AccessDeniedView();

            var sp = _stateProvinceService.GetStateProvinceById(model.Id);
            if (sp == null)
                //No state found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                sp = model.ToEntity(sp);
                _stateProvinceService.UpdateStateProvince(sp);

                UpdateLocales(sp, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId = btnId;
                ViewBag.formId = formId;
                return View(model);
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
        //create
        public ActionResult StateCreatePopup(int countryId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
                return AccessDeniedView();

            var model = new StateProvinceModel();
            model.CountryId = countryId;
            //locales
            AddLocales(_languageService, model.Locales);
            return View(model);
        }
Exemplo n.º 8
0
        protected virtual List<LocalizedProperty> UpdateLocales(StateProvince stateProvince, StateProvinceModel 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;
        }
Exemplo n.º 9
0
        protected virtual List <LocalizedProperty> UpdateLocales(StateProvince stateProvince, StateProvinceModel 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);
        }
Exemplo n.º 10
0
        public ActionResult StateCreatePopup(string btnId, string formId, StateProvinceModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
                return AccessDeniedView();

            var country = _countryService.GetCountryById(model.CountryId);
            if (country == null)
                throw new ArgumentException("No country found with the specified id");

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

                _stateProvinceService.InsertStateProvince(sp);
                UpdateLocales(sp, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId = btnId;
                ViewBag.formId = formId;
                return View(model);
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 11
0
 public static StateProvince ToEntity(this StateProvinceModel model, StateProvince entity)
 {
     MapperFactory.Map(model, entity);
     return(entity);
 }
Exemplo n.º 12
0
 public static StateProvince ToEntity(this StateProvinceModel model)
 {
     return(AutoMapperConfiguration.Mapper.Map <StateProvinceModel, StateProvince>(model));
 }
        public void IntegrationTest()
        {
            var connection = TestSession.GetConnection();

            connection.Open();
            #region good insertion and select by id test
            StateProvinceModel inserted = new StateProvinceModel();
            inserted.StateProvinceCode       = TestSession.Random.RandomString(3);
            inserted.CountryRegionCode       = TestSession.Random.RandomString(3);
            inserted.IsOnlyStateProvinceFlag = Convert.ToBoolean(TestSession.Random.Next(1));
            inserted.Name         = TestSession.Random.RandomString(50);
            inserted.TerritoryID  = TestSession.Random.Next();
            inserted.rowguid      = Guid.NewGuid();
            inserted.ModifiedDate = TestSession.Random.RandomDateTime();

            _tested.Insert(connection, new[] { inserted });

            var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new StateProvinceModelPrimaryKey()
            {
                StateProvinceID = inserted.StateProvinceID,
            });

            CollectionAssert.IsNotEmpty(selectedAfterInsertion);
            var selectedAfterInsert = selectedAfterInsertion.Single();
            Assert.AreEqual(inserted.StateProvinceID, selectedAfterInsert.StateProvinceID);
            Assert.AreEqual(inserted.StateProvinceCode, selectedAfterInsert.StateProvinceCode);
            Assert.AreEqual(inserted.CountryRegionCode, selectedAfterInsert.CountryRegionCode);
            Assert.AreEqual(inserted.IsOnlyStateProvinceFlag, selectedAfterInsert.IsOnlyStateProvinceFlag);
            Assert.AreEqual(inserted.Name, selectedAfterInsert.Name);
            Assert.AreEqual(inserted.TerritoryID, selectedAfterInsert.TerritoryID);
            Assert.AreEqual(inserted.rowguid, selectedAfterInsert.rowguid);
            Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate);

            #endregion

            #region update and select by id test
            inserted.StateProvinceCode       = TestSession.Random.RandomString(3);
            inserted.CountryRegionCode       = TestSession.Random.RandomString(3);
            inserted.IsOnlyStateProvinceFlag = Convert.ToBoolean(TestSession.Random.Next(1));
            inserted.Name         = TestSession.Random.RandomString(50);
            inserted.TerritoryID  = TestSession.Random.Next();
            inserted.rowguid      = Guid.NewGuid();
            inserted.ModifiedDate = TestSession.Random.RandomDateTime();

            _tested.Update(connection, new[] { inserted });

            var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new StateProvinceModelPrimaryKey()
            {
                StateProvinceID = inserted.StateProvinceID,
            });

            CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss);
            var selectedAfterUpdate = selectedAfterUpdateAddresss.Single();
            Assert.AreEqual(inserted.StateProvinceID, selectedAfterUpdate.StateProvinceID);
            Assert.AreEqual(inserted.StateProvinceCode, selectedAfterUpdate.StateProvinceCode);
            Assert.AreEqual(inserted.CountryRegionCode, selectedAfterUpdate.CountryRegionCode);
            Assert.AreEqual(inserted.IsOnlyStateProvinceFlag, selectedAfterUpdate.IsOnlyStateProvinceFlag);
            Assert.AreEqual(inserted.Name, selectedAfterUpdate.Name);
            Assert.AreEqual(inserted.TerritoryID, selectedAfterUpdate.TerritoryID);
            Assert.AreEqual(inserted.rowguid, selectedAfterUpdate.rowguid);
            Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate);

            #endregion

            #region delete test
            _tested.Delete(connection, new[] { inserted });
            var selectedAfterDeleteAddresss = _tested.GetByPrimaryKey(connection, new StateProvinceModelPrimaryKey()
            {
                StateProvinceID = inserted.StateProvinceID,
            });
            CollectionAssert.IsEmpty(selectedAfterDeleteAddresss);
            #endregion
            connection.Close();
        }
Exemplo n.º 14
0
 public virtual StateProvince UpdateStateProvinceModel(StateProvince sp, StateProvinceModel model)
 {
     sp = model.ToEntity(sp);
     _stateProvinceService.UpdateStateProvince(sp);
     return(sp);
 }
Exemplo n.º 15
0
 public static StateProvince ToEntity(this StateProvinceModel model)
 {
     return(model.MapTo <StateProvinceModel, StateProvince>());
 }
Exemplo n.º 16
0
 public static StateProvince ToEntity(this StateProvinceModel model, StateProvince destination)
 {
     return(model.MapTo(destination));
 }
Exemplo n.º 17
0
        /// <summary>
        /// Prepare state and province model
        /// </summary>
        /// <param name="model">State and province model</param>
        /// <param name="country">Country</param>
        /// <param name="state">State or province</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the state and province model
        /// </returns>
        public virtual async Task <StateProvinceModel> PrepareStateProvinceModelAsync(StateProvinceModel model,
                                                                                      Country country, StateProvince state, bool excludeProperties = false)
        {
            Func <StateProvinceLocalizedModel, int, Task> localizedModelConfiguration = null;

            if (state != null)
            {
                //fill in model values from the entity
                model ??= state.ToModel <StateProvinceModel>();

                //define localized model configuration action
                localizedModelConfiguration = async(locale, languageId) =>
                {
                    locale.Name = await _localizationService.GetLocalizedAsync(state, entity => entity.Name, languageId, false, false);
                };
            }

            model.CountryId = country.Id;

            //set default values for the new model
            if (state == null)
            {
                model.Published = true;
            }

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration);
            }

            return(model);
        }