private async void LeaveParkingAndGotoMenu() { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var result = await mApiService.LeaveBooking(Mvx.Resolve <ICacheService>().CurrentUser.UserId, mCacheService.CurrentReservation.Parking.ParkingId, mCacheService.CurrentReservation.BookingId, Rating, Comment, "left"); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result)); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? result.Response.Result : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode))); if (result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } ShowViewModel <MenuViewModel>(presentationFlag: PresentationBundleFlagKeys.Menu); } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
public async void SaveParkingSpot() { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var result = await mApiService.PutParking(Mvx.Resolve <ICacheService>().CurrentUser.UserId, Mvx.Resolve <ICacheService>().ParkingId); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result)); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? "Success" : string.Format("Error {0}", result.Response.ErrorCode))); if (result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("Error : {0}", result.Response.ErrorCode), "Ok", null)); } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } }
public async void GetMyOwnParking() { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var results = await mApiService.OwnerParkings(Mvx.Resolve <ICacheService>().CurrentUser.UserId); if (results != null && results.Response.Count != 0) { Parkings.Clear(); foreach (var item in results.Response) { Parkings.Add(new OwnerParkingItemViewModel(mCacheService, this) { Parking = item, }); } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
public async void DeleteVehicle(string vehicleId) { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var result = await mApiService.DeleteVehicle(mCacheService.CurrentUser.UserId, vehicleId); if (result) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result)); Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result ? "Success" : "Error")); if (result) { var vehicle = mCacheService.UserVehicles.FirstOrDefault(x => x.VehicleId.Equals(vehicleId)); if (vehicle != null) { mCacheService.UserVehicles.Remove(vehicle); //save to local database BlobCache.UserAccount.InsertObject <List <Vehicle> >(mCacheService.CurrentUser.UserId, mCacheService.UserVehicles); } var vehicleVM = Vehicles.FirstOrDefault(x => x.Vehicle.VehicleId == vehicleId); if (vehicle != null) { Vehicles.Remove(vehicleVM); } } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
public async void GetMyReservations() { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var results = await mApiService.RenterBookings(Mvx.Resolve <ICacheService>().CurrentUser.UserId, DateTime.UtcNow.ToLocalTime().DateTimeToTimeStamp(), "sorting", 20, 0); Reservations.Clear(); if (results != null && results.Response.Count != 0) { foreach (var item in results.Response) { Reservations.Add(new ReservationItemViewModel(this) { Reservation = item, }); } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
private async void Update() { if (View != null) { View.CloseKeyboard(); } if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var result = await mApiService.PersonPut(mCacheService.CurrentUser, User.DateOfBirth, User.Street, User.City, User.PostalCode.ToString(), User.Country); if (result != null) { if (result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); Close(this); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
private async Task <int> GetVehiclesCount() { int toReturn = -1; Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); //if the vehicles list has already been loaded if (mCacheService.UserVehicles != null) { toReturn = mCacheService.UserVehicles.Count; } else { //trying to get vehicles from local database List <Vehicle> cachedVehicles = null; try { cachedVehicles = await BlobCache.UserAccount.GetObject <List <Vehicle> >(mCacheService.CurrentUser.UserId); } catch (KeyNotFoundException e) { Debug.WriteLine(e.Message); } //if there is no cached vehicles, then call api to get if (cachedVehicles == null) { if (BaseView != null && BaseView.CheckInternetConnection()) { var vehicles = await mApiService.GetVehicles((mCacheService.CurrentUser != null && !string.IsNullOrEmpty(mCacheService.CurrentUser.UserId))?mCacheService.CurrentUser.UserId : string.Empty); if (vehicles != null) { //cache all vehicles, to prevent reload the next attempt mCacheService.UserVehicles = vehicles.Response; toReturn = mCacheService.UserVehicles.Count; //save to local database BlobCache.UserAccount.InsertObject <List <Vehicle> >(mCacheService.CurrentUser.UserId, mCacheService.UserVehicles); } else { } } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } } else { mCacheService.UserVehicles = cachedVehicles; toReturn = mCacheService.UserVehicles.Count; } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); return(toReturn); }
private async void AddOrRemoveCard() { if (View != null) { View.CloseKeyboard(); } if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); if (IsHaveCreditCard) { Mvx.Resolve <IMvxMessenger>().Publish( new AlertMessage(this, string.Empty, "Please confirm you want to remove your payment card from our server", "No", () => { }, new string[] { "Yes" }, async() => { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var result = await mApiService.RemoveCard(mCacheService.CurrentUser.UserId); if (result) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result ? "Success" : "Error")); Close(this); } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); })); } else { var token = await Mvx.Resolve <IStripeService>().GetCardToken(HolderName, RealCardNumber, ValidityTime.Month, ValidityTime.Year % 100, Cryptogram); if (!string.IsNullOrEmpty(token)) { var result = await mApiService.AddCard(mCacheService.CurrentUser.UserId, token); if (result != null && result.Response != null) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Success")); Close(this); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, string.Format("Error {0}", result.ApiError.Error))); } } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Failed when get card token with Stripe")); } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
public async void DeleteParkingSpot() { if (BaseView != null && BaseView.CheckInternetConnection()) { //var result = await mApiService. } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
private async void PayWithCredits() { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var result1 = await mApiService.CreateBooking(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId.ToString(), StartTimeStamp, EndTimeStamp, PlateNumber); if (result1 != null && result1.Response != null) { if (result1.Response.Status.Equals("success")) { var result = await mApiService.PayBooking(mCacheService.CurrentUser.UserId, ParkingId.ToString(), result1.Response.BookingId); if (result != null) { if (result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, SharedTextSource.GetText("SuccessText"), SharedTextSource.GetText("ExtendSuccessfullyText"), SharedTextSource.GetText("OKText"), () => { NeedRelease = true; mCacheService.ExtendHours = Duration; ShowViewModel <ParkingReservedViewModel>(presentationFlag: PresentationBundleFlagKeys.ParkingReserved); Close(this); })); } else { Close(this); } } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result1.Response.Status, result1.Response.ErrorCode), "Ok", null)); } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
public async void GetVehicles() { IsEditMode = false; SwitchToDefaultMode(); //load user vehicles from cache if (mCacheService.UserVehicles != null) { Vehicles.Clear(); foreach (var vehicle in mCacheService.UserVehicles) { Vehicles.Add(new VehicleItemViewModel(this) { Vehicle = vehicle }); } return; } if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var vehicles = await mApiService.GetVehicles(mCacheService.CurrentUser.UserId); if (vehicles != null && vehicles.Response.Count > 0) { Vehicles.Clear(); foreach (var vehicle in vehicles.Response) { Vehicles.Add(new VehicleItemViewModel(this) { Vehicle = vehicle }); } //cache all vehicles, to prevent reload the next attempt mCacheService.UserVehicles = vehicles.Response; } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
public async void Init(double hourlyRate, double lat, double lng) { if (hourlyRate != 0) { //Mvx.Resolve<ICacheService>().CurrentLat = ; SelectedValue = (float)hourlyRate - 1; Longitude = lng; Latitude = lat; } else { SelectedPrice = SelectedValue + 1; Longitude = Mvx.Resolve <ICacheService>().CurrentLng; Latitude = Mvx.Resolve <ICacheService>().CurrentLat; } await Task.Delay(100); if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var results = await mApiService.RecommendPrice(Latitude, Longitude); if (results != null) { //RecommendedPrice = double.Parse(results.Prices.ParkingRateHourly, CultureInfo.InvariantCulture); decimal value = (decimal)Math.Round((decimal)results.Prices.ParkingRateHourly * 2m, MidpointRounding.AwayFromZero) / 2m; RecommendedPrice = (double)value; if (hourlyRate == 0) { SelectedValue = (float)RecommendedPrice - 1; } } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Api Invalid rec. price")); SelectedValue = 0; } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Please turn on internet")); } }
private async void AddOrReplaceBank() { if (View != null) { View.CloseKeyboard(); } if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var token = await StripeServiceForBank.GetCardToken(AccountName, BankAccount); if (!string.IsNullOrEmpty(token)) { var result = await mApiService.AddBank(mCacheService.CurrentUser.UserId, token); if (result != null && result.Response != null && result.Response.Status == "success") { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Success")); Close(this); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, string.Format("Error {0}", result.ApiError.Error))); } } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Failed when get card token with Stripe")); } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); if (IsHaveCreditCard) { GetBankAccountInformations(); } } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
public async void AvaiableParkingsInMap() { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true, string.Empty, true)); var gpsLatitude = AppConstants.locCenterOfBelgium[0]; var gpsLongitude = AppConstants.locCenterOfBelgium[1]; var maxDistance = AppConstants.MaxDistance; ObservableCollection <Parking> Tmp = new ObservableCollection <Parking>(); do { var parkings = await mApiService.AvaiableParkingsInMap(gpsLatitude, gpsLongitude, maxDistance, Tmp.Count); if (parkings != null && parkings.Response.Count != 0) { foreach (var parking in parkings.Response) { Tmp.Add(parking); } } if (parkings == null || parkings.Response.Count < AppConstants.LimitPerPage) { break; } } while (true); if (Tmp.Count == 0) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "No parkings")); } Parkings = Tmp; Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
public async void DeleteReservation() { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); /*var result = await mApiService.DeleteVehicle("userId", "vehicleId"); * if(result != null) * { * //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result)); * Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}: {1}", result.Result, result.ErrorCode))); * }*/ Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
public async void Init(string location) { await Task.Delay(100); //if user has edited parking spot address if (!string.IsNullOrEmpty(mCacheService.SpotAddress)) { Address = mCacheService.SpotAddress; return; } //if we are editing a parking spot if (!string.IsNullOrEmpty(location)) { Address = location; return; } //if we are adding a new parking spot if (mCacheService.CurrentLat != 0 && mCacheService.CurrentLng != 0) { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var result = await mApiService.AddressOf(mCacheService.CurrentLat, mCacheService.CurrentLng); if (result != null) { Address = result.Address; } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } } }
private async void LeaveBooking() { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve<IMvxMessenger>().Publish(new ProgressMessage(this, true)); if (Mode == ReportMode.PictureLeave || Mode == ReportMode.PictureRefuse) LeaveComment = Problem; if (Mode == ReportMode.PlateNumber || Mode == ReportMode.Unreachable) LeaveComment = PlateNumber; var result = await mApiService.LeaveBooking(Mvx.Resolve<ICacheService>().CurrentUser.UserId, mCacheService.CurrentReservation.Parking.ParkingId, mCacheService.CurrentReservation.BookingId, "0/1", LeaveComment, LeavingStatus); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result)); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? "Success" : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode))); if (result.Response.Status.Equals("success")) { Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); mPlatformService.SetPreference<long>(AppConstants.BookingExpiredTime, 0); mPlatformService.SetPreference<long>(AppConstants.CurrentBookingId, 0); } else { Mvx.Resolve<IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } ShowViewModel<ParkingListsViewModel>(presentationFlag: PresentationBundleFlagKeys.ParkingList); } Mvx.Resolve<IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
private void DeleteEvent() { if (IsReadOnly) { return; } Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, SharedTextSource.GetText("DeleteEventText"), SharedTextSource.GetText("AreYouSureDeleteEventText"), SharedTextSource.GetText("CancelText"), null, new string[] { SharedTextSource.GetText("ConfirmText") }, async() => { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var result = await mApiService.DeleteUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, UnavailabilityId); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result)); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}: {1}", result.Result, result.ErrorCode))); if (result) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Success")); Close(this); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", "", ""), "Ok", null)); } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } })); }
private async void AddEvent() { if (IsReadOnly) { return; } if (string.IsNullOrEmpty(EventTitle) || string.IsNullOrEmpty(EventTitle.Trim())) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Event title must not be empty")); return; } if (EndDate.CompareTo(DateTime.UtcNow.ToLocalTime()) != 1 || StartDate.CompareTo(DateTime.UtcNow.ToLocalTime()) != 1) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "End Date or Start Date must be later than now")); return; } if (EndDate.CompareTo(StartDate) == 0) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Start time & end time must be different when the dates are equal")); return; } if (EndDate.CompareTo(StartDate) > 0) { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); if (IsEditMode) { if (mOldRepeat.Equals("once")) { var result = await mApiService.PutUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, UnavailabilityId, EventTitle, Helpers.TimestampHelpers.DateTimeToTimeStamp(StartDate), Helpers.TimestampHelpers.DateTimeToTimeStamp(EndDate), new Periodicity() { }, "all", true, StartTimestampOfSelectedOccurrence); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}\n{1}",result.Result, result.ErrorCode ))); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}: {1}", result.Result, result.ErrorCode))); if (result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); mCacheService.NeedReloadEvent = true; Close(this); return; } //edit unavaiability Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, SharedTextSource.GetText("EditEventText"), SharedTextSource.GetText("AreYouSureEventText"), SharedTextSource.GetText("CancelText"), null, new string[] { SharedTextSource.GetText("EditFutureEventsText"), SharedTextSource.GetText("EditEventOnlyText") }, async() => { var result = await mApiService.PutUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, UnavailabilityId, EventTitle, Helpers.TimestampHelpers.DateTimeToTimeStamp(StartDate), Helpers.TimestampHelpers.DateTimeToTimeStamp(EndDate), new Periodicity() { Repeat = SelectedRepeat, OccurrencesAmount = Times, Exceptions = new List <PeriodicityException>() { } }, "all", false, StartTimestampOfSelectedOccurrence); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}\n{1}", result.Result, result.ErrorCode))); if (result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } } mCacheService.NeedReloadEvent = true; Close(this); }, async() => { var result = await mApiService.PutUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, UnavailabilityId, EventTitle, Helpers.TimestampHelpers.DateTimeToTimeStamp(StartDate), Helpers.TimestampHelpers.DateTimeToTimeStamp(EndDate), new Periodicity() { }, "all", true, StartTimestampOfSelectedOccurrence); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}\n{1}",result.Result, result.ErrorCode ))); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}: {1}", result.Result, result.ErrorCode))); if (result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } } mCacheService.NeedReloadEvent = true; Close(this); })); } else { //add unavaiability var result = await mApiService.CreateUnavailabilities(mCacheService.CurrentUser.UserId, mCacheService.ParkingId, EventTitle, Helpers.TimestampHelpers.DateTimeToTimeStamp(StartDate), Helpers.TimestampHelpers.DateTimeToTimeStamp(EndDate), new Periodicity() { Repeat = SelectedRepeat, OccurrencesAmount = Times }, "all"); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result)); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Equals("success") ? "Success" : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode))); if (result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); } else { if (result.ApiError.Status.Equals("999")) { Mvx.Resolve <IMvxMessenger> ().Publish(new AlertMessage(this, string.Empty, string.Format("{0}", result.Response.ErrorCode), "Ok", null)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } } } mCacheService.NeedReloadEvent = true; Close(this); } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "End Date must be later than Start Date")); } }
private async void SignIn() { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); //validate email and password var toValidate = new string[] { Email, Password }; SignInValidator validator = new SignInValidator(); ValidationResult results = validator.Validate(toValidate); if (results.IsValid) { //sign in if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); //login first var loginResult = await mApiService.Login(Email, Password, Mvx.Resolve <IPlatformService>().OS == OS.Touch?AppConstants.iOSToken : AppConstants.AndroidToken); if (loginResult != null) { //#region exception //if (loginResult.Result == null) //{ // mCacheService.SessionId = loginResult.SessionId; // mCacheService.CurrentUser = new User(Email, Password); // mCacheService.CurrentUser.UserId = loginResult.UserId; // //then get user information // var result = await mApiService.PersonGet(mCacheService.CurrentUser.UserId); // if (result != null) // { // mCacheService.CurrentUser = result.Response; // mCacheService.CurrentUser.Password = Password; // mCacheService.CurrentUser.UserId = result.Request.UserId; // BlobCache.UserAccount.InsertObject("CurrentUser", mCacheService.CurrentUser); // Mvx.Resolve<IPlatformService>().SetPreference(AppConstants.IsLogin, true); // } //}else // #endregion if (loginResult.Status.Equals("success")) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, loginResult.UserId)); mCacheService.SessionId = loginResult.SessionId; mCacheService.CurrentUser = new User(Email, Password); mCacheService.CurrentUser.UserId = loginResult.UserId; BlobCache.UserAccount.InsertObject("SessionId", mCacheService.SessionId); //then get user information var result = await mApiService.PersonGet(mCacheService.CurrentUser.UserId); if (result != null) { mCacheService.CurrentUser = result.Response; mCacheService.CurrentUser.Password = Password; mCacheService.CurrentUser.UserId = result.Request.UserId; BlobCache.UserAccount.InsertObject("CurrentUser", mCacheService.CurrentUser); Mvx.Resolve <IPlatformService>().SetPreference(AppConstants.IsLogin, true); } } else { if (loginResult.ErrorCode.Equals("888")) { Mvx.Resolve <IMvxMessenger> ().Publish(new AlertMessage(this, string.Empty, "Token is incorrect, please contact [email protected]", "Ok", null)); } else { Mvx.Resolve <IMvxMessenger> ().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", loginResult.Status, loginResult.ErrorCode), "Ok", null)); } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); return; } } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("Email or password is incorrect"), "Ok", null)); Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); return; } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } //then go to menu page ShowViewModel <MenuViewModel>(); Close(this); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, results.Errors[0].ToString().Trim())); } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); }
public async void GetUnavaiabilities(DateTime startDateTime) { if (currentStartDateTime != null && currentStartDateTime.Month == startDateTime.Month && !mCacheService.NeedReloadEvent) { return; } if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); Events.Clear(); if (mCacheService.NeedReloadEvent) { mCacheService.NeedReloadEvent = false; } currentStartDateTime = startDateTime; currentEndDateTime = startDateTime.AddDays(30); var results = await mApiService.OwnerUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, Helpers.TimestampHelpers.DateTimeToTimeStamp(currentStartDateTime), Helpers.TimestampHelpers.DateTimeToTimeStamp(currentEndDateTime), "startTimestamp"); if (results != null && results.Response.Count != 0) { foreach (var item in results.Response) { Events.Add(new EventItemViewModel(this) { Unavaiability = item, IsEditMode = false, IsSelected = false, }); } } var results2 = await mApiService.OwnerBookings(mCacheService.CurrentUser.UserId, ParkingId, Helpers.TimestampHelpers.DateTimeToTimeStamp(currentStartDateTime), Helpers.TimestampHelpers.DateTimeToTimeStamp(currentEndDateTime), "startTimestamp"); if (results2 != null && results2.Response.Count != 0) { foreach (var item in results2.Response) { Events.Add(new EventItemViewModel(this) { Booking = item, IsEditMode = false, IsSelected = false, }); } } if (Events != null && Events.Count > 0) { SaveEventsUnsort = new ObservableCollection <EventItemViewModel>(Events); NewSortUnavaiabilities(); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "No event!")); } if (View != null) { View.UpdateCalendar(true); } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
private async void Ok() { if (View != null) { View.CloseKeyboard(); } Mvx.Resolve <IMvxMessenger> ().Publish(new ProgressMessage(this, true)); //validate email and password var toValidate = new string [] { Email, "FakePasswordToPassValidator" }; SignInValidator validator = new SignInValidator(); ValidationResult results = validator.Validate(toValidate); if (results.IsValid) { //sign in if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger> ().Publish(new ProgressMessage(this, true)); if (View != null) { string identifier = View.GetDeviceIdentifier(); var result = await mApiService.LostPassword(Email, identifier, Mvx.Resolve <IPlatformService> ().OS == OS.Touch?AppConstants.iOSToken : AppConstants.AndroidToken); if (result != null) { if (result.Response != null && result.Response.Status.Equals("success")) { Close(this); } else { if (result.ApiError != null) { Mvx.Resolve <IMvxMessenger> ().Publish(new AlertMessage(this, string.Empty, result.ApiError.Error, "Ok", null)); } else { Mvx.Resolve <IMvxMessenger> ().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } Mvx.Resolve <IMvxMessenger> ().Publish(new ProgressMessage(this, false)); return; } } else { Mvx.Resolve <IMvxMessenger> ().Publish(new ProgressMessage(this, false)); return; } } } else { Mvx.Resolve <IMvxMessenger> ().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } } else { Mvx.Resolve <IMvxMessenger> ().Publish(new ToastMessage(this, results.Errors [0].ToString().Trim())); } Mvx.Resolve <IMvxMessenger> ().Publish(new ProgressMessage(this, false)); }
private async void GotoBooking(ParkingSlotItemViewModel itemVM) { /*if (BaseView != null && BaseView.CheckInternetConnection()) * { * Mvx.Resolve<IMvxMessenger>().Publish(new ProgressMessage(this, true)); * var result = await mApiService.CreateBooking("1","parkingId", 1101010101010 , 1010101010101, "carNumber"); * if (result != null) * { * //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result + "\n" + result.BookingId)); * Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? result.Response.Result : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode))); * ShowViewModel<BookingViewModel>(new {timeout = Int32.Parse(result.TimeoutDuration), cost = double.Parse(result.Cost), remainingCredits = Int32.Parse(result.RemainingCredits) }); * } * Mvx.Resolve<IMvxMessenger>().Publish(new ProgressMessage(this, false)); * } * else * { * Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); * }*/ if (BaseView != null && BaseView.CheckInternetConnection()) { //Mvx.Resolve<IMvxMessenger>().Publish(new ProgressMessage(this, true)); // long startTimeStamp = DateTime.UtcNow.DateTimeToTimeStamp(); // long endTimeStamp = DateTime.UtcNow.AddHours(ParkingTime + 1).DateTimeToTimeStamp(); long startTimeStamp = ValidTime.AddHours(-(ParkingTime + 1)).DateTimeToTimeStamp(); long endTimeStamp = ValidTime.DateTimeToTimeStamp(); double toWait = Math.Round((double)(DateTime.UtcNow.DateTimeToTimeStamp() - startTimeStamp) / 60); if (StartTimeStamp != 0) { startTimeStamp = StartTimeStamp; endTimeStamp = startTimeStamp + ((ParkingTime + 1) * 3600); toWait = Math.Round((double)(startTimeStamp - DateTime.UtcNow.DateTimeToTimeStamp()) / 60); } if (itemVM.ParkingSpot.BookingType == "immediate") { ShowViewModel <BookingViewModel>(new { parkingid = itemVM.ParkingSpot.ParkingId, distance = double.Parse(itemVM.ParkingSpot.Distance, CultureInfo.InvariantCulture), cost = itemVM.ParkingSpot.Cost, remainingCredits = double.Parse(mCacheService.CurrentUser.RemainingCredits, CultureInfo.InvariantCulture), toWait = toWait, duration = Math.Round((double)(endTimeStamp - startTimeStamp) / 3600), startTimestamp = startTimeStamp, endTimestamp = endTimeStamp }); } else if (itemVM.ParkingSpot.BookingType == "delayed") { ShowViewModel <DelayedParkingMapViewModel>(new { parkingid = itemVM.ParkingSpot.ParkingId, startTimestamp = startTimeStamp, endTimestamp = endTimeStamp }); } // var result = await mApiService.CreateBooking(Mvx.Resolve<ICacheService>().CurrentUser.UserId, itemVM.ParkingSpot.ParkingId, startTimeStamp, endTimeStamp, Vehicle.PlateNumber); // if (result != null && result.Response != null) // { // // Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result + "\n" + result.Response.BookingId)); // //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? result.Response.Result : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode))); // if (result.Response.Result.Equals("success")) // { // Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result)); // } // else // { // Mvx.Resolve<IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode), "Ok", null)); // } // } // Mvx.Resolve<IMvxMessenger>().Publish(new ProgressMessage(this, false)); // } // else // { // Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); // } } }
private void DeleteEvent(EventItemViewModel eventVM) { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, SharedTextSource.GetText("DeleteEventText"), SharedTextSource.GetText("AreYouSureDeleteEventText"), SharedTextSource.GetText("NoText"), null, new string[] { SharedTextSource.GetText("DeleteEventOnlyText"), SharedTextSource.GetText("DeleteFutureEventsText") }, async() => { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var result = await mApiService.DeleteUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, eventVM.Unavaiability.UnavailabilityId); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result)); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}: {1}", result.Result, result.ErrorCode))); if (result) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Success")); if (Events.Contains(eventVM)) { Events.Remove(eventVM); } if (View != null) { View.UpdateCalendar(true); } } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", "", ""), "Ok", null)); } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }, async() => { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var result = await mApiService.DeleteUnavailabilities(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId, eventVM.Unavaiability.UnavailabilityId); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result)); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result.Equals("success") ? result.Result : string.Format("{0}: {1}", result.Result, result.ErrorCode))); if (result) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Success")); if (View != null) { View.UpdateCalendar(); } } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", "", ""), "Ok", null)); } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); // Android only: When dismiss delete dialog, Android cannot call resume to call GetUnavaiabilities so we call manual if (AddSpotCalendarTabView != null) { AddSpotCalendarTabView.GetUnavaiabilities(); } /////////////////////////////// } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } })); }
public async void GetParkingLists() { if (BaseView != null && BaseView.CheckInternetConnection()) { if (Latitude == 0 && Longitude == 0 && mCacheService.SearchMode == SearchMode.Later) { return; } if (mCacheService.CurrentLat == 0 && mCacheService.CurrentLng == 0) { return; } //if (mCacheService.SearchMode == SearchMode.Now) //{ Title = "Please choose"; if (View != null) { await Task.Delay(100); View.Stop60sTimer(); } //} IsShowParkingLists = false; Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true, string.Empty, true)); long startTimeStamp = DateTime.UtcNow.DateTimeToTimeStamp(); //long endTimeStamp = DateTime.UtcNow.AddHours(ParkingTime + 1).DateTimeToTimeStamp(); long endTimeStamp = ValidTime.DateTimeToTimeStamp(); if (StartTimeStamp != 0) { startTimeStamp = StartTimeStamp; } Vehicle = mCacheService.SelectedVehicle; double lat = Latitude != 0 ? Latitude : mCacheService.CurrentLat; double lng = Longitude != 0 ? Longitude : mCacheService.CurrentLng; ParkingSlots.Clear(); string maxdistance = string.Empty; if (StartTimeStamp == 0) { maxdistance = "1000"; } else { maxdistance = "10000"; } var parkings = await mApiService.AvaiableParkings(startTimeStamp, endTimeStamp, 2, lat, lng, maxdistance, Vehicle.Type); if (parkings != null && parkings.Response.Count != 0) { ObservableCollection <ParkingSlotItemViewModel> Tmp = new ObservableCollection <ParkingSlotItemViewModel>(); foreach (var parking in parkings.Response) { if (mCacheService.SearchMode == SearchMode.Now && parking.BookingType == "delayed") { continue; } Tmp.Add(new ParkingSlotItemViewModel() { ParkingSpot = parking, IsShowClock = startTimeStamp < Convert.ToInt64(parking.AvailabilityStartTimestamp) }); } ParkingSlots = Tmp; } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "No parkings")); } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); IsShowParkingLists = true; } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
private async void GotoParkingReserved() { Mvx.Resolve <IMvxMessenger>().Publish( new AlertMessage(this, "Confirm", string.Format("Your payment card will be charged {0} €", string.Format("{0:0.0}", Cost)), "Cancel", () => { }, new string[] { "OK" }, async() => { if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); var result1 = await mApiService.CreateBooking(Mvx.Resolve <ICacheService>().CurrentUser.UserId, ParkingId.ToString(), StartTimeStamp, EndTimeStamp, Vehicle.PlateNumber); if (result1 != null && result1.Response != null) { // Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result + "\n" + result.Response.BookingId)); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? result.Response.Result : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode))); if (result1.Response.Status.Equals("success")) { BookingId = long.Parse(result1.Response.BookingId); var result = await mApiService.PayBooking(mCacheService.CurrentUser.UserId, ParkingId.ToString(), result1.Response.BookingId); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result + "\nRemaining credits : " + result.RemainingCredits)); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? "Success" : "Error")); if (result.Response != null && result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); NeedRelease = true; if (mCacheService.SearchMode == SearchMode.Now) { //TODO : mCacheService.CurrentReservation = ?????? Parking parking = new Parking() { ParkingId = ParkingId.ToString(), Location = result.Response.Location, Latitude = result.Response.Latitude, Longitude = result.Response.Longitude }; Reservation reservation = new Reservation() { BookingId = BookingId.ToString(), Cost = Cost.ToString(), StartTimestamp = StartTimeStamp.ToString(), EndTimestamp = EndTimeStamp.ToString(), Parking = parking, PlateNumber = Vehicle.PlateNumber, VehicleType = Vehicle.Type, }; mCacheService.CurrentReservation = reservation; //mCacheService.CurrentUser.RemainingCredits = (double.Parse(mCacheService.CurrentUser.RemainingCredits, CultureInfo.InvariantCulture) - Cost).ToString(); //mCacheService.CurrentUser.RemainingCredits = result.Response.RemainingCredits; ShowViewModel <ParkingReservedViewModel>(new { status = ParkingStatus.Rented }); } else { ShowViewModel <MenuViewModel>(presentationFlag: PresentationBundleFlagKeys.Menu); } } else if (result.ApiError.Error != null && result.ApiError.Error.Equals("cardTrouble")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Please add a credit card in the Wallet section!")); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } } else { //Close(this); Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Error occur!")); } } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result1.Response.Status, result1.Response.ErrorCode), "Ok", null)); } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } })); }
private async void SignUpOrUpdate() { if (View != null) { View.CloseKeyboard(); } if (BaseView != null && BaseView.CheckInternetConnection()) { Mvx.Resolve <IMvxMessenger> ().Publish(new ProgressMessage(this, true)); if (IsShowInfo)//update { var result = await mApiService.PersonPut(mCacheService.CurrentUser.UserId, User.FirstName, User.LastName, User.Email, Password, User.PhoneNumber, User.FacebookId, User.Street, User.PostalCode, User.City, User.Country, User.DateOfBirth); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? result.Response.Result : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode))); if (result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger> ().Publish(new ToastMessage(this, result.Response.Status)); } else { Mvx.Resolve <IMvxMessenger> ().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } } Mvx.Resolve <IMvxMessenger> ().Publish(new ProgressMessage(this, false)); Close(this); } else { if (IsAcceptTerms) { if (string.IsNullOrEmpty(Password)) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Please fill a password")); Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); return; } //sign up var deviceIdentifier = View.GetDeviceIdentifier(); var result = await mApiService.PersonRegister(User.Email, Password, User.FirstName, User.LastName, User.PhoneNumber, Mvx.Resolve <IPlatformService> ().OS == OS.Touch?AppConstants.iOSToken : AppConstants.AndroidToken, deviceIdentifier); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? string.Format("{0}: {1}", result.Response.Result, result.Response.PersonId) : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode))); if (result.Response != null && result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger> ().Publish(new ToastMessage(this, result.Response.Status)); } else { if (result.ApiError != null && result.ApiError.Status.Equals("777")) { Mvx.Resolve <IMvxMessenger> ().Publish(new AlertMessage(this, string.Empty, "Token is incorrect, please contact [email protected]", "Ok", null)); } else { Mvx.Resolve <IMvxMessenger> ().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } Mvx.Resolve <IMvxMessenger> ().Publish(new ProgressMessage(this, false)); return; } var result2 = await mApiService.Login(User.Email, Password, Mvx.Resolve <IPlatformService> ().OS == OS.Touch?AppConstants.iOSToken : AppConstants.AndroidToken); if (result2 != null) { mCacheService.SessionId = result2.SessionId; mCacheService.CurrentUser = new User(); mCacheService.CurrentUser.UserId = result2.UserId; //then get user information var result3 = await mApiService.PersonGet(mCacheService.CurrentUser.UserId); if (result3 != null) { mCacheService.CurrentUser = result3.Response; mCacheService.CurrentUser.UserId = result3.Request.UserId; } //then update user information (F1.3) var result4 = await mApiService.PersonPut(mCacheService.CurrentUser.UserId, User.FirstName, User.LastName, User.Email, Password, User.PhoneNumber, User.FacebookId, User.Street, User.PostalCode, User.City, User.Country, User.DateOfBirth); if (result4 != null) { if (result4.Response.Status.Equals("success")) { Debug.WriteLine("Update person information : " + result4.Response.Status); } else { Mvx.Resolve <IMvxMessenger> ().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result4.Response.Status, result4.Response.ErrorCode), "Ok", null)); } } ShowViewModel <MenuViewModel> (); } } else { //Mvx.Resolve<IMvxMessenger> ().Publish (new ToastMessage (this, "This email is already registered. Please login or ask for a new password at [email protected]")); Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, "Please check the email.")); } Mvx.Resolve <IMvxMessenger> ().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger> ().Publish(new ToastMessage(this, SharedTextSource.GetText("AcceptTermsText"))); } Mvx.Resolve <IMvxMessenger> ().Publish(new ProgressMessage(this, false)); } } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
private async void AddNewVehicle() { if (BaseView != null && BaseView.CheckInternetConnection()) { var isChecked = VehicleTypes.FirstOrDefault(x => x.IsChecked == true); if (isChecked != null && !string.IsNullOrEmpty(PlateNumber)) { Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, true)); if (IsEditMode) { var result = await mApiService.PutVehicle(mCacheService.CurrentUser.UserId, VehicleId, isChecked.Type, PlateNumber); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result)); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? result.Response.Result : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode))); if (result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } //update user vehicles that has been cached if (result.Response.Status.Equals("success")) { var vehicle = mCacheService.UserVehicles.FirstOrDefault(x => x.VehicleId.Equals(VehicleId)); if (vehicle != null) { vehicle.Type = isChecked.Type; vehicle.PlateNumber = PlateNumber; } Mvx.Resolve <IMvxMessenger>().Publish(new UpdateSuccessMessage(this)); //save to local database BlobCache.UserAccount.InsertObject <List <Vehicle> >(mCacheService.CurrentUser.UserId, mCacheService.UserVehicles); } Close(this); } } else { var result = await mApiService.CreateVehicle(mCacheService.CurrentUser.UserId, isChecked.Type, PlateNumber); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Result + "\n" + result.VehicleId)); //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? result.Response.Result : string.Format("{0}: {1}", result.Response.Result, result.Response.ErrorCode))); if (result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } if (result.Response.Status.Equals("success")) { var vehicle = new Vehicle() { VehicleId = result.Response.VehicleId, Type = isChecked.Type, PlateNumber = PlateNumber }; if (!mCacheService.UserVehicles.Contains(vehicle)) { mCacheService.UserVehicles.Add(vehicle); } Mvx.Resolve <IMvxMessenger>().Publish(new UpdateSuccessMessage(this)); //save to local database BlobCache.UserAccount.InsertObject <List <Vehicle> >(mCacheService.CurrentUser.UserId, mCacheService.UserVehicles); } Close(this); } } Mvx.Resolve <IMvxMessenger>().Publish(new ProgressMessage(this, false)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, isChecked != null ? mCacheService.TextSource.GetText("PleaseEnterPlateNumberText") : mCacheService.TextSource.GetText("PleaseChooseVehicleTypeText"))); } } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } }
private async void AddSpot() { var taskLeft = Tasks.FirstOrDefault(x => x.Finished == false); if (taskLeft == null) { //call api if (BaseView != null && BaseView.CheckInternetConnection()) { if (IsEditMode) { var result = await mApiService.PutParking(Mvx.Resolve <ICacheService>().CurrentUser.UserId, Parking.ParkingId); if (result != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? "Success" : string.Format("Error {0}", result.Response.ErrorCode))); if (result.Response.Status.Equals("success")) { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("Error : {0}", result.Response.ErrorCode), "Ok", null)); } Close(this); } } else { //add new parking spot var result = await mApiService.CreateParking(Mvx.Resolve <ICacheService>().CurrentUser.UserId); if (result.Response != null) { //Mvx.Resolve<IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Result.Equals("success") ? "Success" : string.Format("Error: {0}", result.Response.ErrorCode))); if (result.Response.Status.Equals("success")) { IsEditMode = true; if (Parking == null) { Parking = new OwnerParkingsResponse(); } Parking.ParkingId = result.Response.ParkingId; Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, result.Response.Status)); } else { Mvx.Resolve <IMvxMessenger>().Publish(new AlertMessage(this, string.Empty, string.Format("{0}: {1}", result.Response.Status, result.Response.ErrorCode), "Ok", null)); } Close(this); } } } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, SharedTextSource.GetText("TurnOnInternetText"))); } } else { Mvx.Resolve <IMvxMessenger>().Publish(new ToastMessage(this, string.Format("{0} {1}", taskLeft.Title, TextSource.GetText("HasNotBeenDoneText")))); } }