/// <summary> /// This function adds a word to the currently active User's dictionary. /// accepts the word, weight, & user id to attach word to correct user. /// </summary> /// <param name="word">Word to be added to the dictionary.</param> /// <param name="value">Weight of the word being added to the dictionary</param> /// <param name="user_id">ID of the current user to add to correct dictionary</param> /// <returns>Returns true if word was successfully added</returns> public bool addwordDictionary(string word, int value, int user_id) { bool success = false; using (var db = new stock_advisorDataContext(Program.ConnectionString)) { DICTIONARY search = (from p in db.DICTIONARies where p.User_id == user_id && p.Word == word select p).FirstOrDefault(); if (search == null) //record doesn't exist { //create user_info object w/params var newEntry = new DICTIONARY() { User_id = user_id, Word = word, Weight = value }; db.DICTIONARies.InsertOnSubmit(newEntry); try { db.SubmitChanges(); //execute insert //verify that was successfully inserted var added = db.DICTIONARies.SingleOrDefault(a => a.Word == word && a.User_id == user_id); if (added != null) { success = true; } } catch (Exception e) { Console.WriteLine("Exception caught during word creation/insert:\n"); Console.WriteLine(e.Message); } } else //record exists already { success = false; } } return(success); }
/// <summary> /// This function removes a word from the currently active User's dictionary. /// accepts the word & user id to remove word from the correct user. /// </summary> /// <param name="wordToDelete">Word to be added to the dictionary.</param> /// <param name="user_id">ID of the current user to remove word from correct dictionary</param> /// <returns>Returns true if word was successfully removed</returns> public bool deleteWordDictionary(string wordToDelete, int user_id) { bool deleted = false; using (var db = new stock_advisorDataContext(Program.ConnectionString)) { //find word to delete DICTIONARY delWord = (from p in db.DICTIONARies where p.User_id == user_id && p.Word == wordToDelete select p).FirstOrDefault(); if (delWord != null) { db.DICTIONARies.DeleteOnSubmit(delWord); db.SubmitChanges(); deleted = true; } } return(deleted); }
/// <summary> /// This function modifies a word entry in the database, changing the old word's /// weight value to the input weight. /// </summary> /// <param name="word">This is the word to be edited in the dictionary</param> /// <param name="newWeight">This is the new weight of the word being edited</param> /// <param name="user_id">This is the id of the user who's dictionary is being edited</param> /// <returns>true if weight modification was successful</returns> public bool modifyWeightDictionary(string word, int newWeight, int user_id) { bool modified = false; using (var db = new stock_advisorDataContext(Program.ConnectionString)) { DICTIONARY search = (from p in db.DICTIONARies where p.User_id == user_id && p.Word == word select p).FirstOrDefault(); if (search != null) //record does exist { //create user_info object w/params var newEntry = new DICTIONARY() { User_id = user_id, Word = word, Weight = newWeight }; db.DICTIONARies.DeleteOnSubmit(search); //delete old word db.DICTIONARies.InsertOnSubmit(newEntry); try { db.SubmitChanges(); //execute insert //verify that was successfully inserted var added = db.DICTIONARies.SingleOrDefault(a => a.Word == word && a.Weight == newWeight && a.User_id == user_id); if (added != null) { modified = true; } } catch (Exception e) { Console.WriteLine("Exception caught during word update:\n"); Console.WriteLine(e.Message); } } } return(modified); }
private void detach_DICTIONARies(DICTIONARY entity) { this.SendPropertyChanging(); entity.USER_INFO = null; }
partial void DeleteDICTIONARY(DICTIONARY instance);
partial void UpdateDICTIONARY(DICTIONARY instance);
partial void InsertDICTIONARY(DICTIONARY instance);