protected void UpdateLocales(Country country, CountryModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(country, x => x.Name, localized.Name, localized.LanguageId); } }
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); }
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); }
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)); }
/// <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); }
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); }
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; } }
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 })); }
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; })); }
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 }
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"); } }
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)); } }
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"]; }
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")); }
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(); }
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); }
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)); }
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()); } }
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")); }
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)); }
// 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)); }
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); }
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()); } }
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); }
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); } } }
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)); }
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)); }
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); } }
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)); } }
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 }); } }
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)); }
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)); }
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); }
public ActionResult AddCountry(CountryModel model) { return Json(new { result = Helper.Helper.AddCountryHelper(model), content = model }); }
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(); } } }
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]; } } }
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; }
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); }
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); } } }
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); 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 ActionResult AddLocation() { CountryModel cmodel = new CountryModel(); return View(cmodel); }
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) }); } }
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); } }