public async void AddFoodRecord(string userId, string item, string money, string bookDate) { DocumentReference docRef = _db.Collection(userId).Document(bookDate); DocumentSnapshot docShot = await _db.Collection(userId).Document(bookDate).GetSnapshotAsync(); Dictionary <string, object> record = new Dictionary <string, object> { { "Id", Guid.NewGuid().ToString("N") }, { "Name", item }, { "Money", money.Contains(".") ? float.Parse(money) : Convert.ToInt32(money) } }; if (docShot.Exists) { if (docShot.GetValue <List <Dictionary <string, object> > > ("list").Count > 0) { await docRef.UpdateAsync("list", FieldValue.ArrayUnion(record)); } else { await docRef.SetAsync(new { list = new List <Dictionary <string, object> > () { record } }); } } else { await docRef.SetAsync(new { list = new List <Dictionary <string, object> > () { record } }); } }
public async Task Channelmod( [Summary("The user to cmod")][Remainder] SocketGuildUser user) { CollectionReference channelCollection = GranularPermissionsStorage.Db.Document(Convert.ToString(this.Context.Guild.Id)).Collection("channels"); DocumentReference channelDoc = channelCollection.Document(Convert.ToString(this.Context.Channel.Id)); Dictionary <string, object> update = new Dictionary <string, object>(); List <ulong> mods = await GranularPermissionsStorage.GetChannelmodsFor(this.Context.Guild.Id, this.Context.Channel); if (!mods.Contains(user.Id)) { mods.Add(user.Id); update["mods"] = mods; await channelDoc.SetAsync(update, SetOptions.MergeAll); if (this.Context.Channel is SocketGuildChannel sgc) { await sgc.AddPermissionOverwriteAsync(user, new OverwritePermissions(readMessages : PermValue.Allow, sendMessages : PermValue.Allow, manageMessages : PermValue.Allow)); } await this.Context.Message.AddReactionAsync(new Emoji("👌")); } else { mods.RemoveAll(x => x == user.Id); update["mods"] = mods; await channelDoc.SetAsync(update, SetOptions.MergeAll); await this.Context.Channel.SendMessageAsync("Removed a channelmod. (Their Discord permissions were not changed.)"); } }
public IEnumerator TestRemoveViaSetMergeArrayRemove() { DocumentReference doc = TestDocument(); var data = new Dictionary<string, object> { { "array", FieldValue.ArrayUnion(1L, 2L, 3L) } }; yield return AwaitSuccess(doc.SetAsync(data)); data = new Dictionary<string, object> { { "array", FieldValue.ArrayRemove(1L, 3L) } }; AwaitSuccess(doc.SetAsync(data, SetOptions.MergeAll)); yield return AssertExpectedDocument( doc, new Dictionary<string, object> { { "array", new List<object> { 2L } } }); }
public static async Task <bool> SetDefaultRole(ulong guildID, SocketRole role) { try { DocumentReference guildDocument = Db.Document(Convert.ToString(guildID)).Collection("lite").Document("data"); DocumentSnapshot guildSnapshot = await guildDocument.GetSnapshotAsync(); guildSnapshot.TryGetValue("defaultRoles", out List <ulong> defaultRoles); if (defaultRoles == null) { defaultRoles = new List <ulong>(); } if (!defaultRoles.Contains(role.Id)) { defaultRoles.Add(role.Id); } else { defaultRoles.Remove(role.Id); } Dictionary <string, List <ulong> > update = new Dictionary <string, List <ulong> > { ["defaultRoles"] = defaultRoles }; WriteResult wrire = await guildDocument.SetAsync(update, SetOptions.MergeAll); return(true); } catch { return(false); } }
public static async Task <bool> TryConsumeAuthCode(ulong guildID, string code) { CollectionReference authDocument = Db.Document("_authorizeKeys").Collection(code); QuerySnapshot authDocumentSnapshot = await authDocument.GetSnapshotAsync(); if (authDocumentSnapshot.Documents.Count > 0) { DocumentSnapshot authDoc = authDocumentSnapshot.Documents[0]; DocumentReference authRef = authDoc.Reference; AuthorizationStatus authStatus = authDoc.ConvertTo <AuthorizationStatus>(); if (authStatus.used) { return(false); } else { authStatus.used = true; authStatus.sid = guildID; await authRef.SetAsync(authStatus); await SetAuthFor(guildID, true); return(true); } } return(false); }
public static void SendScore(UserScoreData userScoreData, Action <Task> callback) { if (!isAuthenticated || userScoreData == null) { return; } DocumentReference userDocRef = db.Collection(leaderboardId).Document(auth.CurrentUser.UserId); userDocRef.GetSnapshotAsync().ContinueWithOnMainThread(task => { if (!task.IsCompleted) { return; } if (task.Result.Exists) { UserScoreData savedScoreData = task.Result.ConvertTo <UserScoreData>(); if (userScoreData.userScore <= savedScoreData.userScore) { callback?.Invoke(task); return; } } userDocRef.SetAsync(userScoreData).ContinueWithOnMainThread(secondTask => { callback?.Invoke(secondTask); }); }); }
public async Task <HttpResponseMessage> Create(MT_Log_Book LBMD) { Db = con.SurgeryCenterDb(LBMD.Slug); LogResponse Response = new LogResponse(); try { UniqueID = con.GetUniqueKey(); LBMD.Unique_ID = UniqueID; LBMD.Ip_Address = GetClientIp(); LBMD.Operation_Time = con.ConvertTimeZone(LBMD.TimeZone, Convert.ToDateTime(LBMD.Operation_Time)); DocumentReference docRef = Db.Collection("MT_Log_Book").Document(UniqueID); WriteResult Result = await docRef.SetAsync(LBMD); if (Result != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = LBMD; } else { Response.Status = con.StatusNotInsert; Response.Message = con.MessageNotInsert; Response.Data = null; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public async Task <HttpResponseMessage> CreateAsync(MT_Slug SMD) { SlugMResponse Response = new SlugMResponse(); try { UniqueID = con.GetUniqueKey(); SMD.Slug_Unique_ID = UniqueID; DocumentReference docRef = Db.Collection("MT_Slug").Document(UniqueID); WriteResult Result = await docRef.SetAsync(SMD); if (Result != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = SMD; } else { Response.Status = con.StatusNotInsert; Response.Message = con.MessageNotInsert; Response.Data = null; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
async void Add_Document_with_orden() { DocumentReference docRef = database.Collection("Revisiones").Document(txtorden.Text); DocumentSnapshot snapshot = await docRef.GetSnapshotAsync(); if (snapshot.Exists) { MessageBox.Show("Repetido"); } else { DocumentReference DOC = database.Collection("Revisiones").Document(txtorden.Text); Dictionary <String, Object> data1 = new Dictionary <string, object>() { { "Nombre", txtnombre.Text }, { "Numero", txtnumero.Text }, { "Modelo", txtmarca.Text + " " + txtmodelo.Text }, { "Descripcion", txtdescripcion.Text }, { "Accesorios", Accesorios }, { "Tiempo de espera", tiemporespuesta }, { "Fecha y Hora", txthorayfecha.Text } }; await DOC.SetAsync(data1, SetOptions.MergeAll); MessageBox.Show("guardado"); } }
public async Task <ActionResult> CreateCounsellingSession(IFormCollection form) { string userID = form["userID"].ToString(); int sessionID = Convert.ToInt32(form["SessionID"]); int cID = HttpContext.Session.GetInt32("CounsellorID").Value; string counsellorID = HttpContext.Session.GetInt32("CounsellorID").ToString(); string session = counsellorID + "-" + userID; HttpContext.Session.SetString("roomID", session); var projectName = "fir-chat-ukiyo"; var authFilePath = "/Users/joeya/Downloads/NP_ICT/FSD & P2/fir-chat-ukiyo-firebase-adminsdk.json"; //var authFilePath = "/Users/jaxch/Downloads/fir-chat-ukiyo-firebase-adminsdk.json"; //var authFilePath = "/Users/tee/Downloads/fir-chat-ukiyo-firebase-adminsdk.json"; Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", authFilePath); FirestoreDb db = FirestoreDb.Create(projectName); DocumentReference docRef = db.Collection("CounsellingChat").Document(session); Dictionary <string, object> start = new Dictionary <string, object> { { "Date", Timestamp.GetCurrentTimestamp() }, { "Status", "Online" }, { "UserID", userID } }; counsellorDAL.confirmSes(sessionID, cID); await docRef.SetAsync(start); return(RedirectToAction("CounsellorChat")); //return View(); }
// See b/174676322 for why this test is added. public IEnumerator TestMultipleDeletesInOneUpdate() { DocumentReference doc = TestDocument(); var setTask = doc.SetAsync(new Dictionary<string, object> { { "key1", "value1" }, { "key2", "value2" }, { "key3", "value3" }, { "key4", "value4" }, { "key5", "value5" }, }); yield return AwaitSuccess(setTask); var updateTask = doc.UpdateAsync(new Dictionary<string, object> { { "key1", FieldValue.Delete }, { "key3", FieldValue.Delete }, { "key5", FieldValue.Delete }, }); yield return AwaitSuccess(updateTask); var getTask = doc.GetSnapshotAsync(Source.Cache); yield return AwaitSuccess(getTask); DocumentSnapshot snapshot = getTask.Result; var expected = new Dictionary<string, object> { { "key2", "value2" }, { "key4", "value4" }, }; Assert.That(snapshot.ToDictionary(), Is.EquivalentTo(expected)); }
public async Task <HttpResponseMessage> Create(MT_SurgicalProcedureInformationTemplates SPIT) { Db = con.SurgeryCenterDb(SPIT.Slug); SPITemplateResponse Response = new SPITemplateResponse(); try { UniqueID = con.GetUniqueKey(); SPIT.Temp_Unique_ID = UniqueID; SPIT.Temp_Create_Date = con.ConvertTimeZone(SPIT.Temp_TimeZone, Convert.ToDateTime(SPIT.Temp_Create_Date)); SPIT.Temp_Modify_Date = con.ConvertTimeZone(SPIT.Temp_TimeZone, Convert.ToDateTime(SPIT.Temp_Modify_Date)); DocumentReference docRef = Db.Collection("MT_SurgicalProcedureInformationTemplates").Document(UniqueID); WriteResult Result = await docRef.SetAsync(SPIT); if (Result != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = SPIT; } else { Response.Status = con.StatusNotInsert; Response.Message = con.MessageNotInsert; Response.Data = null; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public async Task <IActionResult> PutRecipe(String id, Recipe recipe) { 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"); // Push the recipe data into the existing one to update the recipe DocumentReference docuRef = db.Collection("RecipeWebApp").Document(id); Dictionary <string, object> updatedRecipe = new Dictionary <string, object> { { "Title", recipe.Title }, { "Description", recipe.Description }, { "Image", recipe.Image }, { "Ingredients", recipe.Ingredients }, { "Method", recipe.Method } }; // Sanity check to make sure the recipe exists DocumentSnapshot snap = await docuRef.GetSnapshotAsync(); if (snap.Exists) { await docuRef.SetAsync(updatedRecipe); } return(NoContent()); }
public async Task <bool> Create(Dictionary <string, object> dictionary) { DocumentReference docRef = collection.Document(); await docRef.SetAsync(dictionary); return(true); }
public async Task <string> CreateTag(TagModel myTag) { DocumentReference docRef = _db.Collection("tags").Document(); await docRef.SetAsync(myTag); return(docRef.Id); }
public async Task <HttpResponseMessage> Create(MT_Page_Master PMD) { Db = con.SurgeryCenterDb(PMD.Slug); PageMasterResponse Response = new PageMasterResponse(); try { UniqueID = con.GetUniqueKey(); PMD.PM_Unique_ID = UniqueID; DocumentReference docRef = Db.Collection("MT_Page_Master").Document(UniqueID); WriteResult Result = await docRef.SetAsync(PMD); if (Result != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = PMD; } else { Response.Status = con.StatusNotInsert; Response.Message = con.MessageNotInsert; Response.Data = null; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public bool Update <T>(T record) where T : Base { DocumentReference recordRef = fireStoreDb.Collection(collectionName).Document(record.Id); recordRef.SetAsync(record, SetOptions.MergeAll).GetAwaiter().GetResult(); return(true); }
public static async Task <bool> SetSelfassignable(ulong guildID, string code, SocketRole role) { try { DocumentReference guildDocument = Db.Document(Convert.ToString(guildID)).Collection("lite").Document("data"); DocumentSnapshot guildSnapshot = await guildDocument.GetSnapshotAsync(); guildSnapshot.TryGetValue("selfAssignable", out Dictionary <string, object> selfAssignables); if (selfAssignables == null) { selfAssignables = new Dictionary <string, object>(); } if (selfAssignables.ContainsKey(code) && role == null) { selfAssignables[code] = null; } else { selfAssignables[code] = role.Id; } Dictionary <string, Dictionary <string, object> > update = new Dictionary <string, Dictionary <string, object> > { ["selfAssignable"] = selfAssignables }; WriteResult wrire = await guildDocument.SetAsync(update, SetOptions.MergeAll); return(true); } catch { return(false); } }
public void AddDocumentWithId(string collectionName, string documentId, Dictionary <string, object> data) { DocumentReference document = db.Collection(collectionName).Document(documentId); //insert data in the collection document.SetAsync(data); }
public IEnumerator TestCreateViaArrayUnion() { DocumentReference doc = TestDocument(); var data = new Dictionary<string, object> { { "array", FieldValue.ArrayUnion(1L, 2L) } }; yield return AwaitSuccess(doc.SetAsync(data)); yield return AssertExpectedDocument( doc, new Dictionary<string, object> { { "array", new List<object> { 1L, 2L } } }); }
public Task UpdateMatch(Match match) { if (!isLoading) { isLoading = true; } OnMatchUpdate?.Invoke(); DocumentReference docRef = Match.collectionRef.Document(match.id); Dictionary <string, object> updatedMatch = new Dictionary <string, object> { { "isActive", match.isActive }, { "mark0", match.marks[0] }, { "mark1", match.marks[1] }, { "mark2", match.marks[2] }, { "mark3", match.marks[3] }, { "mark4", match.marks[4] }, { "mark5", match.marks[5] }, { "mark6", match.marks[6] }, { "mark7", match.marks[7] }, { "mark8", match.marks[8] } }; return(docRef.SetAsync(updatedMatch, SetOptions.MergeAll).ContinueWithOnMainThread(task => { isLoading = false; if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); OnMatchUpdateError?.Invoke(); } })); }
private static async Task UpdateNestedFields(string project) { FirestoreDb db = FirestoreDb.Create(project); // [START fs_update_nested_fields] DocumentReference frankDocRef = db.Collection("users").Document("frank"); Dictionary <string, object> initialData = new Dictionary <string, object> { { "Name", "Frank" }, { "Age", 12 } }; Dictionary <string, object> favorites = new Dictionary <string, object> { { "Food", "Pizza" }, { "Color", "Blue" }, { "Subject", "Recess" }, }; initialData.Add("Favorites", favorites); await frankDocRef.SetAsync(initialData); // Update age and favorite color Dictionary <string, object> updates = new Dictionary <string, object> { { "Age", 13 }, { "Favorites.Color", "Red" }, }; // Asynchronously update the document await frankDocRef.UpdateAsync(updates); // [END fs_update_nested_fields] Console.WriteLine("Updated the age and favorite color fields of the Frank document in the users collection."); }
public async Task <HttpResponseMessage> CreateAsync(MT_CPT CMD) { Db = con.SurgeryCenterDb(CMD.Slug); CPTResponse Response = new CPTResponse(); try { UniqueID = con.GetUniqueKey(); CMD.CPT_Unique_ID = UniqueID; CMD.CPT_Procedure_Code_Category = CMD.CPT_Procedure_Code_Category.ToUpper(); CMD.CPT_Create_Date = con.ConvertTimeZone(CMD.CPT_TimeZone, Convert.ToDateTime(CMD.CPT_Create_Date)); CMD.CPT_Modify_Date = con.ConvertTimeZone(CMD.CPT_TimeZone, Convert.ToDateTime(CMD.CPT_Modify_Date)); DocumentReference docRef = Db.Collection("MT_CPT").Document(UniqueID); WriteResult Result = await docRef.SetAsync(CMD); if (Result != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = CMD; } else { Response.Status = con.StatusNotInsert; Response.Message = con.MessageNotInsert; Response.Data = null; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public async Task modificarAsync() { String documentoBuscar = txtDocumentoBuscar.Text; //Query dato1 = db.Collection("Paciente").WhereEqualTo("documento", documentoBuscar); DocumentReference reference = db.Collection("Paciente").Document(documentoBuscar); Dictionary <string, object> data1 = new Dictionary <string, object>() { { "documento", txtDocumento.Text }, { "nombre", txtNombre.Text }, { "correo", txtCorreo.Text }, { "telefono", txtTelefono.Text }, { "genero", txtGenero.Text }, }; DocumentSnapshot snap = await reference.GetSnapshotAsync(); MessageBox.Show("Paciente modificado"); if (snap.Exists) { await reference.SetAsync(data1); } }
public async Task <Product> AddProduct(Product product) { DocumentReference docRef = _db.Collection("products").Document(product.id); await docRef.SetAsync(product); return(product); }
public IEnumerator WaitForPendingWrites_ShouldWork() { DocumentReference doc = TestDocument(); yield return(AwaitSuccess(doc.Firestore.DisableNetworkAsync())); // `pendingWrites1` completes without network because there are no pending writes at // the time it is created. var pendingWrites1 = doc.Firestore.WaitForPendingWritesAsync(); yield return(AwaitSuccess(pendingWrites1)); doc.SetAsync(new Dictionary <string, object> { { "zip", 98101 } }); // `pendingWrites2` will be pending because the SetAsync above is not acknowledged by the // backend yet. var pendingWrites2 = doc.Firestore.WaitForPendingWritesAsync(); AssertTaskIsPending(pendingWrites2); yield return(AwaitSuccess(doc.Firestore.EnableNetworkAsync())); yield return(AwaitSuccess(pendingWrites2)); }
private static async Task AddDocDataTypes(string project) { FirestoreDb db = FirestoreDb.Create(project); // [START fs_add_doc_data_types] DocumentReference docRef = db.Collection("data").Document("one"); Dictionary <string, object> docData = new Dictionary <string, object> { { "stringExample", "Hello World" }, { "booleanExample", false }, { "numberExample", 3.14159265 }, { "nullExample", null }, }; ArrayList arrayExample = new ArrayList(); arrayExample.Add(5); arrayExample.Add(true); arrayExample.Add("Hello"); docData.Add("arrayExample", arrayExample); Dictionary <string, object> objectExample = new Dictionary <string, object> { { "a", 5 }, { "b", true }, }; docData.Add("objectExample", objectExample); await docRef.SetAsync(docData); // [END fs_add_doc_data_types] Console.WriteLine("Set multiple data-type data for the one document in the data collection."); }
private void btnAgregar_Click(object sender, EventArgs e) { String genero; if (radioButMasculino.Checked) { genero = radioButMasculino.Text; } else { genero = radioButFemenino.Text; } //String path = AppDomain.CurrentDomain.BaseDirectory + @"cloudfire.json"; // Environment.SetEnvironmentVariable("GOOGLE_APLICATION_CREDENTIALS", path); //database = FirestoreDb. String documento = txtDocumento.Text; DocumentReference doc = db.Collection("Paciente").Document(documento); Dictionary <string, object> data1 = new Dictionary <string, object>() { { "documento", txtDocumento.Text }, { "nombre", txtNombre.Text }, { "correo", txtCorreo.Text }, { "telefono", txtTelefono.Text }, { "genero", genero }, }; doc.SetAsync(data1); MessageBox.Show("Paciente adicionado"); }
public async Task <HttpResponseMessage> CreateAsync(MT_Incident IMD) { Db = con.SurgeryCenterDb(IMD.Slug); IncidentResponse Response = new IncidentResponse(); try { UniqueID = con.GetUniqueKey(); IMD.Inci_Unique_ID = UniqueID; IMD.Inci_Create_Date = con.ConvertTimeZone(IMD.Inci_TimeZone, Convert.ToDateTime(IMD.Inci_Create_Date)); IMD.Inci_Modify_Date = con.ConvertTimeZone(IMD.Inci_TimeZone, Convert.ToDateTime(IMD.Inci_Modify_Date)); DocumentReference docRef = Db.Collection("MT_Incident").Document(UniqueID); WriteResult Result = await docRef.SetAsync(IMD); if (Result != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = IMD; } else { Response.Status = con.StatusNotInsert; Response.Message = con.MessageNotInsert; Response.Data = null; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
protected void btnPostThread_Click(object sender, EventArgs e) { if (Session["curUser"] == null) { return; } //Check if user is in database user = (FirebaseAdmin.Auth.UserRecord)Session["curUser"]; db = FirestoreDb.Create("cen-project-d757f"); chatRef = db.Collection("chatThreads"); DocumentReference docref = db.Collection("chatThreads").Document(Guid.NewGuid().ToString()); DateTime unixEpoch = new DateTime(1970, 1, 1); DateTime now = DateTime.Now; double milliseconds = (now - unixEpoch).TotalMilliseconds; //Add thread to database Dictionary <string, object> newThread = new Dictionary <string, object> { { "postedBy", user.Email.Substring(0, user.Email.IndexOf('@')) }, { "message", @txtMessage.Text }, { "milliseconds", milliseconds }, { "title", @txtTitle.Text } }; _ = docref.SetAsync(newThread).Result; curThread = new Guid(); }