Exemple #1
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();
        }
Exemple #2
0
        private static void RUD_Person(MongoCRUD db, List <PersonModel> recs)
        {
            var oneRec = db.LoadRecordById <PersonModel>("Users", recs[2].Id);

            oneRec.DateOfBirth = new DateTime(2003, 12, 28, 0, 0, 0, DateTimeKind.Utc);
            db.UpsertRecord("Users", oneRec.Id, oneRec);

            db.DeleteRecord <PersonModel>("Users", oneRec.Id);
        }
Exemple #3
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();
        }
Exemple #4
0
        private static void InsertName(MongoCRUD db)
        {
            NameModel person = new NameModel
            {
                FirstName = "Andre",
                LastName  = "Bacic"
            };

            db.InsertRecord("Users", person);
        }
Exemple #5
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();
        }
        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();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            // if not available it will actually create one!  Can't do this in SQL.
            MongoCRUD db = new MongoCRUD("AddressBook");

            var oneRecord = db.LoadRecordById <PersonModel>("Users", new Guid("f33c2b5e-4eaf-4b4f-b1f6-d3b257ea30a3"));

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

            Console.ReadLine();
        }
Exemple #8
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();
        }
Exemple #9
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);
        }
Exemple #10
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);
        }
Exemple #11
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();
        }
Exemple #12
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();
        }
Exemple #13
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();
        }
Exemple #14
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);
        }
Exemple #15
0
        static void Main(string[] args)
        {
            MongoCRUD db = new MongoCRUD("UserInfo");

            /*
             * Student student = new Student
             * {
             *   Id = 10100,
             *   FirstName = "Mohamed",
             *   LastName = "Ahmed",
             *   PrimaryAddress = new Address
             *   {
             *       Street = "Dr.Ali Ahmed",
             *       City = "ALexandria",
             *       State = "Egypt",
             *       ZipCode = "21934"
             *   }
             * };
             * db.InsertRecord("Users", student);
             */
            /*
             * var recs = db.GetRecords<Student>("Users");
             * foreach (var rec in recs)
             * {
             *  Console.WriteLine($"{rec.Id}:{rec.FirstName} {rec.LastName}");
             *  if (rec.PrimaryAddress!=null)
             *  {
             *      Console.WriteLine(rec.PrimaryAddress.City + "\n");
             *  }
             * }
             */
            /*
             * var rec = db.GetRecordsById<Student>("Users", 10100);
             * Console.WriteLine($"{rec.Id}:{rec.FirstName} {rec.LastName}");
             */
            /*
             * var rec = db.GetRecordsById<Student>("Users", 10100);
             * rec.DateOfBitrth = new DateTime(1995, 3, 4, 5, 6, 7, DateTimeKind.Local);
             * db.UpdateRecord("Users", rec.Id, rec);
             */
            //db.DeleteRecord<Student>("Users", rec.Id);


            Console.ReadKey();
        }
Exemple #16
0
        private static PersonModel InsertPerson(MongoCRUD db)
        {
            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);
            return(person);
        }
Exemple #17
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();
        }
Exemple #18
0
        static void Main(string[] args)
        {
            MongoCRUD mongoCRUD = new MongoCRUD("Student");

            #region Insert Record
            //var model = new Model
            //{
            //    FirstName = "Mohit",
            //    LastName = "Ande",
            //    Age = 24,
            //    AddressModel = new AddressModel
            //    {
            //        State = "Telangana",
            //        City = "Hyderabad",
            //        Nationality = "Indian"
            //    }
            //};
            //mongoCRUD.InsertRecord("Test", model);
            #endregion

            #region  GetRecords
            //var record = mongoCRUD.GetRecords<Model>("Test");
            //foreach (var i in record)
            //{
            //    Console.WriteLine($" { i.Id}: {i.FirstName} {i.LastName} ");
            //}
            #endregion

            #region GetRecordbyId
            // dc90f7b8-98b3-463d-bcc9-43386cb99942
            // 8e17bbd4-fdf8-4e75-956d-e91bc1989a0b
            //var rec = mongoCRUD.GetRecordById<Model>("Test", new Guid("8e17bbd4-fdf8-4e75-956d-e91bc1989a0b"));
            //Console.WriteLine(rec.FirstName);
            #endregion

            #region UpdateRecord
            //var result = mongoCRUD.GetRecordById<Model>("Test", new Guid("8e17bbd4-fdf8-4e75-956d-e91bc1989a0b"));
            //result.DateTime = new DateTime(1995, 11, 27,0,0,0, DateTimeKind.Utc);
            var model = new Model
            {
                FirstName    = "Mohit",
                LastName     = "Ande",
                Age          = 24,
                AddressModel = new AddressModel
                {
                    State       = "Telangana",
                    City        = "Hyderabad",
                    Nationality = "Indian"
                }
            };
            mongoCRUD.InsertRecord("Test", model);
            model.DateTime = new DateTime(1995, 11, 27, 0, 0, 0, DateTimeKind.Utc);
            mongoCRUD.UpdateRecord("Test", model.Id, model);

            #endregion

            #region DeleteRecord
            //var res = mongoCRUD.GetRecordById<Model>("Test", new Guid("8e17bbd4-fdf8-4e75-956d-e91bc1989a0b"));
            //mongoCRUD.DeleteRecord<Model>("Test", res.Id);
            #endregion
        }