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 LnkdList | |
{ | |
public class Person | |
{ | |
public string Name {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 LnkdList | |
{ | |
public class Node | |
{ | |
public Node Next; | |
public Person person; | |
public Node() |
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
static void Main(string[] args) | |
{ | |
IMongoCollection<Person> collection = InitializeDatabase(); | |
if (args[0] == "Add") | |
{ | |
AddCustomer(collection); | |
} | |
else if (args[0] == "List") | |
{ |
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 UpdateRename(IMongoCollection<Person> collection, int id,string field, string renamed) | |
{ | |
var update = Builders<Person>.Update.Set(field,renamed); | |
collection.UpdateOne(x => x._id == id,update); | |
} |
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 DeleteCustomer(IMongoCollection<Person> collection, int id) | |
{ | |
var result = collection.DeleteOne<Person>(x => x._id == id); | |
if (result.DeletedCount > 0) | |
Console.WriteLine("deleted"); | |
} |
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 PrintPerson(Person person) | |
{ | |
Console.WriteLine($"Person ID is {person._id}"); | |
Console.WriteLine($"Person first Name is {person.FirstName}"); | |
Console.WriteLine($"Person Last Name is {person.LastName}"); | |
Console.WriteLine($"Person HouseNum is {person.Address.HouseNum}"); | |
Console.WriteLine($"Person Street is {person.Address.Street}"); | |
Console.WriteLine($"Person Area is {person.Address.Area}"); | |
Console.WriteLine($"Person state is {person.Address.State}"); | |
Console.WriteLine($"Person country is {person.Address.Country}"); |
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 FindCustomer(IMongoCollection<Person> collection, int id) | |
{ | |
var persons = collection.Find<Person>(person => person._id == id).ToList(); | |
foreach (var person in persons) | |
{ | |
PrintPerson(person); | |
} | |
} |
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 FindCustomer(IMongoCollection<Person> collection, int id) | |
{ | |
var persons = collection.Find<Person>(person => person._id == id).ToList(); | |
foreach (var person in persons) | |
{ | |
PrintPerson(person); | |
} | |
} |
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 FindCustomer(IMongoCollection<Person> collection, int id) | |
{ | |
var persons = collection.Find<Person>(person => person._id == id).ToList(); | |
foreach (var person in persons) | |
{ | |
PrintPerson(person); | |
} | |
} |
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: "); |