public void GetUserMessages(string userID, Delegates.GetUserMessages success, Delegates.GeneralListenerFail fail) { FirebaseDatabase.DefaultInstance.GetReference(DBTable.User.ToString()).Child(userID).Child(Parameters.messages.ToString()) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { fail(task.Exception.ToString()); } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result; List <MessageModel> messages = new List <MessageModel> (); foreach (var message in snapshot.Children) { string json = message.GetRawJsonValue(); MessageModel mMessage = JsonUtility.FromJson <MessageModel> (json); messages.Add(mMessage); } success(messages); } }); }
public void GetAllCompanies(Delegates.GetAllCompanies getAllCompanies, Delegates.GeneralListenerFail getAllCompaniesFail) { FirebaseDatabase.DefaultInstance.GetReference(DBTable.Company.ToString()) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { getAllCompaniesFail(task.Exception.ToString()); } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result; List <CompanyModel> companies = new List <CompanyModel> (); foreach (var company in snapshot.Children) { string json = company.GetRawJsonValue(); CompanyModel mcompany = JsonUtility.FromJson <CompanyModel> (json); companies.Add(mcompany); } getAllCompanies(companies); } }); }
public void UpdateSeviceResponsible(string responsibleID, ServicesProvidedModel service, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { string json = JsonUtility.ToJson(service); reference.Child(DBTable.Responsible.ToString()).Child(responsibleID).Child(Parameters.servicesProvided.ToString()).Child(service.serviceID).SetRawJsonValueAsync(json).ContinueWith(task => { if (task.IsFaulted) { fail(task.Exception.ToString()); } else if (task.IsCompleted) { success(); } }); }
public static void RemoveAppointmentFromUser(AppointmentModel appointment, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { FireBaseManager.GetFireBaseInstance().DeleteAppointment(appointment, delegate() { currentUser.appoitments.Remove(appointment.appointmentID); string minute = (appointment.minute.ToString() == "0" ? "00" : "0"); var message = string.Format("{0} desmarcou o agendamento de {1} marcado para dia {2} às {3}:{4}h", currentUser.name, appointment.description, appointment.data, appointment.hour, minute); CreateNewMessageFromUserToResponsilbe(currentUser, currentResponsible, message, Constants.MessageType.RemoveAppointment.ToString(), delegate() { }, delegate(string error) { }); success(); }, delegate(string error) { fail(error); }); }
public static void RemoveResponsibleFromCompany(UserModel user, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { FirebaseAPIHelper.GetFireBaseAPIHelperInstance().RemoveUser(user.userID, delegate() { FireBaseManager.GetFireBaseInstance().RemoveResponsibleFromCompany(currentUser.userID, user.userID, user.userType, delegate() { responsibles.Remove(user as ResponsibleModel); GetAllResponsablesFromCompanyAsUser(); success(); }); }, fail); }
static void UpdateServiceResponsible(ServicesProvidedModel service, string responsibleID, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { FireBaseManager.GetFireBaseInstance().UpdateSeviceResponsible(responsibleID, service, delegate() { success(); }, delegate(string error) { fail(error); }); }
public static void UpdateResponsibleServices(ResponsibleModel responsible, List <ServicesProvidedModel> services, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { FireBaseManager.GetFireBaseInstance().RemoveAllServcesFromResponsible(responsible.companyID, responsible, delegate() { FireBaseManager.GetFireBaseInstance().AddServicesToResponsible(responsible.companyID, responsible, services); success(); }, delegate(string error) { fail(error); }); }
public static void CreateNewMessageFromClientOrCompanyToResponsilbe(UserModel from, string toID, string message, string type, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { string companyID = ""; var mMessage = new MessageModel(from.name, toID, message, DateTime.Now.ToString(Constants.dateformat), type); if (from.userType == Constants.UserType.Responsible.ToString()) { companyID = (from as ResponsibleModel).companyID; FireBaseManager.GetFireBaseInstance().CreateNewMessage(mMessage, from.userID, toID, companyID, delegate() { success(); }, delegate(string error) { fail(error); }); } else if (from.userType == Constants.UserType.Client.ToString()) { FireBaseManager.GetFireBaseInstance().CreateNewMessageScheduleByCompany(mMessage, toID, currentResponsible.companyID, delegate() { success(); }, delegate(string error) { fail(error); }); } else { fail("Usuário não é um profissional!"); } }
public static void CreateNewAppointment(UserModel user, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { var appointment = new AppointmentModel(dateNewAppointment, user.userID, user.name, currentResponsible.userID, currentResponsible.name, currentservice.name, Mathf.RoundToInt((currentservice.duration) * 60)); FireBaseManager.GetFireBaseInstance().CreateNewAppoitment(user, currentResponsible, appointment, delegate(AppointmentModel mappointment) { success(); string minute = (dateNewAppointment.Minute == 0 ? "00" : "0"); var message = string.Format("{0} realizou novo agendamento de {1} para dia {2}/{3} às {4}:{5}h", user.name, currentservice.name, dateNewAppointment.Day, dateNewAppointment.Month, dateNewAppointment.Hour, minute); if (user.userType == Constants.UserType.User.ToString()) { CreateNewMessageFromUserToResponsilbe(user, currentResponsible, message, Constants.MessageType.ScheduleAppointment.ToString(), delegate() { }, delegate(string error) { }); } else { CreateNewMessageFromClientOrCompanyToResponsilbe(user, currentResponsible.userID, message, Constants.MessageType.ScheduleAppointment.ToString(), delegate() { }, delegate(string error) { }); } }, fail); }
public void GetUserAppointments(string userID, Delegates.GetResponsibleAppointments success, Delegates.GeneralListenerFail fail) { FirebaseDatabase.DefaultInstance.GetReference(DBTable.User.ToString()).Child(userID).Child(Parameters.appointments.ToString()) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { fail(task.Exception.ToString()); } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result; List <AppointmentModel> appointments = new List <AppointmentModel> (); foreach (var appointment in snapshot.Children) { string json = appointment.GetRawJsonValue(); AppointmentModel mAppointment = JsonUtility.FromJson <AppointmentModel> (json); appointments.Add(mAppointment); } success(appointments); } }); }
public void UpdateServicesFromAllResponsibles(List <ResponsibleModel> responsibles, Delegates.GetAllServicesProvided success, Delegates.GeneralListenerFail fail) { int count = 0; List <ResponsibleModel> responsiblesWithServices = responsibles; foreach (var responsible in responsibles) { FirebaseDatabase.DefaultInstance.GetReference(DBTable.Responsible.ToString()).Child(responsible.userID).Child(Parameters.servicesProvided.ToString()) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { fail(task.Exception.ToString()); } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result; List <ServicesProvidedModel> services = new List <ServicesProvidedModel> (); foreach (var service in snapshot.Children) { string json = service.GetRawJsonValue(); ServicesProvidedModel mservice = JsonUtility.FromJson <ServicesProvidedModel> (json); services.Add(mservice); } responsiblesWithServices [count].servicesProvided = services.ToDictionary(x => x.serviceID, x => (object)x); count++; if (count >= responsibles.Count) { success(responsiblesWithServices); } } }); } }
public void GetAllClientsFromCompany(String companyID, Delegates.GetAllClients getAllClientsListener, Delegates.GeneralListenerFail fail) { FirebaseDatabase.DefaultInstance.GetReference(DBTable.Company.ToString()).Child(companyID).Child(Parameters.clients.ToString()) .GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { fail(task.Exception.ToString()); } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result; List <UserModel> clients = new List <UserModel> (); foreach (var client in snapshot.Children) { string json = client.GetRawJsonValue(); clients.Add(JsonUtility.FromJson <UserModel> (json)); } getAllClientsListener(clients); } }); }
public void DeleteClientToCompany(string companyID, UserModel userModel, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { reference.Child(DBTable.Company.ToString()).Child(companyID).Child(Parameters.clients.ToString()).Child(userModel.userID).RemoveValueAsync().ContinueWith(task => { if (task.IsFaulted) { fail(task.Exception.ToString()); } else if (task.IsCompleted) { success(); } }); }
public void AddClientToCompany(string companyID, UserModel userModel, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { string json = JsonUtility.ToJson(userModel); reference.Child(DBTable.Company.ToString()).Child(companyID).Child(Parameters.clients.ToString()).Child(userModel.userID).SetRawJsonValueAsync(json).ContinueWith(task => { if (task.IsFaulted) { fail(task.Exception.ToString()); } else if (task.IsCompleted) { success(); } }); }
public void RemoveAllServcesFromResponsible(string companyID, ResponsibleModel responsible, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { reference.Child(DBTable.Company.ToString()).Child(Parameters.responsibles.ToString()).Child(responsible.userID).Child(Parameters.servicesProvided.ToString()).RemoveValueAsync(); reference.Child(DBTable.Responsible.ToString()).Child(responsible.userID).Child(Parameters.servicesProvided.ToString()).RemoveValueAsync().ContinueWith(task => { if (task.IsFaulted) { fail(task.Exception.ToString()); } else if (task.IsCompleted) { responsible.servicesProvided.Clear(); success(); } }); }
public static void CreateNewClientToCompany(string name, string phone, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { var user = FireBaseManager.GetFireBaseInstance().CreateNewClient(name, phone); FireBaseManager.GetFireBaseInstance().AddClientToCompany(companyData.userID, user, delegate() { if (currentUser.userType == Constants.UserType.Company.ToString()) { (currentUser as CompanyModel).clients.Add(user.userID, (object)user); } success(); }, delegate(string error) { fail(error); }); }
public static void CreateNewAppointmentToCurrentUser(Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { CreateNewAppointment(currentUser, success, fail); }
public void CreateNewAppoitment(UserModel user, ResponsibleModel responsable, AppointmentModel appointment, Delegates.CreateNewAppointment success, Delegates.GeneralListenerFail fail) { string appoitmentID = reference.Child(DBTable.Appointments.ToString()).Push().Key; appointment.appointmentID = appoitmentID; // TODO Get appointments dinamicaly // user.appoitments[appoitmentID] = (object)responsable.userID; // responsable.appoitments[appoitmentID] = (object)user.userID; string json = JsonUtility.ToJson(appointment); CreateTable(DBTable.Appointments, appoitmentID, json); reference.Child(DBTable.User.ToString()).Child(user.userID).Child(Parameters.appointments + "/" + appoitmentID).SetRawJsonValueAsync(json).ContinueWith(task2 => { if (task2.IsFaulted) { fail(task2.Exception.ToString()); } else if (task2.IsCompleted) { reference.Child(DBTable.Responsible.ToString()).Child(responsable.userID).Child(Parameters.appointments + "/" + appoitmentID).SetRawJsonValueAsync(json).ContinueWith(task3 => { if (task3.IsFaulted) { fail(task3.Exception.ToString()); } else if (task3.IsCompleted) { success(appointment); } }); } }); }
public static void CreateNewMessageFromUserToResponsilbe(UserModel from, ResponsibleModel responsible, string message, string type, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { string companyID = ""; var mMessage = new MessageModel(from.name, responsible.userID, message, DateTime.Now.ToString(Constants.dateformat), type); if (from.userType == Constants.UserType.User.ToString()) { FireBaseManager.GetFireBaseInstance().CreateNewMessage(mMessage, from.userID, responsible.userID, responsible.companyID, delegate() { success(); }, delegate(string error) { fail(error); }); } else { fail("Usuário não é um profissional!"); } }
public void DeleteAppointment(AppointmentModel appointment, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { FirebaseDatabase.DefaultInstance.GetReference(DBTable.Appointments.ToString()).Child(appointment.appointmentID).RemoveValueAsync().ContinueWith(task => { if (task.IsFaulted) { fail(task.Exception.ToString()); } else { FirebaseDatabase.DefaultInstance.GetReference(DBTable.User.ToString()).Child(appointment.userID).Child(Parameters.appointments.ToString()).Child(appointment.appointmentID).RemoveValueAsync().ContinueWith(task2 => { if (task2.IsFaulted) { fail(task2.Exception.ToString()); } else { FirebaseDatabase.DefaultInstance.GetReference(DBTable.Responsible.ToString()).Child(appointment.responsableID).Child(Parameters.appointments.ToString()).Child(appointment.appointmentID).RemoveValueAsync().ContinueWith(task3 => { if (task3.IsFaulted) { fail(task3.Exception.ToString()); } else { success(); } }); } }); } }); }
public static void UpdateService(ServicesProvidedModel service, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { bool mError = false; UpdateServiceCompany(service, delegate() { GetAllResponsablesFromCompany(companyData.userID, delegate(List <ResponsibleModel> responsables) { responsables.ForEach(x => { UpdateServiceResponsible(service, x.userID, delegate() { }, delegate(string error) { mError = true; }); }); if (mError) { fail(""); } else { success(); } }); }, delegate(string error) { fail(error); }); }
public void CreateNewCompanyWithEmailAndPassword(string companyName, string email, string password, Delegates.CreateNewUser success, Delegates.GeneralListenerFail fail) { auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled."); fail("Criação cancelada"); return; } if (task.IsFaulted) { fail(GetErrorMessage(task.Exception.InnerExceptions [0] as FirebaseException)); Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception); return; } // Firebase user has been created. user = task.Result; var profile = new Firebase.Auth.UserProfile { DisplayName = companyName }; UpdateUserProfile(profile); success(user.UserId); Debug.LogFormat("Firebase company created successfully: {0} ({1})", user.DisplayName, user.UserId); }); }
static void UpdateServiceCompany(ServicesProvidedModel service, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { FireBaseManager.GetFireBaseInstance().UpdateSeviceCompany(companyData.userID, service, delegate() { success(); }, delegate(string error) { fail(error); }); }
public void CreateNewUserWithEmailAndPassword(string name, string phone, string email, string password, Constants.UserType userType, Delegates.CreateNewUser success, Delegates.GeneralListenerFail fail) { auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled."); fail("Criação cancelada"); return; } if (task.IsFaulted) { fail(GetErrorMessage(task.Exception.InnerExceptions [0] as FirebaseException)); Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception); return; } // Firebase user has been created. user = task.Result; if (userType == Constants.UserType.User) { DataManager.currentUser = FireBaseManager.GetFireBaseInstance().CreateNewUser(auth.CurrentUser.UserId, name, phone); } var profile = new Firebase.Auth.UserProfile { DisplayName = name }; UpdateUserProfile(profile); success(user.UserId); Debug.LogFormat("Firebase user created successfully: {0} ({1})", user.DisplayName, user.UserId); }); }
public static void GetResponsibleAppointments(Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { FireBaseManager.GetFireBaseInstance().GetResponsibleAppointments(currentResponsible.userID, delegate(List <AppointmentModel> appointments) { responsibleAppointmentList.Clear(); appointments.ForEach(x => responsibleAppointmentList.Add(x)); success(); }, delegate(string error) { fail(error); }); }
public void ForgotPassword(string email, Delegates.GeneralListenerSuccess successListener, Delegates.GeneralListenerFail failListener) { if (user != null) { auth.SendPasswordResetEmailAsync(email).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SendPasswordResetEmailAsync was canceled."); failListener("SendPasswordResetEmailAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SendPasswordResetEmailAsync encountered an error: " + task.Exception); failListener(GetErrorMessage(task.Exception.InnerExceptions [0] as FirebaseException)); return; } Debug.Log("Password reset email sent successfully."); successListener(); }); } }
public static void JustRemoveAppointmentWithouMessage(AppointmentModel appointment, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { FireBaseManager.GetFireBaseInstance().DeleteAppointment(appointment, success, fail); }
public static void DeleteClient(UserModel client, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { FireBaseManager.GetFireBaseInstance().DeleteClientToCompany(currentUser.userID, client, delegate() { (currentUser as CompanyModel).clients.Remove(client.userID); success(); }, fail); }
public static void GetCurrentUserMessages(Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { FireBaseManager.GetFireBaseInstance().GetUserMessages(currentUser.userID, delegate(List <MessageModel> messages) { userMessages.Clear(); userMessages = messages; success(); }, delegate(string error) { fail(error); }); }
public void CreateNewMessageScheduleByCompany(MessageModel message, string responsibleID, string userID, Delegates.GeneralListenerSuccess success, Delegates.GeneralListenerFail fail) { string messageID = reference.Child(DBTable.User.ToString()).Push().Key; message.id = messageID; string json = JsonUtility.ToJson(message); reference.Child(DBTable.Company.ToString()).Child(userID).Child(Parameters.messages + "/" + messageID).SetRawJsonValueAsync(json).ContinueWith(task => { if (task.IsFaulted) { fail(task.Exception.ToString()); } else if (task.IsCompleted) { reference.Child(DBTable.Responsible.ToString()).Child(responsibleID).Child(Parameters.messages + "/" + messageID).SetRawJsonValueAsync(json).ContinueWith(task2 => { if (task2.IsFaulted) { fail(task2.Exception.ToString()); } else if (task2.IsCompleted) { success(); } }); } }); }