コード例 #1
0
 protected void UpdateLocales(Country country, CountryModel model)
 {
     foreach (var localized in model.Locales)
     {
         _localizedEntityService.SaveLocalizedValue(country,
                                                        x => x.Name,
                                                        localized.Name,
                                                        localized.LanguageId);
     }
 }
コード例 #2
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
                return AccessDeniedView();

            var model = new CountryModel();
            //locales
            AddLocales(_languageService, model.Locales);
            //default values
            model.Published = true;
            return View(model);
        }
コード例 #3
0
        public ActionResult Create()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
                return AccessDeniedView();

            var model = new CountryModel();
            //locales
            AddLocales(_languageService, model.Locales);
            //Stores
            PrepareStoresMappingModel(model, null, false);
            //default values
            model.Published = true;
            model.AllowsBilling = true;
            model.AllowsShipping = true;
            return View(model);
        }
コード例 #4
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);
                //Stores
                SaveStoreMappings(country, model);

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

                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, country, true);
            return(View(model));
        }
コード例 #5
0
        /// <summary>
        /// Prepare country model
        /// </summary>
        /// <param name="model">Country model</param>
        /// <param name="country">Country</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 country model
        /// </returns>
        public virtual async Task <CountryModel> PrepareCountryModelAsync(CountryModel model, Country country, bool excludeProperties = false)
        {
            Action <CountryLocalizedModel, int> localizedModelConfiguration = null;

            if (country != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model = country.ToModel <CountryModel>();
                    model.NumberOfStates = (await _stateProvinceService.GetStateProvincesByCountryIdAsync(country.Id))?.Count ?? 0;
                }

                //prepare nested search model
                PrepareStateProvinceSearchModel(model.StateProvinceSearchModel, country);

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

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

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

            //prepare available stores
            await _storeMappingSupportedModelFactory.PrepareModelStoresAsync(model, country, excludeProperties);

            return(model);
        }
コード例 #6
0
        private IEnumerable <Link> CreateLinksForCountryAttractions(CountryModel countrymodel)
        {
            var links = new List <Link>();

            if (countrymodel.Cities != null)
            {
                foreach (var city in countrymodel.Cities)
                {
                    if (city.Attractions != null)
                    {
                        foreach (var attraction in city.Attractions)
                        {
                            links.Add(new Link($"http://localhost:50615/attractions/{attraction.AttractionId}", "self", "GET"));
                        }
                    }
                }
            }

            return(links);
        }
コード例 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ContinentDatabase continentDatabase = new ContinentDatabase();

            ContinentList.DataSource     = continentDatabase.getAllContinent();
            ContinentList.DataTextField  = "title";
            ContinentList.DataValueField = "id";
            ContinentList.DataBind();
            loadTable();

            if (Request.QueryString["id"] != null)
            {
                id = int.Parse(Request.QueryString["id"]);
                AddCountry.Text = "Update Country";
                CountryDatabase countryDatbase = new CountryDatabase();
                CountryModel    countryModel   = countryDatbase.getCountry(id);
                ContinentList.Items.FindByValue(countryModel.ContinentId.ToString());
                //countryTxtbox.Text = countryModel.Name;
            }
        }
コード例 #8
0
        public async Task <IActionResult> Create(CountryModel model)
        {
            var country = new CountryModifyRequest()
            {
                Id   = model.Id,
                Name = model.Name,
                Code = model.Code
            };

            var exist = _countryService.FindByName(model.Name);

            if (exist != null)
            {
                return(RedirectToErrorPage());
            }

            var id = await _countryService.CreateAsync(country);

            return(RedirectToAction(nameof(Detail), new { id }));
        }
コード例 #9
0
        public HttpResponseMessage GetCountry(HttpRequestMessage request, long countryId)
        {
            return(GetHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                var countryModel = new CountryModel();

                Country country = _CoreService.GetCountry(countryId);
                StateData[] states = _CoreService.GetStates(country.Code);

                countryModel.Country = country;
                countryModel.States = states;

                // notice no need to create a seperate model object since Country entity will do just fine
                response = request.CreateResponse <CountryModel>(HttpStatusCode.OK, countryModel);

                return response;
            }));
        }
コード例 #10
0
        public async Task GetCountryByName()
        {
            // Arrange
            var country = new CountryModel
            {
                Name = "France"
            };

            var newcountry = await _countryService.AddNewCountry(country);

            // Act

            var result = await _countryService.GetCountryByName(newcountry.Name);

            // Assert

            Assert.IsNotNull(result);
            Assert.IsTrue(result.ID > 0);
            //Assert.AreEqual(result.Name, country.Name); // failed
        }
コード例 #11
0
    public void BuyCharacter()
    {
        int currentPoints = PointsUtil.GetCurrentPoints();
        var country       = countries[PlayerSelectedIndex];

        if (currentPoints >= country.UnlockCost)
        {
            Debug.Log("COUNTRY BOUGHT");
            country.IsLocked = false;
            PointsUtil.AddPoints(-country.UnlockCost);

            PointsObject.UpdatePoints();
            RefreshSelection();
            CountryModel.OverwriteCountries(countries);
        }
        else
        {
            Debug.Log("NOT ENOUGH POINTS");
        }
    }
コード例 #12
0
 public Result Add(CountryModel model)
 {
     try
     {
         if (_countryRepository.Query().Any(c => c.Name.ToUpper() == model.Name.ToUpper().Trim()))
         {
             return(new ErrorResult("Country with the same name exists!"));
         }
         var entity = new Country()
         {
             Name = model.Name.Trim()
         };
         _countryRepository.Add(entity);
         return(new SuccessResult());
     }
     catch (Exception exc)
     {
         return(new ExceptionResult(exc));
     }
 }
コード例 #13
0
        private void BindControls()
        {
            /* Binding countries to comboBox */
            CountryModel.BindTo(comboBoxCountry);

            /* Binding regimens to checked listbox */
            checkedListBoxReg.DataSource    = RegimenModel.regimen.Tables[0];
            checkedListBoxReg.DisplayMember = "descr";
            checkedListBoxReg.ValueMember   = "id_regimen";

            /* Loading what handler says */
            textBoxName.Text              = (handler["name"] == DBNull.Value)? "" : (String)handler["name"];
            textBoxMail.Text              = (handler["mail"] == DBNull.Value)? "" : (String)handler["mail"];
            textBoxPhone.Text             = (handler["phone"] == DBNull.Value) ? "" : (String)handler["phone"];
            textBoxStreet.Text            = (handler["street"] == DBNull.Value) ? "" : (String)handler["street"];
            textBoxStreetNum.Text         = (handler["street_num"] == DBNull.Value) ? "" : ((int)handler["street_num"]).ToString();
            textBoxCity.Text              = (handler["city"] == DBNull.Value) ? "" : (String)handler["city"];
            comboBoxCountry.SelectedValue = (handler["country"] == DBNull.Value) ? "" : (String)handler["country"];
            numericUDStars.Value          = (handler["stars"] == DBNull.Value) ? 1 : (int)handler["stars"];
        }
コード例 #14
0
        public IActionResult Action(CountryModel model)
        {
            if (_modelValidations.IsObjectNull(model))
            {
                return(RedirectToAction("Add", "Countries"));
            }

            if (!_modelValidations.IsValid(model))
            {
                return(RedirectToAction("Add", "Countries"));
            }

            var dto = new CountryDto {
                NameAr = model.NameAr, NameEn = model.NameEn
            };

            var country = _countriesRepository.Insert(dto);

            return(RedirectToAction("Index", "Countries"));
        }
コード例 #15
0
 public void AddCountry(CountryModel model)
 {
     if (model.Id == 0)
     {
         Country country = new Country()
         {
             Id        = model.Id,
             Name      = model.Name,
             IsDeleted = false
         };
         db.Coutries.Add(country);
     }
     if (model.Id != 0)
     {
         Country country = db.Coutries.FirstOrDefault(x => x.Id == model.Id);
         country.Name            = model.Name;
         db.Entry(country).State = EntityState.Modified;
     }
     db.SaveChanges();
 }
コード例 #16
0
ファイル: Countries.cs プロジェクト: dangialdini/Evolution
        private Error validateModel(CountryModel model)
        {
            string countryName = getFieldValue(model.CountryName);

            var error = isValidRequiredString(countryName, 50, "CountryName", EvolutionResources.errCountryNameRequired);

            if (!error.IsError)
            {
                // Check if a record with the same name already exists
                var country = db.FindCountry(model.CountryName);
                if (country != null &&                 // Record was found
                    ((country.Id == 0 ||               // when creating new or
                      country.Id != model.Id)))        // when updating existing
                {
                    error.SetError(EvolutionResources.errItemAlreadyExists, "CountryName");
                }
            }

            return(error);
        }
コード例 #17
0
        public IActionResult Edit(CountryModel country)
        {
            if (ModelState.IsValid)
            {
                var result = _countryService.Update(country);
                if (result.Status == ResultStatus.Success)
                {
                    return(RedirectToAction(nameof(Index)));
                }

                if (result.Status == ResultStatus.Error)
                {
                    ModelState.AddModelError("", result.Message);
                    return(View(country));
                }

                throw new Exception(result.Message);
            }
            return(View(country));
        }
コード例 #18
0
        public async Task <IActionResult> CreateCountry(CountryModel model)
        {
            if (ModelState.IsValid)
            {
                //var countryEntity = new CountryEntity()
                //{
                //	Code = model.Code.ToUpper(),
                //	IsActive = true,
                //	Name = model.Name
                //};

                //_countryRepository.Insert(countryEntity);

                return(new OkResult());
            }
            else
            {
                return(BadRequest());
            }
        }
コード例 #19
0
        public ActionResult SaveCountry(CountryModel _viewBrandModal)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                if (_viewBrandModal.intCountryId == 0)
                {
                    _objbrandBAL.SaveCountry(_viewBrandModal);
                }
                else
                {
                    _objbrandBAL.UpdateCountry(_viewBrandModal);
                }

                ModelState.AddModelError("", _viewBrandModal.StatusMessaage);
            }
            ModelState.Clear();
            return(RedirectToAction("Index", "Country"));
        }
コード例 #20
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));
        }
コード例 #21
0
        // GET: Country
        public ActionResult Index()
        {
            var country = new CountryModel();

            country.Id   = 1;
            country.Name = "Россия";
            country.Code = "RU";

            countryModels.Add(country);

            var country2 = new CountryModel();

            country2.Id   = 2;
            country2.Name = "Белорусь";
            country2.Code = "BY";

            countryModels.Add(country2);

            return(View(countryModels));
        }
コード例 #22
0
ファイル: Countries.cs プロジェクト: dangialdini/Evolution
        public CountryModel FindCountryModel(int id, bool bCreateEmptyIfNotfound = true)
        {
            CountryModel model = null;

            var country = db.FindCountry(id);

            if (country == null)
            {
                if (bCreateEmptyIfNotfound)
                {
                    model = new CountryModel();
                }
            }
            else
            {
                model = MapToModel(country);
            }

            return(model);
        }
コード例 #23
0
        public async Task <ActionResult <CountryModel> > updateCountry(CountryModel countryModel)
        {
            try
            {
                var country = _context.country.FirstOrDefault(x => x.id == countryModel.id);
                country.name         = countryModel.name;
                country.alfa_2       = countryModel.alfa_2;
                country.alfa_3       = countryModel.alfa_3;
                country.numeric_code = countryModel.numeric_code;
                country.link_iso     = countryModel.link_iso;
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetModelCountry", new { id = countryModel.id }, countryModel));
            }
            catch (Exception ex)
            {
                Console.WriteLine("an error ocurred" + ex.ToString());
                return(BadRequest());
            }
        }
コード例 #24
0
        public async Task AddCountry()
        {
            // *** test paterns ***

            // Arrange
            var country = new CountryModel
            {
                Name = "Spain"
            };

            // Act

            var result = await _countryService.AddNewCountry(country);

            // Assert

            Assert.IsNotNull(result);
            Assert.IsTrue(result.ID > 0);
            Assert.AreEqual(result.Name, country.Name);
        }
コード例 #25
0
        public static List <CountryModel> GetCountry(int id = 0, bool save = false, bool delete = false)
        {
            var countryModelsList = new List <CountryModel>();
            var sessionFactory    = SessionFactory.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    if (save)
                    {
                        var country = new Country
                        {
                            Id   = 1,
                            Name = "Polska"
                        };



                        session.SaveOrUpdate(country);
                        transaction.Commit();
                    }
                    var CountryCreate = session.CreateCriteria(typeof(Country))
                                        .List <Country>();

                    foreach (var con in CountryCreate)
                    {
                        var temp = new CountryModel()
                        {
                            Id        = con.Id,
                            Name      = con.Name,
                            Continent = con.Continent,
                        };

                        countryModelsList.Add(temp);
                    }

                    return(countryModelsList);
                }
            }
        }
コード例 #26
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)
                {
                    return(RedirectToAction("List"));
                }

                //selected tab
                SaveSelectedTabName();

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

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

            //if we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #27
0
        public async Task <IActionResult> Edit(int id, [Bind("Item")] CoffeeViewModel cvm)
        {
            if (id != cvm.Item.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    CountryModel newCountry = _context.Countries.FirstOrDefault(c => c.Name == cvm.Item.Country.Name) ?? new CountryModel(null, cvm.Item.Country.Name);
                    if (newCountry.Id == null)
                    {
                        _context.Add(newCountry);
                    }
                    VarietyModel newVariety = _context.Varieties.FirstOrDefault(v => v.Name == cvm.Item.Variety.Name) ?? new VarietyModel(null, cvm.Item.Variety.Name);
                    if (newVariety.Id == null)
                    {
                        _context.Add(newVariety);
                    }
                    cvm.Item.Country = newCountry;
                    cvm.Item.Variety = newVariety;
                    _context.Update(cvm.Item);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CoffeeModelExists(cvm.Item.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(cvm));
        }
コード例 #28
0
        public static async Task <GetResultModel <CityModel[]> > LoadCities(CountryModel country = null)
        {
            if (country is null)
            {
                throw new ArgumentNullException();
            }

            string url = $"{apiEndpoint}?country={country.Code}&limit=10000";

            using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))
            {
                if (response.IsSuccessStatusCode)
                {
                    GetResultModel <CityModel[]> data = await response.Content.ReadAsAsync <GetResultModel <CityModel[]> >();

                    return(data);
                }

                throw new Exception(response.ReasonPhrase);
            }
        }
コード例 #29
0
        public ActionResult Create_Post()
        {
            CityModel objCityModel = new CityModel();

            if (ModelState.IsValid)
            {
                TryUpdateModel <CityModel>(objCityModel);
                objCityModel.AddEditCity(objCityModel, clsCommon.Insert);
                return(RedirectToAction("Index"));
            }
            else
            {
                CountryModel objCountry = new CountryModel();
                objCityModel.countryList = objCountry.GetCountryList().ToList();

                StateModel objStateModel = new StateModel();
                objCityModel.stateList = objStateModel.GetStateList().ToList();

                return(View(objCityModel));
            }
        }
コード例 #30
0
ファイル: CountryService.cs プロジェクト: DungNQ10/low_code
        public ActionResult Save(CountryModel model)
        {
            var item = model.CloneToModel <CountryModel, Country>();

            if (model.Id == 0)
            {
                var res = _CountryRepository.Insert(item);
                return(new ActionResult()
                {
                    Success = res
                });
            }
            else
            {
                var res = _CountryRepository.Update(item);
                return(new ActionResult()
                {
                    Success = res
                });
            }
        }
コード例 #31
0
        public ActionResult BasicDetails()
        {
            OrasModel        oras        = new OrasModel();
            CastContextModel objC        = new CastContextModel();
            ReligionModel    objReligion = new ReligionModel();
            CountryModel     objCountry  = new CountryModel();
            StateModel       objState    = new StateModel();
            BloodGroupModel  objB        = new BloodGroupModel();
            BasicResponse    response    = new BasicResponse()
            {
                CastData     = objC.GetCasts(),
                OrasData     = oras.GetOrass(),
                BloodGroup   = objB.GetBloodGroups(),
                CountryData  = objCountry.GetCountrys(),
                HeightData   = oras.GetHeights(),
                ReligionData = objReligion.GetReligions(),
                StateList    = objState.GetStates(),
            };

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
コード例 #32
0
ファイル: CountryController.cs プロジェクト: falutx/desnivell
        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);

                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
            return(View(model));
        }
コード例 #33
0
        private static void GetStateforDefaultCountry(string countryID)
        {
            _CountryModel.Clear();

            ht_param.Clear();
            ht_param.Add("@COUNTRY_ID", countryID);
            ds = db.SysFetchDataInDataSet("[GetStateList]", ht_param);

            if (ds.Tables.Count > 0)
            {
                foreach (DataRow item in ds.Tables[0].Rows)
                {
                    CountryModel CountryModel_Detail = new CountryModel();
                    CountryModel_Detail.Name       = item["NAME"].ToString();
                    CountryModel_Detail.COUNTRY_ID = Convert.ToInt32(item["LOCATION_ID"].ToString());
                    _CountryModel.Add(CountryModel_Detail);
                }
            }
            ReturnData.Remove("State");
            ReturnData["State"] = serializer.Serialize(_CountryModel);
        }
コード例 #34
0
 public ActionResult AddCountry(CountryModel model)
 {
     return Json(new { result = Helper.Helper.AddCountryHelper(model), content = model });
 }
コード例 #35
0
        protected virtual void PrepareStoresMappingModel(CountryModel model, Country country, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            model.AvailableStores = _storeService
                .GetAllStores()
                .Select(s => s.ToModel())
                .ToList();
            if (!excludeProperties)
            {
                if (country != null)
                {
                    model.SelectedStoreIds = country.Stores.ToArray();
                }
            }
        }
コード例 #36
0
        private void PrepareStoresMappingModel(CountryModel model, Country country, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            model.AvailableStores = _storeService
                .GetAllStores()
                .Select(s => s.ToModel())
                .ToList();
            if (!excludeProperties)
            {
                if (country != null)
                {
                    model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(country);
                }
                else
                {
                    model.SelectedStoreIds = new int[0];
                }
            }
        }
コード例 #37
0
        protected virtual List<LocalizedProperty> UpdateLocales(Country country, CountryModel 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;
        }
コード例 #38
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);
                //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);
        }
コード例 #39
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);
        }
コード例 #40
0
 protected void SaveStoreMappings(Country country, CountryModel model)
 {
     var existingStoreMappings = _storeMappingService.GetStoreMappings(country);
     var allStores = _storeService.GetAllStores();
     foreach (var store in allStores)
     {
         if (model.SelectedStoreIds != null && model.SelectedStoreIds.Contains(store.Id))
         {
             //new role
             if (existingStoreMappings.Count(sm => sm.StoreId == store.Id) == 0)
                 _storeMappingService.InsertStoreMapping(country, store.Id);
         }
         else
         {
             //removed role
             var storeMappingToDelete = existingStoreMappings.FirstOrDefault(sm => sm.StoreId == store.Id);
             if (storeMappingToDelete != null)
                 _storeMappingService.DeleteStoreMapping(storeMappingToDelete);
         }
     }
 }
コード例 #41
0
        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);
        }
コード例 #42
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);

                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);
        }
コード例 #43
0
 public ActionResult AddLocation()
 {
     CountryModel cmodel = new CountryModel();
     return View(cmodel);
 }
コード例 #44
0
        protected virtual void PrepareStoresMappingModel(CountryModel model, Country country, bool excludeProperties)
        {
            if (model == null)
                throw new ArgumentNullException("model");

            if (!excludeProperties && country != null)
                model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(country).ToList();

            var allStores = _storeService.GetAllStores();
            foreach (var store in allStores)
            {
                model.AvailableStores.Add(new SelectListItem
                {
                    Text = store.Name,
                    Value = store.Id.ToString(),
                    Selected = model.SelectedStoreIds.Contains(store.Id)
                });
            }
        }
コード例 #45
0
 public ActionResult AddLocation(CountryModel cmodel)
 {
     try
     {
         HolidayPlanner.DAL.Country ct = new HolidayPlanner.DAL.Country()
         {
             CountryId = cmodel.CountryId,
             CountryName = cmodel.CountryName
         };
         context.Countries.InsertOnSubmit(ct);
         context.SubmitChanges();
         return RedirectToAction("Index");
     }
     catch
     {
         return View(cmodel);
     }
 }