static void Main(String[] args) { try { InitializerAPI.InitAPI(); IEventHandler <Person> eventHandler = Backendless.Data.Of <Person>().RT(); eventHandler.AddCreateListener(createdObject => { Console.WriteLine($"Person object has been created. Object Id - { createdObject.ObjectId }"); }); Backendless.RT.AddConnectErrorListener((fault) => { Console.WriteLine($"Connection error. {fault}"); }); Backendless.RT.AddConnectListener(() => { Backendless.Data.Of <Person>().Save(new Person("Joe", 21)); }); } catch (Exception e) { Console.WriteLine("An error occurred during the operation" + e); } Console.ReadKey(); }
public void EnableRT(Object sender, EventArgs ea) { IEventHandler <Person> eventHandler = Backendless.Data.Of <Person>().RT(); Boolean CheckObjectCreation = false; Backendless.RT.AddConnectListener(async() => { if (!CheckObjectCreation) { await Backendless.Data.Of <Person>().SaveAsync(new Person("Joe", 21)); CheckObjectCreation = true; } }); Backendless.RT.AddConnectErrorListener((fault) => { Device.BeginInvokeOnMainThread(async() => { await DisplayAlert("Error", "Connection cannot be established " + fault.Message, "Ok"); }); }); eventHandler.AddCreateListener(createdObject => { Device.BeginInvokeOnMainThread(async() => { await DisplayAlert("Event", $"Person object has been created. Object id: {createdObject.ObjectId}", "Ok"); }); }); ambiguousButton.IsEnabled = false; }
//Constructor for the class public ReservationCreatedEventListener(MainForm masterform) { _masterform = masterform; reservationCreatedEvent = Backendless.Data.Of <Reservation>().RT(); reservationCreatedEvent.AddCreateListener("restaurantId = '" + OwnerStorage.ThisRestaurant.objectId + "'", createdOrder => { createdOrder.TakenFrom = createdOrder.TakenFrom.AddHours(2); createdOrder.TakenTo = createdOrder.TakenTo.AddHours(2);//<--+2:00 for Time Zone Boolean flag = false; foreach (Reservation r in OwnerStorage.ActiveReservations) { if (createdOrder.objectId == r.objectId) { flag = true; } } if (flag != true) { AsyncCallback <BackendlessUser> loadContactCallback = new AsyncCallback <BackendlessUser>( foundContact => { //Success. the reservation will now be added to the flp on the main form if (foundContact != null) { OwnerStorage.AllUsers.Add(foundContact); OwnerStorage.ActiveReservations.Add(createdOrder); _masterform.AddOneReservationView(createdOrder); //Determines if the reservation was made by the restaurant or by a customer if (foundContact.ObjectId == OwnerStorage.CurrentlyLoggedIn.ObjectId) { OwnerStorage.LogInfo.Add("Reservation has been created\nName: " + createdOrder.Name + "\nCreated By: Restaurant"); OwnerStorage.LogTimes.Add(System.DateTime.Now.ToString("HH:mm:ss")); } else { OwnerStorage.LogInfo.Add("Reservation has been created\nName: " + createdOrder.Name + "\nCreated By: Customer"); OwnerStorage.LogTimes.Add(System.DateTime.Now.ToString("HH:mm:ss")); } } }, error => { }); //Callback to find the user who created the reservation Backendless.Data.Of <BackendlessUser>().FindById(createdOrder.UserId, loadContactCallback); } }); }