public static async Task SaveUserCourse(string user_id, UserCourse course) { UserDataCollection user = UserDataCollection.Find(x => x.User_id == user_id).FirstOrDefault(); List <UserCourse> courses = user.PastCourses; courses.Add(course); var update = Builders <UserDataCollection> .Update.Set("PastCourses", courses); UserDataCollection.FindOneAndUpdate(x => x.User_id == user_id, update); }
internal async static Task <UserDataCollection> GetUserDataCollection(string user_id) { //change after upcoming demo UserDataCollection user = UserDataCollection.Find(x => x.User_id == user_id).FirstAsync().Result; //UserDataCollection user = UserDataCollection.Find(x => x.User_id == user_id && x.Name == user_name.ToLower()).FirstAsync().Result; //if (user == null) //{ // await SaveNewUser(user_id); // user = UserDataCollection.Find(x => x.User_id == user_id).FirstAsync().Result; //} return(user); }
public static async Task SaveNewUser(string user_id, UserDataCollection user) { /* Saves a new user to the database who has accepted the privacy policy * Name and Skype ID are saved and the other fields are populated with default values * Preferences app is used to update these other values */ await UserDataCollection.InsertOneAsync(new UserDataCollection { Name = user.Name, gender = user.gender, Notification = 7, PreferedLang = "English", PreferedSub = new List <string>(), PastCourses = new List <UserCourse>(), User_id = user_id, interests = new List <string>(), consent = true, consent_time = (Int32)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds, expiry_time = (Int32)DateTime.UtcNow.AddDays(365).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, privacy_policy_version = 1, consent_text = "I have read and accept the privacy policy", }); }