Beispiel #1
0
        static void Main(string[] args)
        {
            MongoCRUD db = new MongoCRUD("AddressBook");

            //PersonModel person = new PersonModel
            //{
            //    FirstName = "Ribhu",
            //    LastName = "Goel",
            //    PrimaryAddress = new AddressModel
            //    {
            //        StreetAddress = "16 Inner Cir",
            //        City = "Scottsdale",
            //        State = "AZ",
            //        ZipCode = "85258"
            //    }
            //};

            // Insert
            //db.InsertRecord("Users", person);
            //db.InsertRecord("Users", new PersonModel { FirstName = "Shreyas", LastName = "Deshmukh"});

            // Load All
            //var recs = db.LoadRecords<PersonModel>("Users");

            //foreach (var rec in recs)
            //{
            //    Console.WriteLine($"{rec.Id} : {rec.FirstName} {rec.LastName}");

            //    if(rec.PrimaryAddress != null)
            //    {
            //        Console.WriteLine(rec.PrimaryAddress.City);
            //    }
            //    Console.WriteLine();
            //}

            // Load by Id
            //var oneRec = db.LoadRecordById<PersonModel>("Users", new Guid("cebe7910-fd42-4974-8212-cce32aa54f0b"));

            // Upsert record
            //oneRec.DateofBirth = new DateTime(1992, 11, 22, 0, 0, 0, DateTimeKind.Utc);
            //db.UpsertRecord("Users", oneRec.Id, oneRec);

            // Delete Record
            //db.DeleteRecord<PersonModel>("Users", oneRec.Id);


            var recs = db.LoadRecords <NameModel>("Users");

            foreach (var rec in recs)
            {
                Console.WriteLine($"{rec.FirstName} {rec.LastName}");

                Console.WriteLine();
            }

            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            MongoCRUD db = new MongoCRUD("AddressBook");

            //PersonModel person = new PersonModel
            //{
            //    FirstName = "Aysenur",
            //    LastName = "Şahin",
            //    PrimaryAddress = new AddressModel
            //    {
            //        StreetAdress = "Nazilli",
            //        State = "Türkiye",
            //        City = "Ankara",
            //        Zipcode = "06540"
            //    }
            //};
            //PersonModel person2 = new PersonModel
            //{
            //    FirstName = "Yeni",
            //    LastName = "Şahin"
            //};

            //db.InsertRecord("Users", person);
            //db.InsertRecord("Users", person2);

            var recs = db.LoadRecords <NameModel>("Users");

            foreach (var rec in recs)
            {
                Console.WriteLine($" {rec.FirstName} {rec.LastName}");

                Console.WriteLine();
            }



            //var oneRec = db.LoadRecordById<PersonModel>("Users",new Guid("5f373d47-5cfd-41df-a1b7-f80cd340180c"));
            //Console.WriteLine(oneRec.FirstName);

            ////UPDATE
            //oneRec.DateOfBirth = DateTime.Now;
            //db.UpsertRecord("Users", oneRec.Id, oneRec);


            ////DELETE
            //db.DeleteRecord<PersonModel>("Users", oneRec.Id);
            Console.ReadLine();
        }
Beispiel #3
0
        private static void NewMethod()
        {
            MongoCRUD db = new MongoCRUD("AddressBook");

            Person insert = new Person()
            {
                FirstName      = "John",
                LastName       = "Doe",
                PrimaryAddress = new Address()
                {
                    StreetAddress = "A",
                    City          = "B",
                    State         = "C",
                    ZipCode       = "D"
                }
            };

            db.InsertDocument("Users", insert);
            var names     = db.GetDocuments <Name>("Users");
            var documents = db.GetDocuments <Person>("Users");


            var documentForUpdate = db.GetDocumentById <Person>("Users", documents.FirstOrDefault().Id);

            documentForUpdate.PrimaryAddress = new Address()
            {
                StreetAddress = "UpsertA",
                City          = "UpsertB",
                State         = "UpsertC",
                ZipCode       = "UpsertD"
            };
            db.UpdateDocument("Users", documentForUpdate.Id, documentForUpdate);



            db.DeleteDocument <Person>("Users", documentForUpdate.Id);

            Console.ReadLine();
        }