예제 #1
0
        static void Main(string[] args)
        {
            MongoCRUD db = new MongoCRUD("AddressBook");
            //PersonModel person = new PersonModel
            //{
            //    Firstname="Ansu",
            //    Lastname="Gyawali",
            //    PrimaryAddress=new AddressModel
            //    {
            //        StreetAddress="1206 hooks dr",
            //        City="Hammond",
            //        State="LA",
            //        ZipCode="70401",

            //    }

            //};

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

            //var records = db.LoadRecords<PersonModel>("Users");
            //foreach(var rec in records)
            //{
            //    Console.WriteLine($"{rec.Id}:{rec.Firstname}{rec.Lastname}");
            //    if (rec.PrimaryAddress != null)
            //    {
            //        Console.WriteLine(rec.PrimaryAddress.City);
            //    }
            //    Console.WriteLine();
            //}
            var rec = db.LoadRecordById <PersonModel>("Users", new Guid("4992cd9a-5e5b-4401-b080-df7d0ad33511"));

            rec.DateOfBirth = new DateTime(1997, 10, 19, 0, 0, 0, DateTimeKind.Utc);
            db.UpsertRecord("Users", rec.Id, rec);
            db.DeleteRecord <PersonModel>("Users", rec.Id);
            Console.ReadLine();
        }
예제 #2
0
파일: Program.cs 프로젝트: R3ap4r/MongoDB
        static void Main(string[] args)
        {
            //Create a database and insert some dummy data

            MongoCRUD db = new MongoCRUD("AddressBook");

            db.InsertRecord("Users", new PersonModel {
                FirstName = "Russ", LastName = "VeganRankin", IsAdmin = true
            });
            db.InsertRecord("Users", new PersonModel {
                FirstName = "Billy", LastName = "MeatballMilano", IsAdmin = true
            });
            db.InsertRecord("Users", new PersonModel {
                FirstName = "Colin", LastName = "AnimalJerwood", IsAdmin = true
            });
            db.InsertRecord("Users", new PersonModel {
                FirstName = "Wattie", LastName = "HeartAttackBuchan"
            });
            db.InsertRecord("Users", new PersonModel {
                FirstName = "Elvis", LastName = "ToiletPresley"
            });

            //Load the database we've just created
            var records = db.LoadRecords <PersonModel>("Users");

            //Loop through the records and show them
            foreach (var record in records)
            {
                Console.WriteLine($"{record.FirstName}\t\t{record.LastName}\t\tAdministrator: {record.IsAdmin}");
            }
            ;

            //Ask a first and lastname to search for and delete record from the database
            Console.Write("Enter the firstname: ");
            string firstName = Console.ReadLine();

            Console.Write("Enter the lastname: ");
            string lastName = Console.ReadLine();

            db.DeleteRecord <PersonModel>("Users", firstName, lastName);

            //reload database and show it again, this time the record should be deleted
            var records2 = db.LoadRecords <PersonModel>("Users");

            foreach (var IsAdmin in records2.Where(t => t.IsAdmin == true))
            {
                Console.WriteLine(IsAdmin.FirstName);
            }
            ;


            //This time, only get the lastname and check if the person is an admin
            Console.Write("Enter the lastname: ");
            string findLastName = Console.ReadLine();

            var searchResult = db.FindRecord <PersonModel>("Users", findLastName);

            //Display every record that complies with the search parameter
            foreach (var item in searchResult)
            {
                Console.WriteLine($"{item.FirstName}  {item.LastName}  Administrator: {item.IsAdmin}");
            }

            Console.ReadLine();
        }