private async void Delete() { var answer = await Application.Current.MainPage.DisplayAlert( Languages.Confirm, Languages.DeleteConfirmation, Languages.Yes, Languages.No); if (!answer) { return; } this.IsRunning = true; this.IsEnabled = false; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, connection.Message, Languages.Accept); return; } var url = Application.Current.Resources["UrlAPI"].ToString(); var prefix = Application.Current.Resources["UrlPrefix"].ToString(); var controller = Application.Current.Resources["UrlVehiclesController"].ToString(); var response = await this.apiService.Delete(url, prefix, controller, this.Vehicle.VehicleId); if (!response.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert(Languages.Error, response.Message, Languages.Accept); return; } var vehiclesViewModel = VehiclesViewModel.GetInstance(); var deletedVehicle = vehiclesViewModel.MyVehicles.Where(p => p.VehicleId == this.Vehicle.VehicleId).FirstOrDefault(); if (deletedVehicle != null) { vehiclesViewModel.MyVehicles.Remove(deletedVehicle); } vehiclesViewModel.RefreshLIst(); this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.Navigation.PopAsync(); }
private async void Save() { if (string.IsNullOrEmpty(this.Brand)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.BrandError, Languages.Accept); return; } if (string.IsNullOrEmpty(this.Type)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.TypeError, Languages.Accept); return; } if (string.IsNullOrEmpty(this.Owner)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.OwnerError, Languages.Accept); return; } if (string.IsNullOrEmpty(this.Model)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.ModelError, Languages.Accept); return; } var model = int.Parse(this.Model); if (model < 0) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.NegativeNumbers, Languages.Accept); return; } if (string.IsNullOrEmpty(this.Mileage)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.MileageError, Languages.Accept); return; } var mileage = int.Parse(this.Mileage); if (mileage < 0) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.NegativeNumbers, Languages.Accept); return; } if (string.IsNullOrEmpty(this.Price)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.PriceError, Languages.Accept); return; } var price = decimal.Parse(this.Price); if (price < 0) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.NegativeNumbers, Languages.Accept); return; } if (string.IsNullOrEmpty(this.Specifications)) { await Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.SpecificationsError, Languages.Accept); return; } this.IsRunning = true; this.IsEnabled = false; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert( Languages.Error, connection.Message, Languages.Accept); return; } byte[] imageArray = null; if (this.file != null) { imageArray = FilesHelper.ReadFully(this.file.GetStream()); } var vehicle = new Vehicle { Brand = this.Brand, Type = this.Type, Owner = this.Owner, Model = model, Mileage = mileage, Price = price, Specifications = this.Specifications, ImageArray = imageArray, IsNegotiable = this.IsNegotiable, }; var url = Application.Current.Resources["UrlAPI"].ToString(); var prefix = Application.Current.Resources["UrlPrefix"].ToString(); var controller = Application.Current.Resources["UrlVehiclesController"].ToString(); var response = await this.apiService.Post(url, prefix, controller, vehicle); if (!response.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert( Languages.Error, response.Message, Languages.Accept); return; } var newVehicle = (Vehicle)response.Result; var vehiclesViewModel = VehiclesViewModel.GetInstance(); vehiclesViewModel.MyVehicles.Add(newVehicle); vehiclesViewModel.RefreshLIst(); this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.Navigation.PopAsync(); }
private async void Save() { //PREGUNTAR SI TODOS LOS CAMPOS SIN OBLIGATORIOS PARA SABER SI VAN O NO ALGUNAS VALIDACIONES if (string.IsNullOrEmpty(this.Vehicle.Brand)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.BrandError, Languages.Accept); return; } if (string.IsNullOrEmpty(this.Vehicle.Type)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.TypeError, Languages.Accept); return; } if (string.IsNullOrEmpty(this.Vehicle.Owner)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.OwnerError, Languages.Accept); return; } if (this.Vehicle.Model < 0) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.NegativeNumbers, Languages.Accept); return; } var model = Convert.ToString(this.Vehicle.Model); if (string.IsNullOrEmpty(model)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.ModelError, Languages.Accept); return; } if (this.Vehicle.Mileage < 0) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.NegativeNumbers, Languages.Accept); return; } var mileage = Convert.ToString(this.Vehicle.Mileage); if (string.IsNullOrEmpty(mileage)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.MileageError, Languages.Accept); return; } if (this.Vehicle.Price < 0) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.NegativeNumbers, Languages.Accept); return; } var price = Convert.ToString(this.Vehicle.Price); if (string.IsNullOrEmpty(price)) { await Application.Current.MainPage.DisplayAlert( Languages.Error, Languages.PriceError, Languages.Accept); return; } if (string.IsNullOrEmpty(this.Vehicle.Specifications)) { await Application.Current.MainPage.DisplayAlert(Languages.Error, Languages.SpecificationsError, Languages.Accept); return; } //PREGUNTAR SI TODOS LOS CAMPOS SIN OBLIGATORIOS PARA SABER SI VAN O NO ALGUNAS VALIDACIONES this.IsRunning = true; this.IsEnabled = false; var connection = await this.apiService.CheckConnection(); if (!connection.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert( Languages.Error, connection.Message, Languages.Accept); return; } byte[] imageArray = null; if (this.file != null) { imageArray = FilesHelper.ReadFully(this.file.GetStream()); this.Vehicle.ImageArray = imageArray; } var url = Application.Current.Resources["UrlAPI"].ToString(); var prefix = Application.Current.Resources["UrlPrefix"].ToString(); var controller = Application.Current.Resources["UrlVehiclesController"].ToString(); var response = await this.apiService.Put(url, prefix, controller, this.Vehicle, this.Vehicle.VehicleId); if (!response.IsSuccess) { this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.DisplayAlert( Languages.Error, response.Message, Languages.Accept); return; } var newVehicle = (Vehicle)response.Result; var vehiclesViewModel = VehiclesViewModel.GetInstance(); var oldVehicle = vehiclesViewModel.MyVehicles.Where(p => p.VehicleId == this.Vehicle.VehicleId).FirstOrDefault(); if (oldVehicle != null) { vehiclesViewModel.MyVehicles.Remove(oldVehicle); } vehiclesViewModel.MyVehicles.Add(newVehicle); vehiclesViewModel.RefreshLIst(); this.IsRunning = false; this.IsEnabled = true; await Application.Current.MainPage.Navigation.PopAsync(); }