This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace AuthorSerialize | |
{ | |
public class Address | |
{ | |
public string Country; | |
public string State; | |
public string Street; | |
public int HouseNum; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace AuthorSerialize | |
{ | |
public class Book | |
{ | |
public string BookName; | |
public string Genre; | |
public string ISBNcode; | |
public Book() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using Newtonsoft.Json; | |
namespace AuthorSerialize | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MongoDB; | |
using MongoDB.Driver; | |
namespace MongoAddress | |
{ | |
public class Person | |
{ | |
public int _id {get;set;} | |
public string FirstName {get; set;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace MongoAddress | |
{ | |
public class Address | |
{ | |
public string Country; | |
public string State; | |
public string Area; | |
public string Street; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace MongoAddress | |
{ | |
class PersonFactory | |
{ | |
public Person CreatePerson() | |
{ | |
Person person = new Person(); | |
System.Console.WriteLine("Enter The _id of the document"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static IMongoCollection<Person> InitializeDatabase() | |
{ | |
var client = new MongoClient("mongodb+srv://lol:lol@clusterone-5rfg7.mongodb.net/CustomersDB?retryWrites=true&w=majority"); | |
var database = client.GetDatabase("CustomersDB"); | |
var collection = database.GetCollection<Person>("Customers"); | |
return collection; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void AddCustomer(IMongoCollection<Person> collection) | |
{ | |
bool repeat = true; | |
PersonFactory factory = new PersonFactory(); | |
Person person = new Person(); | |
while (repeat) | |
{ | |
person = factory.CreatePerson(); | |
collection.InsertOne(person); | |
Console.WriteLine("Go again? Y/N: "); |
OlderNewer