Skip to content

Instantly share code, notes, and snippets.

View AbhinavPradeep's full-sized avatar

Abhinav Pradeep AbhinavPradeep

View GitHub Profile
@AbhinavPradeep
AbhinavPradeep / Author.cs
Created December 12, 2019 23:27
Describing the fields required for an author.
using System.Collections.Generic;
using System.Text.Json;
namespace AuthorSerialize
{
public class Author
{
public string FirstName {get; set;}
public string LastName {get;set;}
namespace AuthorSerialize
{
public class Address
{
public string Country;
public string State;
public string Street;
public int HouseNum;
}
}
namespace AuthorSerialize
{
public class Book
{
public string BookName;
public string Genre;
public string ISBNcode;
public Book()
{
namespace AuthorSerialize
{
class AuthorFactory
{
public Author CreateAuthor()
{
Author Kishimoto = new Author();
Kishimoto.FirstName = "Mashashi";
Kishimoto.LastName = "Kishimoto";
@AbhinavPradeep
AbhinavPradeep / Program.cs
Last active December 13, 2019 03:30
This is program.cs
using System;
using System.IO;
using Newtonsoft.Json;
namespace AuthorSerialize
{
public class Program
{
static void Main(string[] args)
{
using System;
using MongoDB;
using MongoDB.Driver;
namespace MongoAddress
{
public class Person
{
public int _id {get;set;}
public string FirstName {get; set;}
using System;
namespace MongoAddress
{
public class Address
{
public string Country;
public string State;
public string Area;
public string Street;
using System;
namespace MongoAddress
{
class PersonFactory
{
public Person CreatePerson()
{
Person person = new Person();
System.Console.WriteLine("Enter The _id of the document");
@AbhinavPradeep
AbhinavPradeep / InitializeDatabase.cs
Last active December 20, 2019 03:03
Initialize a MongoDb Database
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;
}
@AbhinavPradeep
AbhinavPradeep / AddCustomer.cs
Created December 20, 2019 03:13
Adding a person as a customer in a mongodb database
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: ");