Created
November 1, 2013 21:34
-
-
Save TimonVS/7272321 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.Bson; | |
using MongoDB.Driver; | |
using MongoDB.Driver.Builders; | |
using System; | |
using System.Collections.Generic; | |
using System.Configuration; | |
using System.Data.Entity; | |
using System.Linq; | |
using System.Web; | |
namespace PRJ56.Models | |
{ | |
public class Profiles | |
{ | |
public ObjectId _id { get; set; } | |
public string profile_id { get; set; } | |
public string location { get; set; } | |
public string sector { get; set; } | |
public BsonArray education { get; set; } | |
public string overview_html { get; set; } | |
public BsonArray experience { get; set; } | |
public string url { get; set; } | |
public BsonDocument groups { get; set; } | |
public BsonArray skills { get; set; } | |
public string picture { get; set; } | |
public string summary { get; set; } | |
public BsonArray courses { get; set; } | |
public string specialities { get; set; } | |
public BsonArray languages { get; set; } | |
public string interests { get; set; } | |
public BsonArray honors { get; set; } | |
public BsonDocument name { get; set; } | |
} | |
public class MongoDBEntities : DbContext | |
{ | |
public MongoDBEntities() : base("name=MongoConnection") { } | |
static MongoServer server = MongoServer.Create(ConfigurationManager.ConnectionStrings["MongoConnection"].ConnectionString.ToString()); | |
MongoDatabase database = server.GetDatabase("linkedin_crawl"); | |
List<Profiles> profiles; | |
public List<Profiles> Profiles | |
{ | |
get | |
{ | |
var collection = database.GetCollection<Profiles>("profiles_copy"); | |
return collection.FindAllAs<Profiles>().ToList(); | |
} | |
set { profiles = value; } | |
} | |
public void CreateProfile(Profiles collection) | |
{ | |
try | |
{ | |
string Id = "test"; | |
MongoCollection<Profiles> MCollection = database.GetCollection<Profiles>("profiles_copy"); | |
BsonDocument doc = new BsonDocument { | |
{"profile_id",Id}, | |
{"location",collection.location} | |
}; | |
IMongoQuery query = Query.EQ("DepartmentName", collection.location); | |
var exists = MCollection.Find(query); | |
if (exists.ToList().Count == 0) | |
MCollection.Insert(doc); | |
} | |
catch { } | |
} | |
public void EditProfile(Profiles collection) | |
{ | |
try | |
{ | |
MongoCollection<Profiles> MCollection = database.GetCollection<Profiles>("profiles_copy"); | |
IMongoQuery query = Query.EQ("profile_id", collection.profile_id); | |
IMongoUpdate update = MongoDB.Driver.Builders.Update.Set("location", collection.location); | |
MCollection.Update(query, update); | |
} | |
catch { } | |
} | |
public void DeleteDepartment(Profiles collection) | |
{ | |
try | |
{ | |
MongoCollection<Profiles> MCollection = database.GetCollection<Profiles>("profiles_copy"); | |
IMongoQuery query = Query.EQ("_id", collection._id); | |
MCollection.Remove(query); | |
} | |
catch { } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment