VivekScorp
Member
- Joined
- May 12, 2022
- Messages
- 11
- Programming Experience
- 3-5
There is a Dependency class in android that has these two functions
1.
In my PCL ViewModel class
so my PCL class calls ReadVisitorDetails() whenever the MessagingCenter text is true
The first time when it runs the output is fine onevent - 1 return - 1
after the first time return is always 0 onevent - 1 return - 0
visitorDetails is a class variable initialized inside the constructor
1.
C#:
public void OnEvent(Java.Lang.Object obj, FirebaseFirestoreException error)
{
try
{
var docs = (QuerySnapshot)obj;
visitorDetails.Clear();
foreach (var doc in docs.Documents)
{
Console.WriteLine(doc.Get("VisitorName").ToString());
var visitordetails = new VisitorDetails
{
Name = doc.Get("VisitorName").ToString(),
ContactNumber = doc.Get("VisitorContact").ToString(),
VehicleNumber = doc.Get("VisitorVehicleNo").ToString(),
IsApproved = doc.Get("VisitorIsApproved").ToString(),
IsActive = doc.Get("VisitorIsActive").ToString(),
Purpose = doc.Get("PurposeOfVisit").ToString(),
Email = doc.Get("VisitorEmail").ToString(),
FromDate = toDatetime(doc.GetDate("FromDate") as Date),
ToDate = toDatetime(doc.GetDate("ToDate") as Date),
docID = doc.Id
};
visitorDetails.Add(visitordetails);
}
Console.WriteLine("onevent - " + visitorDetails.Count.ToString());
HasReadCompleted = true;
MessagingCenter.Send<object, string>(this, "HasChanges", "true");
}
catch (FirebaseFirestoreException error1)
{
Console.WriteLine(readMode + error1.Message);
HasReadCompleted = false;
}
}
2. public async Task<ObservableCollection<VisitorDetails>> ReadVisitorDetails()
{
try
{
Console.WriteLine("return - " + visitorDetails.Count.ToString());
return visitorDetails;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return null;
}
}
C#:
MessagingCenter.Subscribe<object, string>
(this, "HasChanges", (sender, status) =>
{
if(status=="true" && userdetails != null)
{
details = await DatabaseHelper.ReadVisitorDetails();
}
});
The first time when it runs the output is fine onevent - 1 return - 1
after the first time return is always 0 onevent - 1 return - 0
visitorDetails is a class variable initialized inside the constructor