I have found many answers in Java but not specifically in C#.
Currently, I have the following data model in my Firestore cloud database:
I then layered out my models in C#:
public class User
{
public string Uid { get; set; }
public string Username { get; set; }
public List<TaskDetails> Tasks { get; set; }
}
public class TaskDetails
{
public DateTime DueDate { get; set; }
public bool IsCompleted { get; set; }
public string Details { get; set; }
}
Here is how I get the data so far:
public class FirestoreUsers : Java.Lang.Object, IFirestoreUsers, IOnCompleteListener
{
List<User> Users = new List<User>();
public async Task<IList<User>> GetUsers()
{
FirebaseFirestore.Instance.Collection("Users").Get().AddOnCompleteListener(this);
await System.Threading.Tasks.Task.Delay(1000);
return Users;
}
public void OnComplete(Android.Gms.Tasks.Task task)
{
var snapshot = (QuerySnapshot)task.Result;
if (snapshot.IsEmpty) return;
var document = snapshot.Documents;
Users.Clear();
foreach (DocumentSnapshot user in document)
{
User userModel = new User
{
Uid = user.Id, // 'Document Id' is the 'User' 'Uid'
Username = user.Get("Username"),
};
Users.Add(userModel);
}
}
}
At the moment, I can only get the Uid and Username. Now, I need to get the Tasks.. struggled for hours and can only find answer in Java. I am not sure where to get started.
What I tried
I looked into this answer:
https://stackoverflow.com/a/70122197/12485722
But it seems like he's using a different library than me. I use Xamarin.Firebase.Firestore.
