public void Remove(int me, int favoriteId) { var db = new OkbDbContext(); var fav = db.Favorites.Find(me, favoriteId); db.Favorites.Remove(fav); db.SaveChanges(); }
public void Save(int me, int favoriteId) { var db = new OkbDbContext(); db.Favorites.Add(new Favorite { ProfileId = me, FavoriteId = favoriteId, FavoriteDate = DateTime.Now }); db.SaveChanges(); }
public void AnsweredQuestionActivity(int who, string quesText, string choiceText) { var db = new OkbDbContext(); db.ActivityFeed.Add(new Activity { Who = who, CategoryId = (int)OkbConstants.ActivityCategories.AnsweredQuestion, Field1 = Truncate(quesText, OkbConstants.FEED_BLURB_SIZE), Field2 = Truncate(choiceText, OkbConstants.FEED_BLURB_SIZE), Timestamp = DateTime.Now }); db.SaveChanges(); }
public void EditProfileTextActivity(int who, string what) { var db = new OkbDbContext(); var act = new Activity { Who = who, CategoryId = (int)OkbConstants.ActivityCategories.EditedProfileText, Field1 = Truncate(what, OkbConstants.FEED_BLURB_SIZE), Timestamp = DateTime.Now }; db.ActivityFeed.Add(act); db.SaveChanges(); }
/// <summary> /// Seed the Activity feed with a bunch of activities. /// Can be Joined, AnsweredQuestion, UploadedPhoto, or EditedProfile /// </summary> public void SeedActivities(int n) { var db = new OkbDbContext(); var rand = new Random(); for (int i = 0; i < n; i++) { db.ActivityFeed.Add(new Activity { Who = (rand.Next() % 1000) + 1, CategoryId = (rand.Next() % 4) + 1, Timestamp = RandomTime(rand), Field1 = "this is some test text for metadata field. lorum ipsum dolor blah blah blah" }); } db.SaveChanges(); }
/// <summary> /// Simulations answering one question to see how fast we can insert answers into the DB. /// Should be called in a loop and given a Random object. /// </summary> public void SimulateAnsweringQuestion(Random rand) { var db = new OkbDbContext(); var ans = new Answer { ProfileId = rand.Next(2, 200000), QuestionId = (short)rand.Next(201, 1243), ChoiceIndex = 1, ChoiceWeight = 1, ChoiceAccept = 1, LastAnswered = DateTime.Now }; try { db.Answers.Add(ans); db.SaveChanges(); } catch (Exception) { throw; } }
public void SeedTranslateQuestions(List<TranslateQuestion> quesList) { var db = new OkbDbContext(); foreach (var q in quesList) { db.TranslateQuestions.Add(q); } var ret = db.SaveChanges(); }
/// <summary> /// Seed the users by creating a OkbUser and Profile for each user. Takes a list of provinces /// and randomizes the location of each user. Uses the UserProfileBulkReader to generate random /// profiles. /// </summary> public void SeedUsers(int numOfUsers, IList<LocationPinyinModel> provinces, int commitCount = 100) { var db = new OkbDbContext(); var profileGen = new ProfileGenerator(provinces); var userManager = new UserManager<OkbUser, string>(new UserStore<OkbUser>(db)); db.Configuration.AutoDetectChangesEnabled = false; for (int i = 1; i < numOfUsers; i++) { var email = "test" + i + "@okboba.com"; var user = new OkbUser { UserName = email, Email = email, PasswordHash = userManager.PasswordHasher.HashPassword("password"), SecurityStamp = Guid.NewGuid().ToString(), JoinDate = DateTime.Now }; var profile = profileGen.Next(); user.Profile = profile; profile.UserId = user.Id; db.Users.Add(user); if (i % commitCount == 0) { db.SaveChanges(); db.Dispose(); db = new OkbDbContext(); db.Configuration.AutoDetectChangesEnabled = false; } } db.SaveChanges(); }
/// <summary> /// Update the database with okboba questions /// </summary> public void SeedOkbQuestions(string filename) { string answerLine; var stream = new StreamReader(filename); var rgx = new Regex("^\\d+\\. (.*)"); var db = new OkbDbContext(); int count = 1; while (!stream.EndOfStream) { var line = stream.ReadLine(); //question var match = rgx.Match(line); var questionText = match.Groups[1].Value; var ques = db.Questions.Find(count); ques.Text = questionText; int index = 1; //delete old choices db.QuestionChoices.RemoveRange(db.QuestionChoices.Where(c => c.QuestionId == count)); //Loop thru answers while ((answerLine = stream.ReadLine()) != "" && !stream.EndOfStream) { db.QuestionChoices.Add(new QuestionChoice { QuestionId = (short)count, Index = (byte)index, Score = 0, Text = answerLine }); index++; } count++; db.SaveChanges(); } //db.SaveChanges(); }
/// <summary> /// Seed the Questions from the given file containg Okc Questions /// </summary> public void SeedOkcQuestions(string filename) { var db = new OkbDbContext(); if (db.Questions.Count() > 0) return; //////////////// Insert Okcupid questions //////////////////// var stream = new StreamReader(filename); int count = 1; while (!stream.EndOfStream) { var line = stream.ReadLine(); int index = 1; string answerLine; //Loop thru answers while ((answerLine = stream.ReadLine()) != "" && !stream.EndOfStream) { db.QuestionChoices.Add(new QuestionChoice { QuestionId = (short)count, Index = (byte)index, Score = 0, Text = answerLine }); index++; } //Add Question db.Questions.Add(new Question { Id = (short)count, Rank = count, Text = line, TraitId = null }); count++; db.SaveChanges(); } }
/// <summary> /// Seed the detail options from the given file /// </summary> public void SeedDetailOptions(string filename) { var sr = new StreamReader(filename); var colName = ""; var details = new List<ProfileDetailOption>(); byte id = 0; var db = new OkbDbContext(); while (!sr.EndOfStream) { var line = sr.ReadLine(); if (line.IndexOf('\t') != -1) { //detail option db.ProfileDetailOptions.Add(new ProfileDetailOption { ColName = colName, Id = id, Value = line.Trim() }); //details.Add(new ProfileDetailOption //{ // ColName = colName, // Id = id, // Value = line.Trim() //}); id++; } else { //new detail colName = line.Split(',')[1].Trim(); id = 1; } } db.SaveChanges(); //Dump it out //foreach (var option in details) //{ // Console.WriteLine("{0}, {1}, {2}", option.Id, option.ColName, option.Value); //} }
/// <summary> /// Seed the Locations from the given file /// </summary> public void SeedLocations(string filename) { OkbDbContext db = new OkbDbContext(); if (db.Locations.Count() > 0) { db.Dispose(); return; } //Read from file using (StreamReader sr = new StreamReader(filename)) { string line; Int16 provinceCount = 1; while ((line = sr.ReadLine()) != null) { var cities = line.Split(' '); //First entry is the province string province = cities[0]; for (Int16 districtCount = 1; districtCount < cities.Length; districtCount++) { string district = cities[districtCount]; var loc = new Location { LocationId1 = provinceCount, LocationId2 = districtCount, LocationName1 = province, LocationName2 = district }; //Update the database db.Locations.Add(loc); db.SaveChanges(); } provinceCount++; } } }
public void EditProfileText(int profileId, string text, string whichQuestion) { var db = new OkbDbContext(); //Check if we are adding or updating var currProfileText = db.ProfileTexts.Find(profileId); if (currProfileText == null) { currProfileText = new ProfileText { ProfileId = profileId }; db.ProfileTexts.Add(currProfileText); } switch (whichQuestion) { case "q1": currProfileText.Question1 = text; break; case "q2": currProfileText.Question2 = text; break; case "q3": currProfileText.Question3 = text; break; case "q4": currProfileText.Question4 = text; break; case "q5": currProfileText.Question5 = text; break; default: throw new Exception("Invalid profile text id"); } db.SaveChanges(); }
public void EditDetails(ProfileDetail details, OkbConstants.ProfileDetailSections section, int profileId) { var db = new OkbDbContext(); //check if we're updating or adding var currDetails = db.ProfileDetails.Find(profileId); if (currDetails==null) { //adding new Profile Detail row details.ProfileId = profileId; db.ProfileDetails.Add(details); db.SaveChanges(); return; } //otherwise we're updating //db.ProfileDetails.Attach(details); //db.Entry(details).State = System.Data.Entity.EntityState.Modified; switch (section) { case OkbConstants.ProfileDetailSections.Basic: currDetails.LookingFor = details.LookingFor; currDetails.Height = details.Height; currDetails.Education = details.Education; currDetails.RelationshipStatus = details.RelationshipStatus; currDetails.HaveChildren = details.HaveChildren; currDetails.WantChildren = details.WantChildren; currDetails.Nationality = details.Nationality; currDetails.MonthlyIncome = details.MonthlyIncome; currDetails.LivingSituation = details.LivingSituation; currDetails.CarSituation = details.CarSituation; currDetails.EconomicConcept = details.EconomicConcept; //db.Entry(details).Property(col => col.LookingFor).IsModified = true; //db.Entry(details).Property(col => col.Height).IsModified = true; //db.Entry(details).Property(col => col.Education).IsModified = true; //db.Entry(details).Property(col => col.RelationshipStatus).IsModified = true; //db.Entry(details).Property(col => col.HaveChildren).IsModified = true; //db.Entry(details).Property(col => col.WantChildren).IsModified = true; //db.Entry(details).Property(col => col.Nationality).IsModified = true; //db.Entry(details).Property(col => col.MonthlyIncome).IsModified = true; //db.Entry(details).Property(col => col.LivingSituation).IsModified = true; //db.Entry(details).Property(col => col.CarSituation).IsModified = true; //db.Entry(details).Property(col => col.EconomicConcept).IsModified = true; break; case OkbConstants.ProfileDetailSections.Lifestyle: currDetails.Smoke = details.Smoke; currDetails.Drink = details.Drink; currDetails.Exercise = details.Exercise; currDetails.Eating = details.Eating; currDetails.Shopping = details.Shopping; currDetails.Religion = details.Religion; currDetails.SleepSchedule = details.SleepSchedule; currDetails.SocialCircle = details.SocialCircle; currDetails.MostMoney = details.MostMoney; currDetails.Housework = details.Housework; currDetails.LovePets = details.LovePets; currDetails.HavePets = details.HavePets; break; case OkbConstants.ProfileDetailSections.Job: currDetails.Job = details.Job; currDetails.Industry = details.Industry; currDetails.WorkHours = details.WorkHours; currDetails.CareerAndFamily = details.CareerAndFamily; break; case OkbConstants.ProfileDetailSections.Appearance: currDetails.BodyType = details.BodyType; currDetails.FaceType = details.FaceType; currDetails.EyeColor = details.EyeColor; currDetails.EyeShape = details.EyeShape; currDetails.HairColor = details.HairColor; currDetails.HairLength = details.HairLength; currDetails.HairType = details.HairType; currDetails.SkinType = details.SkinType; currDetails.Muscle = details.Muscle; currDetails.HealthCondition = details.HealthCondition; currDetails.DressStyle = details.DressStyle; break; case OkbConstants.ProfileDetailSections.Personality: currDetails.Sociability = details.Sociability; currDetails.Humour = details.Humour; currDetails.Temper = details.Temper; currDetails.Feelings = details.Feelings; break; default: //invalid section. fail silently? break; } db.SaveChanges(); }
public void UploadPhotoActivity(int who, string what) { var db = new OkbDbContext(); db.ActivityFeed.Add(new Activity { Who = who, CategoryId = (int)OkbConstants.ActivityCategories.UploadedPhoto, Field1 = what, Timestamp = DateTime.Now }); db.SaveChanges(); }
public void JoinedActivity(int who) { var db = new OkbDbContext(); db.ActivityFeed.Add(new Activity { Who = who, CategoryId = (int)OkbConstants.ActivityCategories.Joined, Field1 = "", Timestamp = DateTime.Now }); db.SaveChanges(); }
/// <summary> /// Marks a conversation as read. If the message was unread previoulsy then we /// decrement the unread count in the cache /// </summary> public void MarkAsRead(int profileId, int convId) { var db = new OkbDbContext(); var map = db.ConversationMap.Find(profileId, convId); //Error check - make sure we're marking an existing conversation if (map != null) { //Decrement count and mark only if message was previously unread if (!map.HasBeenRead) { DecrementUnreadCount(profileId); map.HasBeenRead = true; db.SaveChanges(); } } }