Ejemplo n.º 1
0
        public async Task <WriteResult> RemoveProductToCart(string pProductId, string pUserUId)
        {
            FirestoreDb db   = CreateInstanceDB();
            FirebaseApp wApp = CreateFirebaseApp();

            //GetData
            DocumentReference wDocRef  = db.Collection("user").Document(pUserUId);
            DocumentSnapshot  snapshot = await wDocRef.GetSnapshotAsync();

            WriteResult wWResult = null;

            Dictionary <string, object>[] wCartArray = snapshot.ContainsField("carrello") ? snapshot.GetValue <Dictionary <string, object>[]>("carrello") : null;
            if (wCartArray != null)
            {
                foreach (Dictionary <string, object> wCartDBColl in wCartArray)
                {
                    if (wCartDBColl["uidProdotto"].ToString() == pProductId)
                    {
                        wWResult = await wDocRef.UpdateAsync("carrello", FieldValue.ArrayRemove(wCartDBColl));
                    }
                }
            }
            //End get Data

            return(wWResult);
        }
Ejemplo n.º 2
0
        public void TakeTeacherAttendance(IList <string> teacherIds, DateTime date)
        {
            string d = date.ToString("MM/dd/yyyy");

            foreach (string teacherId in Teachers.Keys)
            {
                DocumentReference dr = db.Collection("teachers").Document(teacherId);

                DocumentSnapshot snapshot = Teachers[teacherId];

                try
                {
                    snapshot.GetValue <string[]>("attended");
                    if (teacherIds.Contains(teacherId))
                    {
                        dr.UpdateAsync("attended", FieldValue.ArrayUnion(d)).Wait();
                    }
                    else
                    {
                        dr.UpdateAsync("attended", FieldValue.ArrayRemove(d)).Wait();
                    }
                }
                catch
                {
                    if (teacherIds.Contains(teacherId))
                    {
                        Dictionary <string, object> update = new Dictionary <string, object>
                        {
                            { "attended", new string[] { d } }
                        };
                        dr.SetAsync(update, SetOptions.MergeAll).Wait();
                    }
                }
            }
        }
 public static async Task RemoveNotificationFromUserAsync(string userId, string notification_id)
 {
     await CrossCloudFirestore.Current
     .Instance
     .GetCollection("User")
     .GetDocument(userId)
     .UpdateDataAsync("notifications", FieldValue.ArrayRemove(notification_id));
 }
Ejemplo n.º 4
0
 private static void RemoveAssetRefFromEdge(WriteBatch batch, DocumentReference assetRef, DocumentReference edgeRef)
 {
     Console.WriteLine($"Removing asset ({assetRef.Id}) from edge ({edgeRef.Id})");
     batch.Update(edgeRef, new Dictionary <string, object> {
         { nameof(EdgeData.AssetRefs), FieldValue.ArrayRemove(assetRef) },
         { nameof(EdgeData.LastUpdate), Timestamp.GetCurrentTimestamp() }
     });
 }
Ejemplo n.º 5
0
 /**
  * Remove user request from a team
  */
 public static async Task RemoveUserRequestFromTeamAsync(string userId, Team team)
 {
     await CrossCloudFirestore.Current
     .Instance
     .GetCollection("Team")
     .GetDocument(team.Id)
     .UpdateDataAsync("member_request", FieldValue.ArrayRemove(userId));
 }
 /**
  * Remove user request from a team
  */
 public static async Task RemoveTeamInvitationFromUserAsync(string teamId, User user)
 {
     await CrossCloudFirestore.Current
     .Instance
     .GetCollection("Team")
     .GetDocument(user.Id)
     .UpdateDataAsync("invitation", FieldValue.ArrayRemove(teamId));
 }
 public static async Task RemoveTeamFromUserAsync(string userId, Team team)
 {
     await CrossCloudFirestore.Current
     .Instance
     .GetCollection("User")
     .GetDocument(userId)
     .UpdateDataAsync("team", FieldValue.ArrayRemove(team.Id));
 }
Ejemplo n.º 8
0
    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 } } });
    }
Ejemplo n.º 9
0
        void Delete_An_Element_Inside_An_Array()
        {
            DocumentReference           docref = db.Collection("Add_Aray").Document("myDoc");
            Dictionary <string, object> data   = new Dictionary <string, object>()
            {
                { "My Array", FieldValue.ArrayRemove(456, true) }
            };

            docref.UpdateAsync(data);
            MessageBox.Show("Done");
        }
Ejemplo n.º 10
0
        public void ArrayRemove()
        {
            var sentinel = FieldValue.ArrayRemove("a", 1);
            var value    = ValueSerializer.Serialize(SerializationContext.Default, sentinel);

            Assert.Equal(SentinelKind.ArrayRemove, SentinelValue.GetKind(value));
            var array    = SentinelValue.GetArrayValue(value);
            var expected = CreateArray(CreateValue("a"), CreateValue(1)).ArrayValue;

            Assert.Equal(expected, array);
        }
Ejemplo n.º 11
0
        private static async Task UpdateDocumentArray(string project)
        {
            FirestoreDb db = FirestoreDb.Create(project);
            // [START fs_update_document_array]
            DocumentReference washingtonRef = db.Collection("cities").Document("DC");

            // Atomically add a new region to the "regions" array field.
            await washingtonRef.UpdateAsync("Regions", FieldValue.ArrayUnion("greater_virginia"));

            // Atomically remove a region from the "regions" array field.
            await washingtonRef.UpdateAsync("Regions", FieldValue.ArrayRemove("east_coast"));

            // [END fs_update_document_array]
            Console.WriteLine("Updated the Regions array of the DC document in the cities collection.");
        }
Ejemplo n.º 12
0
    public IEnumerator TestRemoveObjectsViaUpdateArrayRemove() {
      DocumentReference doc = TestDocument();
      var data = new Dictionary<string, object> {
        { "array",
          FieldValue.ArrayUnion(1L, new Dictionary<string, object> { { "a", "value" } }, 3L) }
      };
      yield return AwaitSuccess(doc.SetAsync(data));

      data = new Dictionary<string, object> {
        { "array", FieldValue.ArrayRemove(new Dictionary<string, object> { { "a", "value" } }) }
      };
      AwaitSuccess(doc.UpdateAsync(data));
      yield return AssertExpectedDocument(
          doc, new Dictionary<string, object> { { "array", new List<object> { 1L, 3L } } });
    }
Ejemplo n.º 13
0
        public async Task <IActionResult> Delete(string documentId, string productId)
        {
            db = FirestoreDatabase.LoadDatabase();

            CollectionReference klantenColl  = db.Collection("Klanten");
            DocumentReference   document     = klantenColl.Document(documentId);
            DocumentSnapshot    klantMetNaam = await document.GetSnapshotAsync();

            Klant klant = klantMetNaam.ConvertTo <Klant>();

            Product product = klant.products.FirstOrDefault(p => p.ProductId == productId);

            if (product != null)
            {
                await document.UpdateAsync("products", FieldValue.ArrayRemove(product));
            }

            return(RedirectToAction(documentId, "Klant/Producten"));
        }
Ejemplo n.º 14
0
        public void EditStudent(string studentId, string newClassName, string newStudentName, string newStudentPhone, string newGrade,
                                string newParentName, string newParentPhone, DateTime newBirthday)
        {
            DocumentReference dr = db.Collection("students").Document(studentId);

            Dictionary <string, object> update = new Dictionary <string, object>
            {
                { "studentName", newStudentName },
                { "studentPhone", newStudentPhone },
                { "grade", newGrade },
                { "parentName", newParentName },
                { "parentPhone", newParentPhone },
                { "birthday", newBirthday.ToString("MM/dd/yyyy").Substring(0, 5) }
            };

            dr.SetAsync(update, SetOptions.MergeAll).Wait();
            var w = dr.GetSnapshotAsync();

            w.Wait();
            Students[studentId] = w.Result;

            if (CurrentClass != newClassName)
            {
                //Remove student from current class
                DocumentReference curClass = db.Collection("classes").Document(Classes[CurrentClass]);
                curClass.UpdateAsync("students", FieldValue.ArrayRemove(studentId)).Wait();

                //add student to new class
                DocumentReference newClass = db.Collection("classes").Document(Classes[newClassName]);
                try
                {
                    newClass.UpdateAsync("students", FieldValue.ArrayUnion(studentId)).Wait();
                }
                catch
                {
                    Dictionary <string, object> fields = new Dictionary <string, object>
                    {
                        { "students", new string[] { studentId } }
                    };
                    newClass.SetAsync(fields).Wait();
                }
            }
        }
Ejemplo n.º 15
0
        public void TakeAttendance(IList <string> studentIds, DateTime date)
        {
            string d = date.ToString("MM/dd/yyyy");

            // Make sure that takeAttendance is the last call that happens!!!!!

            // go through all students in this class
            // if they are in the list, add their attendance
            // if not, remove their attendance
            foreach (string studentId in Students.Keys)
            {
                DocumentReference dr = db.Collection("students").Document(studentId);

                DocumentSnapshot snapshot = Students[studentId];

                try
                {
                    snapshot.GetValue <string[]>("attended");
                    if (studentIds.Contains(studentId))
                    {
                        dr.UpdateAsync("attended", FieldValue.ArrayUnion(d)).Wait();
                    }
                    else
                    {
                        dr.UpdateAsync("attended", FieldValue.ArrayRemove(d)).Wait();
                    }
                }
                catch
                {
                    if (studentIds.Contains(studentId))
                    {
                        Dictionary <string, object> update = new Dictionary <string, object>
                        {
                            { "attended", new string[] { d } }
                        };
                        dr.SetAsync(update, SetOptions.MergeAll).Wait();
                    }
                }
            }
            CurrentClass = "";
        }
Ejemplo n.º 16
0
        public void EditTeacher(string teacherId, string newClassName, string newTeacherName, string newTeacherPhone, DateTime newBirthday)
        {
            DocumentReference dr = db.Collection("teachers").Document(teacherId);

            Dictionary <string, object> update = new Dictionary <string, object>
            {
                { "teacherName", newTeacherName },
                { "phone", newTeacherPhone },
                { "birthday", newBirthday.ToString("MM/dd/yyyy").Substring(0, 5) }
            };

            dr.SetAsync(update, SetOptions.MergeAll).Wait();
            var w = dr.GetSnapshotAsync();

            w.Wait();
            Teachers[teacherId] = w.Result;

            if (CurrentClass != newClassName)
            {
                //Remove student from current class
                DocumentReference curClass = db.Collection("classes").Document(Classes[CurrentClass]);
                curClass.UpdateAsync("teachers", FieldValue.ArrayRemove(teacherId)).Wait();

                //add student from current class
                DocumentReference newClass = db.Collection("classes").Document(Classes[newClassName]);
                try
                {
                    newClass.UpdateAsync("teachers", FieldValue.ArrayUnion(teacherId)).Wait();
                }
                catch
                {
                    Dictionary <string, object> t = new Dictionary <string, object>
                    {
                        { "teachers", new string[] { teacherId } }
                    };
                    newClass.SetAsync(t, SetOptions.MergeAll).Wait();
                }
            }
        }
Ejemplo n.º 17
0
        public async Task <WriteResult> RemoveMenuCategory(String RestaurantID, String MenuCategory)
        {
            WriteResult writeResult = await Root.Collection("restaurants").Document(RestaurantID).UpdateAsync("MenuCategories", FieldValue.ArrayRemove(MenuCategory));

            return(writeResult);
        }
Ejemplo n.º 18
0
        public async Task <WriteResult> RemoveFood(String RestaurantID, Food food)
        {
            WriteResult writeResult = await Root.Collection("restaurants").Document(RestaurantID).UpdateAsync("Foods", FieldValue.ArrayRemove(food));

            return(writeResult);
        }