示例#1
0
        static void Main(string[] args)
        {
            MongoCRUD db = new MongoCRUD("AddressBook");
            //1. To insert simple model objects
            //db.InsertRecord("Users", new PersonModel { FirstName = "Mary", LastName = "Jones" });

            //2. To insert complex model objects
            //PersonModel person = new PersonModel()
            //{
            //    FirstName = "Joe",
            //    LastName = "Smith",
            //    PrimaryAddress = new AddressModel()
            //    {
            //        StreetAddress = "101 Oak Street",
            //        City = "Scranton",
            //        State = "PA",
            //        ZipCode = "11100"
            //    }
            //};
            //db.InsertRecord("Users", person);


            //3. To read records (Simpler to 'select * from db' in SQL database
            var records = db.LoadRecords <PersonModel>("Users");

            foreach (var item in records)
            {
                Console.WriteLine($"{item.Id}: {item.FirstName}: {item.LastName} ");
                if (item.PrimaryAddress != null)
                {
                    Console.WriteLine(item.PrimaryAddress.City);
                }
                Console.WriteLine();
            }


            //4. To read single record depending upon ID
            var userRecord = db.LoadRecordById <PersonModel>("Users", new Guid("8dcc7170-c154-407a-9a4e-f335c8fbd46e"));

            //5. To update the single record
            userRecord.DateOfBirth = new DateTime(1982, 10, 31, 0, 0, 0, DateTimeKind.Utc);
            db.UpsertRecord("Users", userRecord.Id, userRecord);

            //6. To delete record
            db.DeleteRecord <PersonModel>("Users", userRecord.Id);

            //7. To read data in different Model Object
            var nameRecords = db.LoadRecords <NameModel>("Users");

            foreach (var item in records)
            {
                Console.WriteLine($"{item.Id}: {item.FirstName}: {item.LastName} ");
                Console.WriteLine();
            }

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

            //PersonModel person = new PersonModel
            //{
            //    FirstName = "James",
            //    LastName = "Bond",
            //    PrimaryAddress = new AddressModel
            //    {
            //        StreetAddress = "8 pivet drive",
            //        City = "Norwich",
            //        State = "Cambridge",
            //        ZipCode = "1234"
            //    }
            //};
            //db.InsertRecord("Users", person);

            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("602879cf-d2db-4f1d-9db6-845817322e38"));
            //oneRec.DateOfBirth = new DateTime(1982, 10, 31, 0, 0, 0, DateTimeKind.Utc);
            //db.UpsertRecord("Users", oneRec.Id, oneRec);

            //db.DeleteRecord<PersonModel>("Users", oneRec.Id);
            Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            MongoCRUD db = new MongoCRUD("AddressBook");

            //PersonModel person = new PersonModel
            //{
            //    FirstName = "LogiBear",
            //    LastName = "Jayawant"
            //};

            //PersonModel person = new PersonModel
            //{
            //    FirstName = "James",
            //    LastName = "Jayawant",
            //    PrimaryAddress = new AddressModel
            //    {
            //        StreetAddress = "23 MOntauk Ave",
            //        City = "Merrick",
            //        State = "NY",
            //        ZipCode = "11566"
            //    }
            //};

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

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

            //foreach (NameModel item in records)
            //{
            //    Console.WriteLine($"{item.FirstName} {item.LastName}");
            //    Console.WriteLine();
            //}

            var records = db.LoadRecords <PersonModel>("Users");

            foreach (PersonModel item in records)
            {
                Console.WriteLine($"{item.Id} : {item.FirstName} {item.LastName}");
                if (item.PrimaryAddress != null)
                {
                    Console.WriteLine(item.PrimaryAddress.City);
                }
                Console.WriteLine();
            }

            // var person = db.LoadRecordById<PersonModel>("Users", new Guid("12be3a03-08f9-4048-b666-30b7be835366"));

            //person.DateOfBirth = new DateTime(1965, 1, 17, 0, 0, 0, DateTimeKind.Utc);

            //db.UpsertRecord<PersonModel>("Users", person.Id, person);

            // db.DeleteRecord<PersonModel>("Users", person.Id);

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

            //PersonModel person = new PersonModel()
            //{
            //    FirstName = "Joe",
            //    LastName = "smith",
            //    PrimaryAddress = new AddressModel
            //    {
            //        StreetAddress = "101 Oak Street",
            //        city = "Scranton",
            //        state = "PA",
            //        ZipCode = "18512"
            //    }

            //};

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


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


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

                Console.WriteLine();
            }


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

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


            //var oneRec = db.LoadRecordById<PersonModel>("Users", new Guid("db57d0b5-6740-487b-9d37-33057d4ee2d3"));

            //oneRec.DateOfBirth = new DateTime(1982, 10, 31, 0, 0, 0, DateTimeKind.Utc);
            //db.UpsertRecord("Users", oneRec.Id, oneRec);

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

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

            //PersonModel person = new PersonModel
            //{
            //	FirstName = "Joe",
            //	LastName = "Smith",
            //	PrimaryAddress = new AddressModel
            //	{
            //		StreetAddress = "101 Oak Street",
            //		City = "Scranton",
            //		State = "PA",
            //		ZipCode = "18512"
            //	}
            //};

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

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

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

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

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

            //-------

            // Update or Delete
            //var oneRec = db.LoadRecordById<PersonModel>("Users", new Guid("bdc73c6f-5530-42c2-bd4e-e2b324762431"));
            // UPDATE
            //oneRec.DateOfBirth = new DateTime(1982, 10, 31, 0, 0, 0, 0, DateTimeKind.Utc);
            //db.UpsertRecord("Users", oneRec.Id, oneRec);
            // DELETE
            //db.DeleteRecord<PersonModel>("Users", oneRec.Id);

            Console.ReadLine();
        }
示例#6
0
        private static List <NameModel> DisplayNames(MongoCRUD db)
        {
            var recs = db.LoadRecords <NameModel>("Users");

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

                Console.WriteLine();
            }

            return(recs);
        }
示例#7
0
        private static CarModel CreateCar(MongoCRUD db)
        {
            var person = db.LoadRecords <PersonModel>("Users")[1];

            var car = new CarModel
            {
                OwnerId  = person.Id,
                YearMade = 2013
            };

            db.InsertRecord("Cars", car);
            return(car);
        }
示例#8
0
        static void Main(string[] args)
        {
            MongoCRUD db = new MongoCRUD("AddressBook");

            //PersonModel person = new PersonModel
            //{
            //    FirstName = "John",
            //    LastName = "Smith",
            //    PrimaryAddress = new AddressModel
            //    {
            //        StreetAddress = "101 Oak Street",
            //        City = "Scranton",
            //        State = "PA",
            //        ZipCode = "18512"
            //    }
            //};

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

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

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


            //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();
            //}

            //var oneRec = db.LoadRecordById<PersonModel>("Users", new Guid("a5030a36-95ac-4ab3-8a7a-3174fff5094b"));

            //oneRec.DateOfBirth = new DateTime(1989, 8, 28, 0, 0, 0, DateTimeKind.Utc);
            //db.UpsertRecord("Users", oneRec.Id, oneRec);

            //db.DeleteRecords<PersonModel>("Users", oneRec.Id);


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

            /*
             * PersonModel person = new PersonModel
             * {
             *      FirstName = "Joe",
             *      LastName = "Smith",
             *      PrimaryAddress = new AddresModel
             *      {
             *              StreetAddres = "101 Oak Street",
             *              City = "Scranton",
             *              ZipCode = "18512"
             *      }
             * };
             *
             * db.InsertRecord("Users", person);
             */


            //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}");
             *      }
             * }
             */

            //var oneRec = db.LoadRecordById<PersonModel>("User", new Guid("0a6acfca-b10c-4438-8e73-b09b015d650a"));
            //oneRec.DateOfBirth = new DateTime(1994, 05, 14, 0, 0, 0, DateTimeKind.Utc);
            //db.UpsertRecord("Users", oneRec.Id, oneRec);

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

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

            Console.ReadLine();
        }
示例#10
0
        static void Main(string[] args)
        {
            //Database ophalen en starten er mee te werken of niewe database opzetten
            MongoCRUD db = new MongoCRUD("Addressbook");

            //============Insert van een PersonModel in Users
            //PersonModel person = new PersonModel
            //{
            //    FirstName = "Jpe",
            //    LastName = "Smith",
            //    PrimaryAddress = new AddressModel
            //    {
            //        StreetAddress = "101 Oak Street",
            //        City = "Scranton",
            //        State = "PA",
            //        ZipCode = "18512"
            //    }
            //};
            //db.InsertRecord("Users", person);

            //================ "Select All" van Users; Opgelet<PersonModel>
            // 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);
            //    }
            //}
            //var oneRec = db.LoadRecordById<PersonModel>("Users", new Guid("d435c856-341b-438d-9c1b-b8f29f42e4d2"));
            //datum toevoegen aan oneRec
            //oneRec.DateOfBirth = new DateTime(1982, 10, 20, 0, 0, 0, DateTimeKind.Utc);
            //db.UpsertRecord("Users", oneRec.Id, oneRec);
            //db.DeleteRecords<PersonModel>("Users", oneRec.Id);

            //
            //================ "Select All" van Users maar nu via de andere class; Opgelet<NameModel>
            var recs = db.LoadRecords <NameModel>("Users");

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


            Console.ReadLine();
        }
示例#11
0
        private static List <PersonModel> DisplayPeople(MongoCRUD db)
        {
            var recs = db.LoadRecords <PersonModel>("Users");

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

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

            return(recs);
        }
示例#12
0
        static void Main(string[] args)
        {
            MongoCRUD db = new MongoCRUD("AddressBook");

            //InsertName(db);
            //DisplayNames(db);

            //InsertPerson(db);
            //List<PersonModel> recs = DisplayPeople(db);

            //RUD_Person(db, recs);

            //CreateCar(db);
            var car = db.LoadRecords <CarModel>("Cars").First(c => c.YearMade == 2013);

            car = db.LookupRecord <CarModel>("Cars", "Users", car.Id, "OwnerId", "_id", "Owner");

            Console.WriteLine($"Car with id { car.Id }:\nYear - { car.YearMade }\nOwner name - { car.Owner.FirstName }");

            Console.ReadLine();
        }