public async void UpdateMeal(Meal mealRequest) { try { var retrievedMeal = GetMeal(mealRequest); if (retrievedMeal != null) { QuerySnapshot MealQuerySnapshot = await GetSnapshot(mealRequest); DocumentReference Docref = MealQuerySnapshot.Documents.First().Reference; await Docref.SetAsync(retrievedMeal, SetOptions.Overwrite); } else { AddMeal(mealRequest); } } catch (Exception e) { throw new Exception($"Update meal failed: Exception {e}"); } }
private static async Task RetrieveAllDocuments(string project) { FirestoreDb db = FirestoreDb.Create(project); // [START fs_get_all] CollectionReference usersRef = db.Collection("users"); QuerySnapshot snapshot = await usersRef.SnapshotAsync(); foreach (DocumentSnapshot document in snapshot.Documents) { Console.WriteLine("User: {0}", document.Id); Dictionary <string, object> documentDictionary = document.ToDictionary(); Console.WriteLine("First: {0}", documentDictionary["First"]); if (documentDictionary.ContainsKey("Middle")) { Console.WriteLine("Middle: {0}", documentDictionary["Middle"]); } Console.WriteLine("Last: {0}", documentDictionary["Last"]); Console.WriteLine("Born: {0}", documentDictionary["Born"]); Console.WriteLine(); } // [START fs_get_all] }
//[Authorize(Roles ="SAdmin")] public async Task <HttpResponseMessage> VerifyPasscode(MT_Patient_Forms_URLs PMD) { Db = con.SurgeryCenterDb(PMD.Slug); PFURLResponse Response = new PFURLResponse(); try { MT_Patient_Forms_URLs user = new MT_Patient_Forms_URLs(); Query colref = Db.Collection("MT_Patient_Forms_URLs").WhereEqualTo("PFU_Is_Active", true).WhereEqualTo("PFU_Passcode", PMD.PFU_Passcode).WhereEqualTo("PFU_Unique_ID", PMD.PFU_Unique_ID); QuerySnapshot ObjDocSnap = await colref.GetSnapshotAsync(); if (ObjDocSnap != null) { user = ObjDocSnap.Documents[0].ConvertTo <MT_Patient_Forms_URLs>(); if (user.PFU_Unique_ID != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; } else { Response.Status = con.StatusDNE; Response.Message = con.MessageDNE; } } else { Response.Data = null; Response.Status = con.StatusDNE; Response.Message = con.MessageDNE; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = "Passcode Expired"; } return(ConvertToJSON(Response)); }
TechnicianCheckup(string serviceName, DateTime begin, DateTime end) { FirestoreDb db = connection.GetFirestoreDb(); List <TechniciаnCheckupViewModel> result = new List <TechniciаnCheckupViewModel>(); QuerySnapshot snapshot = await db .Collection("service-repairs") .GetSnapshotAsync(); Dictionary <string, List <DocumentSnapshot> > dictionary = snapshot .Documents .GroupBy(x => x.ConvertTo <Repair>().TechnicianName) .ToDictionary(x => x.Key, x => x.ToList()); dictionary.ToList() .ForEach(x => { TechniciаnCheckupViewModel model = new TechniciаnCheckupViewModel(); model.Name = x.Key; double labor = 0; x.Value .ForEach(x => { Repair repair = x.ConvertTo <Repair>(); labor += repair.TechnicianLabor; model.Brand = repair.ApplianceBrand; model.Model = repair.ApplianceModel; }); model.Labor = labor; result.Add(model); }); return(result); }
GetAllParts(string serviceName) { FirestoreDb db = connection.GetFirestoreDb(); List <WarehousePartViewModel> parts = new List <WarehousePartViewModel>(); Query query = db.Collection("warehouse-parts") .WhereGreaterThanOrEqualTo("Availability", 1); QuerySnapshot snapshot = await query.GetSnapshotAsync(); Parallel.ForEach(snapshot.Documents, ds => { lock (typeof(WarehousePart)) { WarehousePartViewModel part = ConvertDsToViewModel(ds); parts.Add(part); } }); return(parts); }
public async Task <List <Team> > GetTeamsOfGroup(int Group) // get list og teams in group { Query Teamquery = db.Collection("Team").WhereEqualTo("Match_group", Group); QuerySnapshot Teamssnap = await Teamquery.GetSnapshotAsync(); List <Team> Group_list = new List <Team>(); foreach (DocumentSnapshot document in Teamssnap.Documents) { Team temp = document.ConvertTo <Team>(); temp.Doc_id = document.Id; Group_list.Add(temp); } if (Group_list.Count == 0) { return(null); // in case of empty group } else { return(Group_list); // return list } }
/// <summary> /// Async method that fetches all members from the database. /// </summary> /// <return> /// A list of Member object ///</returns> public async Task <List <Member> > FetchAllMembers() { Query allMembersQuery = _db.Collection("members"); QuerySnapshot allMemberQuerySnapshot = await allMembersQuery.GetSnapshotAsync(); List <Member> members = new List <Member>(); foreach (DocumentSnapshot documentSnapshot in allMemberQuerySnapshot.Documents) { Dictionary <string, object> snapshotMember = documentSnapshot.ToDictionary(); Member member = new Member { FirstName = snapshotMember["FirstName"].ToString(), LastName = snapshotMember["LastName"].ToString(), PersonalId = snapshotMember["PersonalId"].ToString(), MemberId = Convert.ToInt32(snapshotMember["MemberId"].ToString()) }; members.Add(member); } return(members); }
public async Task <ActionResult <IEnumerable <Recipe> > > GetRecipes() { string path = @"RWPfirebase.json"; Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path); // Create a connection to the Firestore Database FirestoreDb db = FirestoreDb.Create("recipe-web-app-64a48"); // Query the database to get all the recipes Query allRecipesQuery = db.Collection("RecipeWebApp"); List <Recipe> Recipes = new List <Recipe>(); QuerySnapshot allRecipesQuerySnapshot = await allRecipesQuery.GetSnapshotAsync(); // For each recipe in the database, convert it into a recipe object and store it in a list foreach (DocumentSnapshot documentSnapshot in allRecipesQuerySnapshot) { List <string> recipeDocument = new List <string>(); Recipe docuRecipe = documentSnapshot.ConvertTo <Recipe>(); docuRecipe.id = documentSnapshot.Id; Recipes.Add(docuRecipe); } return(Recipes); }
public async Task <List <Dictionary <string, object> > > ListAllClients() { List <Dictionary <string, object> > list = new List <Dictionary <string, object> >(); try { CollectionReference collRef = db.Collection("clients"); QuerySnapshot snapshot = await collRef.GetSnapshotAsync(); foreach (DocumentSnapshot document in snapshot.Documents) { Dictionary <string, object> documentDictionary = document.ToDictionary(); list.Add(documentDictionary); } } catch (Exception ex) { throw ex; } return(list); }
//[Authorize(Roles ="SAdmin")] public async Task <HttpResponseMessage> ListDD(MT_Pack Pck) { Db = con.SurgeryCenterDb(Pck.Slug); PackResponse Response = new PackResponse(); try { List <MT_Pack> AnesList = new List <MT_Pack>(); Query docRef = Db.Collection("MT_Pack").WhereEqualTo("Pack_Is_Deleted", false).WhereEqualTo("Pack_Is_Active", true); QuerySnapshot ObjQuerySnap = await docRef.GetSnapshotAsync(); if (ObjQuerySnap != null) { foreach (DocumentSnapshot Docsnapshot in ObjQuerySnap.Documents) { if (Pck.Pack_Surgery_Physician_Id != "28bLAlDi21ab1a937541a6") { if (Docsnapshot.ConvertTo <MT_Pack>().Pack_Surgery_Physician_Id == "28bLAlDi21ab1a937541a6" || Docsnapshot.ConvertTo <MT_Pack>().Pack_Surgery_Physician_Id == Pck.Pack_Surgery_Physician_Id || Docsnapshot.ConvertTo <MT_Pack>().Pack_Surgery_Physician_Id == Pck.Pack_SC_Id) { AnesList.Add(Docsnapshot.ConvertTo <MT_Pack>()); } } else { AnesList.Add(Docsnapshot.ConvertTo <MT_Pack>()); } } Response.DataList = AnesList.OrderBy(o => o.Pack_Name).ToList(); } Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public async Task <LastIdentificationNumber> getLastIdetificationNumber(string domainEntityName) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); long databaseId; string databaseEntityName; LastIdentificationNumber lastIdetificationNumber = new LastIdentificationNumber(); Query identificationNumberQuery = db.Collection("LastEntityIdentificationNumber").WhereEqualTo("EntityName", domainEntityName); QuerySnapshot identificationNumberQuerySnapshot = await identificationNumberQuery.GetSnapshotAsync(); foreach (DocumentSnapshot documentSnapshot in identificationNumberQuerySnapshot.Documents) { Console.WriteLine("Document data for {0} document:", documentSnapshot.Id); Dictionary <string, object> identificationNumberDocument = documentSnapshot.ToDictionary(); identificationNumberDocument.TryGetTypedValue("Id", out databaseId); identificationNumberDocument.TryGetTypedValue("EntityName", out databaseEntityName); lastIdetificationNumber.entityName = databaseEntityName; lastIdetificationNumber.id = databaseId; } return(lastIdetificationNumber); }
/// <summary> /// Returns a list of Subscribers that are looking for matching posts /// </summary> /// <returns></returns> public async Task <List <Subscriber> > GetSubscribers() { await FirestoreSetup(); List <Subscriber> subscribers = new List <Subscriber>(); try { CollectionReference matchCollection = DBHandle.Collection(SUBSCRIBERS); QuerySnapshot matchesSnapshot = await matchCollection.GetSnapshotAsync(); foreach (DocumentSnapshot docss in matchesSnapshot.Documents) { Subscriber match = docss.ConvertTo <Subscriber>(); match.DocumentId = docss.Id; subscribers.Add(match); } } catch (Exception e) { Logger.Log($"An unknown error ocurred while fetching the subscribers:\n{e.Message} "); } return(subscribers); }
public async Task <ActionResult> Index() { string ClinicMobileNumber = GlobalSessionVariables.ClinicMobileNumber; string Path = AppDomain.CurrentDomain.BaseDirectory + @"greenpaperdev-firebase-adminsdk-8k2y5-fb46e63414.json"; Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", Path); FirestoreDb db = FirestoreDb.Create("greenpaperdev"); List <User> UserList = new List <User>(); //Query Qref = db.Collection("Students").WhereEqualTo("StudentName","Suvidhi"); Query Qref = db.Collection("clinics").WhereEqualTo("clinicmobilenumber", ClinicMobileNumber); QuerySnapshot snapClinics = await Qref.GetSnapshotAsync(); foreach (DocumentSnapshot docsnapClinics in snapClinics) { Clinic clinic = docsnapClinics.ConvertTo <Clinic>(); QuerySnapshot snapUsers = await docsnapClinics.Reference.Collection("user").OrderByDescending("name").GetSnapshotAsync(); foreach (DocumentSnapshot docsnapUsers in snapUsers) { User user = docsnapUsers.ConvertTo <User>(); user.clinicmobilenumber = clinic.clinicmobilenumber; user.Id = docsnapUsers.Id; //QuerySnapshot snapPatient = await docsnapClinics.Reference.Collection("patientList").WhereEqualTo("patient_id", appointment.patient_id).Limit(1).GetSnapshotAsync(); //DocumentSnapshot docsnapPatient = snapPatient.Documents[0]; //Patient patient = docsnapPatient.ConvertTo<Patient>(); if (docsnapUsers.Exists) { UserList.Add(user); } } } return(View(UserList)); //return View(); }
public async Task <List <Person> > GetData() { var p = new List <Person>(); Query docRef = db.Collection("data"); QuerySnapshot snapshot = await docRef.GetSnapshotAsync(); foreach (DocumentSnapshot ds in snapshot.Documents) { var i = ds.GetValue <int>("ID"); var j = ds.GetValue <string>("Name"); p.Add(new Person() { PersonId = i, Name = j }); } return(p); }
/// <summary> /// Move all sections at the same order or higher one up to fit the new order. /// </summary> /// <param name="order"></param> /// <returns></returns> private async Task UpdateOrders(int order) { Query heigherOrder = db.Collection("sections").WhereGreaterThanOrEqualTo("Order", order); QuerySnapshot querySnapshot = await heigherOrder.GetSnapshotAsync(); Dictionary <string, int> newOrders = new Dictionary <string, int>(); foreach (DocumentSnapshot doc in querySnapshot.Documents) { newOrders.Add(doc.Id, doc.GetValue <int>("Order") + 1); } WriteBatch batch = db.StartBatch(); foreach (KeyValuePair <string, int> entry in newOrders) { DocumentReference updateRef = db.Collection("sections").Document(entry.Key); batch.Update(updateRef, "Order", entry.Value); } await batch.CommitAsync(); }
public async Task <List <Dictionary <string, object> > > ListAllProductRegistations() { List <Dictionary <string, object> > productRegistrations = new List <Dictionary <string, object> >(); try { CollectionReference collRef = db.Collection("products_registrations"); QuerySnapshot snapshot = await collRef.GetSnapshotAsync(); foreach (DocumentSnapshot document in snapshot.Documents) { Dictionary <string, object> documentDictionary = document.ToDictionary(); productRegistrations.Add(documentDictionary); } } catch (Exception ex) { throw ex; } return(productRegistrations); }
public async Task UploadLogToExistingRepair(int id, RepairLog log) { FirestoreDb db = connection.GetFirestoreDb(); CollectionReference colRef = db .Collection("activity-log"); QuerySnapshot snapshot = colRef .WhereEqualTo("RepairId", id) .Limit(1) .GetSnapshotAsync() .Result; CollectionReference subColRef = snapshot .Documents .FirstOrDefault() .Reference .Collection("logs"); await db.RunTransactionAsync(async t => { await subColRef.AddAsync(log); }); }
public async Task <IDataResult <List <User> > > GetAll() { List <User> userList = new List <User>(); FirestoreDb database = FirestoreDb.Create(FirebaseConstants.DATABASE); Query query = database.Collection(FirebaseConstants.USER_COLLECTION); QuerySnapshot userSnapshots = await query.GetSnapshotAsync(); if (userSnapshots != null) { foreach (DocumentSnapshot document in userSnapshots.Documents) { Dictionary <string, object> data = document.ToDictionary(); string documentId = document.Id; string firstName = data["FirstName"].ToString(); string lastName = data["LastName"].ToString(); string email = data["Email"].ToString(); string userID = data["UserID"].ToString(); string _userName = data["UserName"].ToString(); string about = data["About"].ToString(); string profileImage = data["ProfileImage"].ToString(); Uri uri = null; if (profileImage != null) { uri = new Uri(profileImage); } userList.Add(new User(firstName, lastName, email, "", _userName, userID, uri, about, documentId)); } return(new SuccessDataResult <List <User> >(userList)); } else { return(new ErrorDataResult <List <User> >()); } }
public async Task <ActionResult> ViewStudent() { string institute = Session["user"].ToString(); if (Session["user"] == null) { return(RedirectToAction("../Login/Index")); } else { List <Student> list = new List <Student>(); try { list.Clear(); Query faculty = firestoreDb.Collection("Institute").Document(institute).Collection("Student"); QuerySnapshot getfaculty = await faculty.GetSnapshotAsync(); foreach (DocumentSnapshot documentSnapshot in getfaculty.Documents) { if (documentSnapshot.Exists) { Dictionary <string, object> city = documentSnapshot.ToDictionary(); string json = JsonConvert.SerializeObject(city); Student newuser = JsonConvert.DeserializeObject <Student>(json); newuser.Id = documentSnapshot.Id; list.Add(newuser); } } } catch (Exception e) { Console.WriteLine("{0}", e.Source); throw new Exception(e.Source); } ViewBag.Faculty = list; return(View()); } }
public async Task <ActionResult> EditStudent(string Id) { string institute = Session["user"].ToString(); if (Session["user"] == null) { return(RedirectToAction("../Login/Index")); } else { Student data = new Student(); try { Query student = firestoreDb.Collection("Institute").Document(institute).Collection("Student"); QuerySnapshot getstudent = await student.GetSnapshotAsync(); foreach (DocumentSnapshot documentSnapshot in getstudent.Documents) { if (documentSnapshot.Exists && documentSnapshot.Id == Id.ToString()) { Dictionary <string, object> city = documentSnapshot.ToDictionary(); string json = JsonConvert.SerializeObject(city); Student newuser = JsonConvert.DeserializeObject <Student>(json); newuser.Id = documentSnapshot.Id; data = newuser; break; } } } catch (Exception e) { Console.WriteLine("{0}", e.Source); throw new Exception(e.Source); } ViewBag.Student = data; return(View()); } }
/// <summary> /// Function to be registered as an event when the bird dies, crashing into obstacles or ground. /// The event is registered in Bird script. /// </summary> public void BirdDied() { gameOver = true; //Retrieve the collection named 'High Score Collection' from our database in the Firebase Cloud CollectionReference HighScoreCollection = db.Collection("High Score Collection"); HighScore = 0; //Retrieve the results from the cloud HighScoreCollection.GetSnapshotAsync().ContinueWithOnMainThread(task => { QuerySnapshot snapshot = task.Result; //Convert the queury's result from the server to List for convenience List <DocumentSnapshot> ListOfDocs = snapshot.ToList(); //Since there is only one Document in the the collection, 'High Score Document' Dictionary <string, object> documentDictionary = ListOfDocs[0].ToDictionary(); //Check for the field containing our high score if (documentDictionary.ContainsKey("High Score")) { if (int.TryParse(documentDictionary["High Score"].ToString(), out HighScore)) { //if the current score of the user is higher than the already registered high score, then update it on the cloud if (score > HighScore) { SetHighScore(score); } else { SetPageState(UserInterfaceState.GameOver); } } } }); }
public async Task <IDataResult <User> > GetById(string Id) { FirestoreDb database = FirestoreDb.Create(FirebaseConstants.DATABASE); Query userQuery = database.Collection(FirebaseConstants.USER_COLLECTION).WhereEqualTo("UserID", Id); QuerySnapshot userSnapshots = await userQuery.GetSnapshotAsync(); User user = null; foreach (DocumentSnapshot document in userSnapshots.Documents) { Dictionary <string, object> data = document.ToDictionary(); string documentId = document.Id; string firstName = data["FirstName"].ToString(); string lastName = data["LastName"].ToString(); string email = data["Email"].ToString(); string userID = data["UserID"].ToString(); string userName = data["UserName"].ToString(); string profileImage = data["ProfileImage"].ToString(); string token = data["Token"].ToString(); string about = data["About"].ToString(); Uri uriImage = null; if (profileImage != null) { uriImage = new Uri(profileImage); } user = new User(firstName, lastName, email, "", userName, userID, uriImage, about, documentId); } if (user != null) { return(new SuccessDataResult <User>(user)); } return(new ErrorDataResult <User>()); }
public async Task <HttpResponseMessage> VCCancelledListForPatient(MT_Virtual_Consultant_Booking VCMD) { Db = con.SurgeryCenterDb(VCMD.Slug); VCBookingResponse Response = new VCBookingResponse(); try { List <MT_Virtual_Consultant_Booking> patilist = new List <MT_Virtual_Consultant_Booking>(); Query ObjQuery = Db.Collection("MT_Virtual_Consultant_Booking").WhereEqualTo("VCB_Is_Deleted", false).WhereEqualTo("VCB_Patient_ID", VCMD.VCB_Patient_ID); QuerySnapshot ObjQuerySnap = await ObjQuery.GetSnapshotAsync(); if (ObjQuerySnap != null) { foreach (DocumentSnapshot Docsnapshot in ObjQuerySnap.Documents) { if (Docsnapshot.ConvertTo <MT_Virtual_Consultant_Booking>().VCB_Status == "Cancelled") { patilist.Add(Docsnapshot.ConvertTo <MT_Virtual_Consultant_Booking>()); } } Response.DataList = patilist.OrderBy(o => o.VCB_Booking_Date).ToList(); Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; } else { Response.Status = con.StatusDNE; Response.Message = con.MessageDNE; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
//[Authorize(Roles ="SAdmin")] public async Task <HttpResponseMessage> GetAlertListFilterWithSCPO(MT_Alert AMD) { Db = con.SurgeryCenterDb(AMD.Slug); AlertResponse Response = new AlertResponse(); try { List <MT_Alert> AnesList = new List <MT_Alert>(); MT_Alert Alert = new MT_Alert(); Query docRef = Db.Collection("MT_Alert").WhereEqualTo("Alert_Is_Deleted", false).WhereEqualTo("Alert_Is_Active", true).OrderBy("Alert_Name"); QuerySnapshot ObjQuerySnap = await docRef.GetSnapshotAsync(); if (ObjQuerySnap != null) { foreach (DocumentSnapshot Docsnapshot in ObjQuerySnap.Documents) { Alert = Docsnapshot.ConvertTo <MT_Alert>(); if (AMD.Alert_Surgery_Physician_Id == Alert.Alert_Surgery_Physician_Id) { AnesList.Add(Alert); } else if (Alert.Alert_Surgery_Physician_Id == "0") { AnesList.Add(Alert); } } Response.DataList = AnesList.OrderBy(o => o.Alert_Name).ToList(); } Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public async Task HandleAsync(ListenNewOrder eve, QuerySnapshot e) { if (e == null || e.Count == 0) { return; } foreach (var snapshot in e) { if (!snapshot.Exists) { continue; } var dic = snapshot.ToDictionary(); var order = dic.ConvertJson <Order>(); order.GuidId = new Guid(snapshot.Id); var action = "add new"; var existing = await _orderService.GetAsync(order.GuidId); if (existing == null) { await _orderService.CreateAsync(order); } else { action = "update status"; await _orderService.UpdateStatusAsync(order.GuidId, order.Status); } var updateData = new Dictionary <string, object> { { eve.ServeName, true } }; await _firestoreService.UpdateDocumentAsync(eve.CollectionName, snapshot.Id, updateData); _logger.LogInformation($"[{DateTime.Now}] Process - documentId: {snapshot.Id}, action: {action} - {JsonConvert.SerializeObject(dic)}"); } }
public static async void GetAllDocuments(string collectionName) { string path = AppDomain.CurrentDomain.BaseDirectory + @"cloudfire.json"; Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path); FirestoreDb db = FirestoreDb.Create("imdb-clone-project"); Query movie = db.Collection(collectionName); QuerySnapshot snap = await movie.GetSnapshotAsync(); foreach (DocumentSnapshot documentSnapshot in snap.Documents) { if (documentSnapshot.Exists) { Dictionary <string, object> documentDictionary = documentSnapshot.ToDictionary(); foreach (var item in documentDictionary) { Console.WriteLine(item.Key, item.Value); } } } }
public async Task <List <UserDbModel> > GetAllAsync() { Query Query = _entities.FirestoreDb?.Collection(_collection); QuerySnapshot QuerySnapshot = await Query?.GetSnapshotAsync(); var list = new List <UserDbModel>(); foreach (DocumentSnapshot documentSnapshot in QuerySnapshot.Documents) { if (documentSnapshot.Exists) { Dictionary <string, object> dictionary = documentSnapshot.ToDictionary(); list.Add(new UserDbModel() { Id = documentSnapshot.Id, Email = dictionary["email"].ToString() }); } } return(list.OrderBy(x => x.Email).ToList()); }
public async Task <List <object> > GetAllTasks() { CollectionReference colRef = db.Collection("users"); QuerySnapshot querySnapshot = await colRef.GetSnapshotAsync(); List <object> list = new List <object>(); foreach (var temp in querySnapshot) { IList <CollectionReference> colList = await temp.Reference.ListCollectionsAsync().ToList(); foreach (var temp2 in colList) { var docSnapshot = await temp2.Document("tasks").Collection("tasks").GetSnapshotAsync(); foreach (var temp3 in docSnapshot) { list.Add(new { id = temp3.Id, title = temp3.ToDictionary()["title"], user = temp.ToDictionary()["Name"], description = temp3.ToDictionary()["description"], downloadUrl = temp3.ToDictionary()["downloadUrl"] }); } } } return(list.Select(x => x).Distinct().ToList()); }
public async Task <StudentDetailModel> GetStudentByIdAsync(int studentId) { FirestoreDb db = FirestoreDb.Create(Project); Query docRef = db.Collection(Collection).WhereEqualTo("Id", studentId).Limit(1); QuerySnapshot snapshot = await docRef.GetSnapshotAsync(); if (snapshot.Count > 0) { Student student = snapshot.ElementAt(0).ConvertTo <Student>(); return(new StudentDetailModel() { About = student.About, EnrollmentDate = student.EnrollmentDate.ToDateTime(), FirstName = student.FirstName, Id = student.Id, LastName = student.LastName }); } else { return(null); } }
public async Task <UserDbModel> GetByEmailAsync(string userEmail) { if (string.IsNullOrWhiteSpace(userEmail)) { return(null); } CollectionReference colRef = _entities.FirestoreDb?.Collection(_collection); Query query = colRef?.WhereEqualTo("email", userEmail); QuerySnapshot querySnapshot = await query.GetSnapshotAsync(); foreach (DocumentSnapshot documentSnapshot in querySnapshot.Documents) { if (documentSnapshot.Exists) { var dbModel = documentSnapshot.ConvertTo <UserDbModel>(); dbModel.Id = documentSnapshot.Id; return(dbModel); } } return(null); }