public IActionResult Delete(string id)
        {
            db.DeleteRecord <RecipesModel>("Recipes", id);
            var items = db.LoadRecords <RecipesModel>("Recipes").ToArray <RecipesModel>();

            return(View("RecipesList", items));
        }
示例#2
0
 // This method deletes data from the database and then redisplays the data.
 public ActionResult DeleteBug(Guid id)
 {
     try
     {
         MongoCRUD db = new MongoCRUD("BZBugs");
         db.DeleteRecord<BugsModel>("Bugs", id);
         return RedirectToAction(nameof(ListBugs));
     }
     catch
     {
         return View();
     }
 }
 public IHttpActionResult DeleteSubmission(string Id)
 {
     System.Diagnostics.Debug.WriteLine("deleting: ", Id);
     db.DeleteRecord <Submission>("Submissions", Id);
     return(Ok());
 }
示例#4
0
        static void Main(string[] args)
        {
            MongoCRUD db = new MongoCRUD("Addresses");


            Person person = new Person
            {
                FirstName      = "Bob Arnold",
                LastName       = "Johnson",
                DateOfBirth    = new DateTime(1982, 10, 31, 0, 0, 0, DateTimeKind.Utc),
                PrimaryAddress = new AddressModel
                {
                    StreetAddress = "111 2nd street",
                    City          = "New York",
                    State         = "NJ",
                    Zip           = "111111"
                },
                SecondaryAddress = new AddressModel
                {
                    StreetAddress = "1112 2nd street",
                    City          = "New York",
                    State         = "AA",
                    Zip           = "line"
                }
            };

            db.InsertRecord("Users", person);

            person = new Person
            {
                FirstName      = "Natalie",
                LastName       = "Jones",
                DateOfBirth    = new DateTime(1983, 10, 31, 0, 0, 0, DateTimeKind.Utc),
                PrimaryAddress = new AddressModel
                {
                    StreetAddress = "2222 B street",
                    City          = "New York",
                    State         = "NJ",
                    Zip           = "111111"
                },
            };

            db.InsertRecord("Users", person);


            person = new Person
            {
                FirstName      = "Seth",
                LastName       = "Jones",
                DateOfBirth    = new DateTime(1987, 10, 31, 0, 0, 0, DateTimeKind.Utc),
                PrimaryAddress = new AddressModel
                {
                    StreetAddress = "3333 L street",
                    City          = "Town",
                    State         = "NJ",
                    Zip           = "111111"
                },
            };

            db.InsertRecord("Users", person);

            Console.WriteLine();
            Console.WriteLine("Records one **");
            Console.WriteLine();

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

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

                if (rec.PrimaryAddress != null)
                {
                    Console.WriteLine(rec.PrimaryAddress.StreetAddress);
                    Console.WriteLine(rec.PrimaryAddress.State);
                    Console.WriteLine(rec.PrimaryAddress.Zip);
                }
                Console.WriteLine();

                if (rec.SecondaryAddress != null)
                {
                    Console.WriteLine(rec.SecondaryAddress.StreetAddress);
                    Console.WriteLine(rec.SecondaryAddress.State);
                    Console.WriteLine(rec.SecondaryAddress.Zip);
                }
                Console.WriteLine();
            }

            Console.WriteLine();
            Console.WriteLine("Records two **");
            Console.WriteLine();

            var records2 = db.LoadRecordByField <Person>("Users", "LastName", "Jones");

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

                if (rec.PrimaryAddress != null)
                {
                    Console.WriteLine(rec.PrimaryAddress.StreetAddress);
                    Console.WriteLine(rec.PrimaryAddress.State);
                    Console.WriteLine(rec.PrimaryAddress.Zip);
                }
                Console.WriteLine();

                if (rec.SecondaryAddress != null)
                {
                    Console.WriteLine(rec.SecondaryAddress.StreetAddress);
                    Console.WriteLine(rec.SecondaryAddress.State);
                    Console.WriteLine(rec.SecondaryAddress.Zip);
                }
                Console.WriteLine();
            }

            Console.WriteLine();
            Console.WriteLine("Records by last name **");
            Console.WriteLine();

            var record = db.LoadRecordByLastName <Person>("Users", "Jones");

            Console.WriteLine($"{record.Id}: {record.FirstName} {record.LastName}");
            Console.WriteLine();

            record.FirstName = "Timothy";
            db.UpsertRecord <Person>("Users", record.Id, record);

            Console.WriteLine();
            Console.WriteLine("Records by last name after change **");
            Console.WriteLine();

            var record2b = db.LoadRecordByLastName <Person>("Users", "Jones");

            Console.WriteLine($"{record2b.Id}: {record2b.FirstName} {record2b.LastName}");
            Console.WriteLine();


            Console.WriteLine();
            Console.WriteLine("Records from address **");
            Console.WriteLine();


            // It doesn't seem to work to try pulling data from a child model:


            var records3 = db.LoadRecordByField <AddressModel>("Users", "Zip", "111111");

            foreach (var rec in records3)
            {
                Console.WriteLine("Address: " + rec.StreetAddress);
            }

            Console.WriteLine();
            Console.WriteLine("Records deletion **");
            Console.WriteLine();

            var records4 = db.LoadRecords <Person>("Users");

            foreach (var rec in records4)
            {
                db.DeleteRecord <Person>("Users", rec.Id);
            }

            Console.ReadLine();
        }
示例#5
0
        public string List(int id = -1)
        {
            Output = "";
            MongoCRUD _db = new MongoCRUD("AddressBook");

            Output += "Deleting existing records.<br /><br />";
            var  _personRecs = _db.LoadRecords <PersonModel>("Users");
            Guid _guid       = new Guid("20A9A798-FE9D-4D00-836B-2186A01A6691");

            foreach (var _rec in _personRecs)
            {
                _guid = _rec.Id;
                _db.DeleteRecord <PersonModel>("Users", _guid);
            }
            Output += "All are deleted.<br /><br />";


            #region //commented out

            //_db.InsertRecord("Users" , new PersonModel { FirstName = "Doğan", LastName = "Kartaltepe" });
            //_db.InsertRecord("Users", new PersonModel { FirstName = "Terrence", LastName = "Ritzman" });

            //PersonModel _personNew = new PersonModel
            //{
            //    FirstName = "Justin",
            //    LastName = "Kloetzer",
            //    Address = new AddressModel
            //    {
            //        StreetAddress = "123 Main Street"   ,
            //        City = "Austin"        ,
            //        State = "Texas"   ,
            //        ZipCode = "76055",
            //        AddressType = "Primary"
            //    }
            //};
            //_db.InsertRecord("Users", _personNew);
            #endregion

            for (int i = 0; i <= 15; i++)
            {
                var _p = new PersonModel()
                {
                    FirstName = Generate.RandomFirstName(),
                    LastName  = Generate.RandomLastName(),
                    Address   = new AddressModel()
                    {
                        StreetAddress = Generate.RandomAddress(),
                        City          = Generate.RandomCityName(),
                        State         = Generate.RandomStateName(),
                        ZipCode       = Generate.RandomZip(),
                        AddressType   = "Primary"
                    },
                    //  DateOfBirth = new DateTime(Generate.RandomInteger(1950, 2012), Generate.RandomInteger(1, 2), Generate.RandomInteger(1, 30), 0, 0, 0, DateTimeKind.Utc)
                    DateOfBirth = Generate.RandomDate(1950, 2012)
                };
                _db.InsertRecord("Users", _p);
            }

            #region //PERSONMODEL
            _personRecs = _db.LoadRecords <PersonModel>("Users");
            foreach (var _rec in _personRecs)
            {
                _guid = _rec.Id;
                OutputPerson(_rec);
                Output += "<br />";
            }
            var _person = _db.LoadRecordById <PersonModel>("Users", _guid);
            OutputPerson(_person);
            Output += "<br />";

            _person.DateOfBirth = Generate.RandomDate(1950, 2012); // new DateTime(Generate.RandomInteger(1950,2012), 1, 1, 0, 0, 0, DateTimeKind.Utc);
            _db.UpsertRecord("Users", _person.Id, _person);
            OutputPerson(_person);
            #endregion
            //PERSONMODEL

            #region //NAMEMODEL
            //var _recsName = _db.LoadRecords<NameModel>("Users");
            //foreach (var _rec in _recsName)
            //{
            //    _guid = _rec.Id;
            //    OutputName(_rec);
            //    Console.WriteLine("\n");

            //}
            //var _name = _db.LoadRecordById<NameModel>("Users", _guid);
            #endregion
            //NAMEMODEL

            return(Output);
        }
示例#6
0
        static void Main(string[] args)
        {
            MongoCRUD _db = new MongoCRUD("AddressBook");

            Console.WriteLine("Deleting existing records.\n\n");
            var  _personRecs = _db.LoadRecords <PersonModel>("Users");
            Guid _guid       = new Guid("20A9A798-FE9D-4D00-836B-2186A01A6691");

            foreach (var _rec in _personRecs)
            {
                _guid = _rec.Id;
                _db.DeleteRecord <PersonModel>("Users", _guid);
            }
            Console.WriteLine("All are deleted.\n\n");


            #region //commented out

            //_db.InsertRecord("Users" , new PersonModel { FirstName = "Doğan", LastName = "Kartaltepe" });
            //_db.InsertRecord("Users", new PersonModel { FirstName = "Terrence", LastName = "Ritzman" });

            //PersonModel _personNew = new PersonModel
            //{
            //    FirstName = "Justin",
            //    LastName = "Kloetzer",
            //    Address = new AddressModel
            //    {
            //        StreetAddress = "123 Main Street"   ,
            //        City = "Austin"        ,
            //        State = "Texas"   ,
            //        ZipCode = "76055",
            //        AddressType = "Primary"
            //    }
            //};
            //_db.InsertRecord("Users", _personNew);
            #endregion

            for (int i = 0; i <= 15; i++)
            {
                var _p = new PersonModel()
                {
                    FirstName = Generate.RandomFirstName(),
                    LastName  = Generate.RandomLastName(),
                    Address   = new AddressModel()
                    {
                        StreetAddress = Generate.RandomAddress(),
                        City          = Generate.RandomCityName(),
                        State         = Generate.RandomStateName(),
                        ZipCode       = Generate.RandomZip(),
                        AddressType   = "Primary"
                    },
                    DateOfBirth = Generate.RandomDate(1950, 2012)
                };
                _db.InsertRecord("Users", _p);
            }

            #region //PERSONMODEL
            _personRecs = _db.LoadRecords <PersonModel>("Users");
            foreach (var _rec in _personRecs)
            {
                _guid = _rec.Id;
                OutputPerson(_rec);
                Console.WriteLine("\n");
            }
            var _person = _db.LoadRecordById <PersonModel>("Users", _guid);
            OutputPerson(_person);
            Console.WriteLine("");

            _person.DateOfBirth = Generate.RandomDate(1950, 2012);
            _db.UpsertRecord("Users", _person.Id, _person);
            OutputPerson(_person);
            #endregion
            //PERSONMODEL

            #region //NAMEMODEL
            //var _recsName = _db.LoadRecords<NameModel>("Users");
            //foreach (var _rec in _recsName)
            //{
            //    _guid = _rec.Id;
            //    OutputName(_rec);
            //    Console.WriteLine("\n");

            //}
            //var _name = _db.LoadRecordById<NameModel>("Users", _guid);
            #endregion
            //NAMEMODEL

            Console.WriteLine("\n\nPress the any key");
            Console.ReadLine();
        }