Created
February 10, 2020 11:16
-
-
Save AbhinavPradeep/4f58d4f5dc6980bc7601be15cef55386 to your computer and use it in GitHub Desktop.
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 MongoDB.Driver; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Theta.Customers.Models; | |
namespace Theta.Customers.Repository | |
{ | |
public class CustomerRepos | |
{ | |
private string ConnectionString { get; set; } | |
public CustomerRepos(string ConnectionString) | |
{ | |
this.ConnectionString = ConnectionString; | |
} | |
private IMongoCollection<Customer> Initialize() | |
{ | |
var client = new MongoClient(ConnectionString); | |
var database = client.GetDatabase("CustomersDB"); | |
var collection = database.GetCollection<Customer>("Customers"); | |
return collection; | |
} | |
public List<Customer> GetCustomer(int customerID) | |
{ | |
IMongoCollection<Customer> collection = Initialize(); | |
var Dbcustomer = collection.Find<Customer>(x => x._id == customerID); | |
return Dbcustomer.ToList(); | |
} | |
public List<Customer> GetAllCustomers() | |
{ | |
IMongoCollection<Customer> collection = Initialize(); | |
var Dbcustomer = collection.Find(x => true); | |
return Dbcustomer.ToList(); | |
} | |
public long DeleteCustomer(int customerID) | |
{ | |
IMongoCollection<Customer> collection = Initialize(); | |
var result = collection.DeleteOne<Customer>(x => x._id == customerID); | |
return result.DeletedCount; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment