コード例 #1
0
		internal static StatesService FromJObject(JObject jObject)
		{
			StatesService response = new StatesService();
			response.nombre = jObject["name"].ToString();
			response.id = jObject["id"].ToString();


			return response;
		}
コード例 #2
0
ファイル: StatesView.cs プロジェクト: saedaes/ProductFinder
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			//Declaramos el actionsheet donde se mostrara el picker
			//actionSheetPicker = new ActionSheetPicker(this.View, null);
			this.pickerStates.Hidden = true;
			this.btnAceptar.Hidden = true;
			//Declaramos el data model para el estado
			pickerDataModel = new PickerDataModel ();
			//Declaramos el data model para la localidad
			pickerDataModelLocality = new PickerDataModelLocality ();

			var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
			_pathToDatabase = Path.Combine(documents, "db_sqlite-net.db");

			using (var db = new SQLite.SQLiteConnection(_pathToDatabase ))
			{
				states = new List<State> (from s in db.Table<State> () select s);
			}

			if(states.Count > 0){
				State estado = states.ElementAt(0);
				this.btnEstado.SetTitle (estado.state, UIControlState.Normal);
				this.btnLocalidad.SetTitle (estado.locality, UIControlState.Normal);
			}

			this.btnEstado.TouchUpInside += (sender, e) => {
				try{
					statesService = new StatesService();
					List<StatesService> estados = statesService.All();
					pickerDataModel.Items = estados;
					pickerStates.Model = pickerDataModel;
					pickerStates.Hidden = false;
					btnAceptar.Hidden = false;
					//actionSheetPicker.Picker.Source = pickerDataModel;
					//actionSheetPicker.Show();
				}catch (System.Net.WebException){
					UIAlertView alert = new UIAlertView () { 
						Title = "Ups =S", Message = "No se puede mostrar la lista de estados, verifica tu conexión a internet e intentalo de nuevo."
					};
					alert.AddButton ("Aceptar");
					alert.Show ();
				}catch(Exception excep){
					Console.WriteLine("ESTE ES EL ERROR: " + excep.ToString());
					UIAlertView alert = new UIAlertView () { 
						Title = "Ups =S", Message = excep.ToString()
					};
					alert.AddButton("Aceptar");
					alert.Show ();
				}
			};

			btnAceptar.TouchUpInside += (sender, e) => {
				this.pickerStates.Hidden = true;
				this.btnAceptar.Hidden = true;
			};

			pickerDataModel.ValueChanged += (sender, e) => {
				this.btnEstado.SetTitle(pickerDataModel.SelectedItem.ToString(), UIControlState.Normal);
				this.stateId = pickerDataModel.SelectedItem.id;
				this.state = pickerDataModel.SelectedItem.ToString();
			};

			this.btnLocalidad.TouchUpInside += (sender, e) => {
				try{
					if(stateId != ""){
						localityService = new LocalityService();
						localityService.setState(stateId);
						List<LocalityService> localidades = localityService.All();
						pickerDataModelLocality.Items = localidades;
						pickerStates.Model = pickerDataModelLocality;
						pickerStates.Hidden = false;
						btnAceptar.Hidden = false;
						//actionSheetPicker.Picker.Source = pickerDataModelLocality;
						//actionSheetPicker.Show();
					}
				}catch(System.Net.WebException){
					UIAlertView alert = new UIAlertView () { 
						Title = "Ups =S", Message = "No se puede mostrar la lista de localidades, verifica tu conexión a internet e intentalo de nuevo."
					};
					alert.AddButton ("Aceptar");
					alert.Show ();
				}catch(Exception){
					UIAlertView alert = new UIAlertView () { 
						Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo."
					};
					alert.AddButton("Aceptar");
					alert.Show ();
				}
			};
				
			pickerDataModelLocality.ValueChanged += (sender, e) => {
				this.btnLocalidad.SetTitle(pickerDataModelLocality.SelectedItem.ToString(),UIControlState.Normal);
				this.localityId = pickerDataModelLocality.SelectedItem.id;
				this.locality = pickerDataModelLocality.SelectedItem.ToString();
			};

			btnGuardar.TouchUpInside += (sender, e) => {
				try{
					if(this.stateId != "" && this.localityId != ""){
						var state = new State {stateId = int.Parse( this.stateId), state = this.locality, localityId = int.Parse(this.localityId), locality = this.locality};
						using (var db = new SQLite.SQLiteConnection(_pathToDatabase ))
						{
							db.DropTable<State>();
							db.CreateTable<State>();
							db.Insert(state);
						}

						MainView.localityId = state.localityId;
						UIAlertView alert = new UIAlertView () { 
							Title = "Bien! =D", Message = "Gracias por definir tu estado y localidad ahora puedes empezar a buscar productos con FixBuy =D"
						};
						alert.AddButton ("Aceptar");
						alert.Show ();
						this.NavigationController.PopViewController(true);
					}
				}catch(Exception){
					UIAlertView alert = new UIAlertView () { 
						Title = "Ups =S", Message = "Algo salio mal, por favor intentalo de nuevo."
					};
					alert.AddButton("Aceptar");
					alert.Show ();
				}
			};
		}