public static void loadTrack(string track) { tempStudent temp = new tempStudent(); //Make a connection with DB for Login collection var conString = "mongodb://localhost:27017"; var Client = new MongoClient(conString); var DB = Client.GetDatabase("Path_To_Grad"); var collection = DB.GetCollection <BsonDocument>("Tracks"); var filter = new BsonDocument { { "_id", "BS.CSC.IA" } }; //Search for desired elements List <MongoDB.Bson.BsonDocument> list = collection.Find(filter).ToList(); //Deserealize var holder = list[0]["curriculum"].ToString(); temp = JsonConvert.DeserializeObject <tempStudent>(holder); Student1.courseList = temp.tempCourseList; }
//Function replicates student object as temp object TO send to database public void Replicate_toDB(tempStudent t) { //Create a duplicate of student object //tempStudent temp = new tempStudent(); t.tempID = Student1.ID; t.tempName = Student1.name; t.tempEmail = Student1.email; t.tempInitial_Login = Student1.Initial_Login; t.tempTrack = Student1.track; t.tempAdvisor = Student1.advisor; t.tempCourseList = Student1.courseList; t.tempTakenCourses = Student1.takenCourses; t.tempCurrentSemester = Student1.currentSemester; t.tempNextSemester = Student1.nextSemester; t.GPA = Student1.GPA; t.chCompleted = Student1.chCompleted; t.chRemaining = Student1.chRemaining; t.ranking = Student1.ranking; t.expectedGradutation = Student1.expectedGradutation; //Passed in object should have values now }
public static void Upload() { //Get CSV to convert string path; //Variable will hold path string track = "BS.CSC.IA"; //Find file path = Directory.GetCurrentDirectory(); path = path + @"\Tracks\" + track + ".csv"; tempStudent temp = new tempStudent(); //Load CSV into Student Course List try { // List<Course> values = File.ReadAllLines(path) temp.tempCourses = File.ReadAllLines(path) .Skip(1) .Select(v => Course.FromCsv(v)) .ToList(); } catch (Exception e) { Console.WriteLine("The file could not be read: "); Console.WriteLine(e.Message); } //Save CSV into Mongo DB //Serialize Object (JSON.NET method) string jsonData = JsonConvert.SerializeObject(temp); //Create Bson Document var document = new BsonDocument { { "_id", track }, { "curriculum", jsonData } }; //Insert into MongoDB //Make Connection with database var conString = "mongodb://localhost:27017"; var Client = new MongoClient(conString); var DB = Client.GetDatabase("Path_To_Grad"); var collection = DB.GetCollection <BsonDocument>("Tracks"); //Insert into Database collection.InsertOne(document); //Give confirmation Console.WriteLine("Successfully Inserted {0} into database", track); Console.WriteLine("Press any key to return to menu..."); Console.ReadKey(); Console.Clear(); Program.menu(); }
public static void newUser() { //Create instance of class and assign values tempStudent t = new tempStudent(); t.tempID = Student.ID; t.tempName = Student.name; t.tempTrack = Student.track; t.tempCourses = Student.courseList; t.tempTaken = Student.takenCourses; //Serialize Object (JSON.NET method) string jsonData = JsonConvert.SerializeObject(t); Console.WriteLine("Serialized Student Object:\n {0}", JsonConvert.SerializeObject(t, Formatting.Indented)); //Insert into database //Create Bson Document var document = new BsonDocument { { "_id", t.tempID }, { "profile", jsonData } }; //Make Connection with database var conString = "mongodb://localhost:27017"; var Client = new MongoClient(conString); var DB = Client.GetDatabase("Path_To_Grad"); var collection = DB.GetCollection <BsonDocument>("Student_Profiles"); //Insert into Database collection.InsertOne(document); /* * //Database not working so save to text file!! * string filename = Student.ID.ToString() + ".txt"; * var writer = new StreamWriter(File.OpenWrite(filename)); * writer.WriteLine(jsonData); * writer.Close(); */ //Give Confirmation Console.WriteLine("Profile Successfully saved!"); Console.WriteLine("Press any key to be directed to Student Profile..."); Console.ReadKey(); Console.Clear(); //https://www.c-sharpcorner.com/article/json-serialization-and-deserialization-in-c-sharp/ }
public void restoreProfile() { /***************TESTING PURPOSES****************/ if (Student1.ID == 0) { Student1.ID = 0451917; } //Make Instance of tempStudent Object tempStudent temp = new tempStudent(); //Make Connection with database var conString = "mongodb://localhost:27017"; var Client = new MongoClient(conString); var DB = Client.GetDatabase("Path_To_Grad"); var collection = DB.GetCollection <BsonDocument>("Student_Profiles"); //Query Database var filter = new BsonDocument { { "_id", Student1.ID } }; List <MongoDB.Bson.BsonDocument> list = collection.Find(filter).ToList(); //Deserealize var holder = list[0]["profile"].ToString(); temp = JsonConvert.DeserializeObject <tempStudent>(holder); //Reasign to Student in program //Profile Information Student1.ID = temp.tempID; Student1.name = temp.tempName; Student1.email = temp.tempEmail; Student1.Initial_Login = temp.tempInitial_Login; Student1.track = temp.tempTrack; Student1.advisor = temp.tempAdvisor; //Course Lists Student1.courseList = temp.tempCourseList; Student1.takenCourses = temp.tempTakenCourses; Student1.currentSemester = temp.tempCurrentSemester; Student1.nextSemester = temp.tempNextSemester; //Calculations Student1.GPA = temp.GPA; Student1.chCompleted = temp.chCompleted; Student1.chRemaining = temp.chRemaining; Student1.completedPercentage = temp.completedPercentage; Student1.ranking = temp.ranking; Student1.expectedGradutation = temp.expectedGradutation; }
public void saveInitialDB() { //Decrease number of logins Student1.Initial_Login--; tempStudent temp = new tempStudent(); //Pass temp object to replicate function //db.Replicate_toDB(t); temp.tempID = Student1.ID; temp.tempName = Student1.name; temp.tempEmail = Student1.email; temp.tempInitial_Login = Student1.Initial_Login; temp.tempTrack = Student1.track; temp.tempAdvisor = Student1.advisor; temp.tempCourseList = Student1.courseList; temp.tempTakenCourses = Student1.takenCourses; temp.tempCurrentSemester = Student1.currentSemester; temp.tempNextSemester = Student1.nextSemester; temp.GPA = Student1.GPA; temp.chCompleted = Student1.chCompleted; temp.chRemaining = Student1.chRemaining; temp.completedPercentage = Student1.completedPercentage; temp.ranking = Student1.ranking; temp.expectedGradutation = Student1.expectedGradutation; //Serialize Object (JSON.NET method) string jsonData = JsonConvert.SerializeObject(temp); //Create Bson Document var document = new BsonDocument { { "_id", Student1.ID }, { "profile", jsonData } }; //Make Connection with database var conString = "mongodb://localhost:27017"; var Client = new MongoClient(conString); var DB = Client.GetDatabase("Path_To_Grad"); var collection = DB.GetCollection <BsonDocument>("Student_Profiles"); //Insert into Database collection.InsertOne(document); //Close Window ClientScript.RegisterStartupScript(typeof(Page), "closePage", "window.close();", true); }
public static void loadTrack(string track) { //Make a connection with DB for Login collection var conString = "mongodb://*****:*****@"\Tracks\" + track + ".csv"; * * try * { * * // List<Course> values = File.ReadAllLines(path) * Student.courseList = File.ReadAllLines(path) * .Skip(1) * .Select(v => Course.FromCsv(v)) * .ToList(); * } * * catch (Exception e) * { * Console.WriteLine("The file could not be read: "); * Console.WriteLine(e.Message); * }*/ }
public static void shortcut() { string filename = "337140.txt"; //var reader = new StreamReader(File.OpenRead(filename)); string contents = File.ReadAllText(filename); //Make Instance of tempStudent Object tempStudent temp = new tempStudent(); //Deserealize temp = JsonConvert.DeserializeObject <tempStudent>(contents); //Reasign to Student in program Student.ID = temp.tempID; Student.name = temp.tempName; Student.track = temp.tempTrack; Student.courseList = temp.tempCourses; Student.takenCourses = temp.tempTaken; Console.Clear(); MainPage.welcomePage(); }
public static void restoreSession() { //string filename = Student.ID.ToString() + ".txt"; //var reader = new StreamReader(File.OpenRead(filename)); //string contents = File.ReadAllText(filename); //Make Instance of tempStudent Object tempStudent temp = new tempStudent(); //Make Connection with database var conString = "mongodb://localhost:27017"; var Client = new MongoClient(conString); var DB = Client.GetDatabase("Path_To_Grad"); var collection = DB.GetCollection <BsonDocument>("Student_Profiles"); //Query Database var filter = new BsonDocument { { "_id", Student.ID } }; List <MongoDB.Bson.BsonDocument> list = collection.Find(filter).ToList(); //Deserealize var holder = list[0]["profile"].ToString(); temp = JsonConvert.DeserializeObject <tempStudent>(holder); //Reasign to Student in program Student.ID = temp.tempID; Student.name = temp.tempName; Student.track = temp.tempTrack; Student.courseList = temp.tempCourses; Student.takenCourses = temp.tempTaken; Console.Clear(); }
public static void Update_Profile() { tempStudent temp = new tempStudent(); //Pass temp object to replicate function //db.Replicate_toDB(t); temp.tempID = Student1.ID; temp.tempName = Student1.name; temp.tempEmail = Student1.email; temp.tempInitial_Login = Student1.Initial_Login; temp.tempTrack = Student1.track; temp.tempAdvisor = Student1.advisor; temp.tempCourseList = Student1.courseList; temp.tempTakenCourses = Student1.takenCourses; temp.tempCurrentSemester = Student1.currentSemester; temp.tempNextSemester = Student1.nextSemester; temp.GPA = Student1.GPA; temp.chCompleted = Student1.chCompleted; temp.chRemaining = Student1.chRemaining; temp.completedPercentage = Student1.completedPercentage; temp.ranking = Student1.ranking; temp.expectedGradutation = Student1.expectedGradutation; //Serialize Object (JSON.NET method) string jsonData = JsonConvert.SerializeObject(temp); //Create Bson Document var document = new BsonDocument { { "_id", Student1.ID }, { "profile", jsonData } }; //Make Connection with database var conString = "mongodb://localhost:27017"; var Client = new MongoClient(conString); var DB = Client.GetDatabase("Path_To_Grad"); var collection = DB.GetCollection <BsonDocument>("Student_Profiles"); //Erase original Profile //Create filter to search through DB var filter = new BsonDocument { { "_id", Student1.ID }, }; //Search for desired elements //If specified user found then add to list List <MongoDB.Bson.BsonDocument> list = collection.Find(filter).ToList(); if (list.Count == 1) { //deleting single record var Deleteone = collection.DeleteOneAsync( Builders <BsonDocument> .Filter.Eq("_id", Student1.ID)); } //Reinsert new profile collection.InsertOne(document); }