protected override Clue MakeClueImpl(User input, Guid accountId) { if (input == null) { throw new ArgumentNullException(nameof(input)); } // TODO: Create clue specifying the type of entity it is and ID var clue = this._factory.Create(EntityType.Person, input.id.ToString(), accountId); // TODO: Populate clue data var data = clue.Data.EntityData; var vocab = new UserVocabulary(); data.Properties[vocab.Id] = input.id.PrintIfAvailable(); data.Name = input.name.PrintIfAvailable(); data.Properties[vocab.Name] = input.name.PrintIfAvailable(); data.Properties[vocab.Email] = input.email; data.Properties[vocab.Username] = input.username; clue.ValidationRuleSuppressions.AddRange(new[] { RuleConstants.DATA_001_File_MustBeIndexed, RuleConstants.METADATA_002_Uri_MustBeSet, RuleConstants.METADATA_003_Author_Name_MustBeSet, RuleConstants.PROPERTIES_002_Unknown_VocabularyKey_Used }); return(clue); }
public void SaveSubtitleNewWords(IList <SubtitleWord> newWords, string subtitleName) { BeginTran(); var q = Session.CreateSQLQuery("delete from Subtitle_NewWord where SubtitleName='" + subtitleName.Replace("'", "''") + "'"); q.ExecuteUpdate(); foreach (var userNewWord in newWords.Distinct()) { Subtitle_NewWord entity = new Subtitle_NewWord() { Word = userNewWord.Word, SubtitleName = subtitleName, Sentence = userNewWord.SubtitleSentence, WordMean = userNewWord.SelectMean }; Session.SaveOrUpdate(entity); UserVocabulary vocabulary = FindOne <UserVocabulary>(v => v.Word == userNewWord.Word); if (vocabulary == null) { vocabulary = new UserVocabulary(); } vocabulary.Word = userNewWord.Word; vocabulary.Source = "Subtitle"; vocabulary.KnownStatus = KnownStatus.Unknown; Session.SaveOrUpdate(vocabulary); } Commit(); }
public void SaveUserVocabulary(IList <Vocabulary> userWords, string source) { var allUserVocabulary = GetAllUserVocabulary(); BeginTran(); foreach (var word in userWords) { var dbWord = allUserVocabulary.SingleOrDefault(v => v.Word == word.Word); if (dbWord != null) { dbWord.KnownStatus = word.IsKnown ? KnownStatus.Known : KnownStatus.Unknown; dbWord.Source = source; SaveUserVocabulary(dbWord); } else { UserVocabulary uv = new UserVocabulary() { Word = word.Word, Source = source, KnownStatus = word.IsKnown ? KnownStatus.Known : KnownStatus.Unknown }; allUserVocabulary.Add(uv); SaveUserVocabulary(uv); } } Commit(); }
//public void SaveUserKnownWords(IList<string> words) //{ // BeginTran(); // foreach (var w in words) // { // Subtitle_KnownWord word = new Subtitle_KnownWord() {AddTime = DateTime.Now, Word = w}; // context.KnownWords.Add(word); // UserVocabulary vocabulary = context.UserVocabulary.SingleOrDefault(v => v.Word == w); // if (vocabulary == null) // { // vocabulary = new UserVocabulary(); // } // vocabulary.Word = w; // vocabulary.Source = "Subtitle"; // vocabulary.KnownStatus = KnownStatus.Known; // context.UserVocabulary.AddOrUpdate(vocabulary); // context.SaveChanges(); // } // Commit(); //} //public UserVocabulary GetUserVocabulary(string word) //{ // return FindFirst<UserVocabulary>(v => v.Word == word); //} public void SaveSubtitleNewWords(IList <SubtitleWord> newWords, string subtitleName) { BeginTran(); RunSql("delete from Subtitle_NewWord where SubtitleName='" + subtitleName.Replace("'", "''") + "'"); foreach (var userNewWord in newWords.Distinct()) { Subtitle_NewWord entity = new Subtitle_NewWord() { Word = userNewWord.Word, SubtitleName = subtitleName, Sentence = userNewWord.SubtitleSentence, WordMean = userNewWord.SelectMean, CreateTime = DateTime.Now, KnownStatus = userNewWord.IsNewWord?KnownStatus.Unknown : KnownStatus.Known }; context.NewWords.Add(entity); UserVocabulary vocabulary = context.UserVocabulary.SingleOrDefault(v => v.Word == userNewWord.Word); if (vocabulary == null) { vocabulary = new UserVocabulary(); vocabulary.CreateTime = DateTime.Now; } vocabulary.Word = userNewWord.Word; vocabulary.Source = "字幕"; vocabulary.Sentence = userNewWord.SubtitleSentence; vocabulary.KnownStatus = userNewWord.IsNewWord ? KnownStatus.Unknown : KnownStatus.Known; vocabulary.UpdateTime = DateTime.Now; context.UserVocabulary.AddOrUpdate(vocabulary); context.SaveChanges(); } Commit(); }
public void Create(User model) { var vocabulary = new Vocabulary { IsPrivate = true, LevelId = 0, Name = "Personal: " + model.Login }; _unitOfWork.VocabularyRepository.Create(vocabulary); _unitOfWork.Commit(); var vocabularyWithId = _unitOfWork.VocabularyRepository.Get(x => x.Name == vocabulary.Name); if (vocabularyWithId == null) { return; } _unitOfWork.UserRepository.Create(model); _unitOfWork.Commit(); var user = _unitOfWork.UserRepository.Get(x => x.Login == model.Login); if (user == null) { return; } var connect = new UserVocabulary { UserId = user.Id, VocabularyId = vocabularyWithId.Id }; _unitOfWork.UserVocabularyRepository.Create(connect); _unitOfWork.Commit(); }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { string word = null; if (e.RowIndex >= 0) { word = dataGridView1.Rows[e.RowIndex].Cells["Word"].Value.ToString(); } if (e.ColumnIndex == 0) { dbOperator.AddIgnoreWord(word); dataGridView1.Rows.RemoveAt(e.RowIndex); } if (e.ColumnIndex == 1) //已经记住该单词 { string sentence = dataGridView1.Rows[e.RowIndex].Cells["SubtitleSentence"].Value.ToString(); //var subtitleName = Path.GetFileNameWithoutExtension(SubtitleFileName); var userVo = dbOperator.GetUserWord(word); if (userVo == null) { userVo = new UserVocabulary() { Word = word, Sentence = sentence, Source = this.SubtitleFileName, CreateTime = DateTime.Now }; } userVo.KnownStatus = KnownStatus.Known; userVo.UpdateTime = DateTime.Now; dbOperator.SaveUserVocabulary(userVo); dataGridView1.Rows.RemoveAt(e.RowIndex); } else if (e.ColumnIndex == 2) //IsStar { var star = dataGridView1.Rows[e.RowIndex].Cells["IsStar"].Value; if (star == "☆") { dataGridView1.Rows[e.RowIndex].Cells[2].Value = "★"; dbOperator.UpdateStarFlag(word, true); } else if (star == "★") { dataGridView1.Rows[e.RowIndex].Cells[2].Value = "☆"; dbOperator.UpdateStarFlag(word, false); } } }
//user favorite list public async Task <IActionResult> FavoriteVocabulary([FromRoute] int id) { ApplicationUser user = await GetCurrentUserAsync(); UserVocabulary newUV = new UserVocabulary() { UserId = user.Id, VocabularyId = id }; _context.Add(newUV); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public VUserWord(UserVocabulary v) { Word = v.Word; CreateTime = v.CreateTime; UpdateTime = v.UpdateTime; var m = Global.DictionaryService.GetChineseMeanInDict(v.Word); if (m != null) { Meaning = m.GetAllMeans(); PhoneticSymbols = m.PhoneticSymbols; } Source = v.Source; Sentence = v.Sentence; IsNewWord = v.KnownStatus == KnownStatus.Unknown ? "是" : "否"; IsStar = v.IsStar ? "★" : "☆"; }
protected override Clue MakeClueImpl([NotNull] Users input, Guid accountId) { if (input == null) { throw new ArgumentNullException(nameof(input)); } var clue = _factory.Create(EntityType.Infrastructure.User, input.Id.ToString(), accountId); var data = clue.Data.EntityData; if (!string.IsNullOrWhiteSpace(input.FirstName) && !string.IsNullOrWhiteSpace(input.LastName)) { data.Name = input.FirstName + ' ' + input.LastName; } if (!string.IsNullOrEmpty(input.CreatedAt)) { if (DateTimeOffset.TryParse(input.CreatedAt, out var createdDate)) { data.CreatedDate = createdDate; } } var vocab = new UserVocabulary(); if (!data.OutgoingEdges.Any()) { _factory.CreateEntityRootReference(clue, EntityEdgeType.PartOf); } data.Properties[vocab.Id] = input.Id.PrintIfAvailable(); data.Properties[vocab.FirstName] = input.FirstName.PrintIfAvailable(); data.Properties[vocab.LastName] = input.LastName.PrintIfAvailable(); data.Properties[vocab.JobTitle] = input.JobTitle.PrintIfAvailable(); data.Properties[vocab.Age] = input.Age.PrintIfAvailable(); data.Properties[vocab.Email] = input.Email.PrintIfAvailable(); data.Properties[vocab.Gender] = input.Gender.PrintIfAvailable(); data.Properties[vocab.CreatedAt] = input.CreatedAt.PrintIfAvailable(); return(clue); }
public void ConnectUserWithDictionary(int userId, int vocabularyId) { var user = _unitOfWork.UserRepository.Get(userId); if (user == null) { return; } var vocabulary = _unitOfWork.VocabularyRepository.Get(vocabularyId); if (vocabulary == null) { return; } var userVocabulary = _unitOfWork.UserVocabularyRepository.Get(x => x.UserId == userId && x.VocabularyId == vocabularyId); if (userVocabulary != null) { return; } var model = new UserVocabulary { UserId = userId, VocabularyId = vocabularyId }; _unitOfWork.UserVocabularyRepository.Create(model); _unitOfWork.Commit(); var words = _wordService.GetByVocabulary(userId, vocabularyId); foreach (var word in words) { _wordService.AddToUser(userId, word.Id); } }
protected override Clue MakeClueImpl([NotNull] User input, Guid accountId) { if (input == null) { throw new ArgumentNullException(nameof(input)); } var clue = _factory.Create(EntityType.Infrastructure.User, input.Id.ToString(), accountId); var data = clue.Data.EntityData; if (!string.IsNullOrWhiteSpace(input.Name)) { data.Name = input.Name.ToString(); } var vocab = new UserVocabulary(); data.Properties[vocab.Active] = input.Active.PrintIfAvailable(); data.Properties[vocab.Admin] = input.Admin.PrintIfAvailable(); data.Properties[vocab.Email] = input.Email.PrintIfAvailable(); if (!string.IsNullOrWhiteSpace(input.Email)) { data.Codes.Add(new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn, input.Email)); } data.Properties[vocab.Id] = input.Id.PrintIfAvailable(); data.Properties[vocab.Locale] = input.Locale.PrintIfAvailable(); data.Properties[vocab.Name] = input.Name.PrintIfAvailable(); data.Properties[vocab.Phone] = input.Phone.PrintIfAvailable(); if (!data.OutgoingEdges.Any()) { _factory.CreateEntityRootReference(clue, EntityEdgeType.PartOf); } return(clue); }
public void SaveUserKnownWords(IList <string> words) { BeginTran(); foreach (var w in words) { Subtitle_KnownWord word = new Subtitle_KnownWord() { AddTime = DateTime.Now, Word = w }; Session.SaveOrUpdate(word); UserVocabulary vocabulary = FindOne <UserVocabulary>(v => v.Word == w); if (vocabulary == null) { vocabulary = new UserVocabulary(); } vocabulary.Word = w; vocabulary.Source = "Subtitle"; vocabulary.KnownStatus = KnownStatus.Known; Session.SaveOrUpdate(vocabulary); } Commit(); }
public void SaveUserVocabulary(UserVocabulary userVocabulary) { context.UserVocabulary.AddOrUpdate(userVocabulary); context.SaveChanges(); }
protected override Clue MakeClueImpl([NotNull] User input, Guid accountId) { if (input == null) { throw new ArgumentNullException(nameof(input)); } // TODO: Create clue specifying the type of entity it is and ID var clue = _factory.Create(EntityType.Infrastructure.User, input.id.ToString(), accountId); clue.ValidationRuleSupressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet); clue.ValidationRuleSupressions.Add(Constants.Validation.Rules.METADATA_003_Author_Name_MustBeSet); // TODO: Populate clue data var data = clue.Data.EntityData; if ((!string.IsNullOrEmpty(input.first_name)) && (!string.IsNullOrEmpty(input.last_name))) { data.Name = string.Format("{0} {1}", input.first_name, input.last_name); } data.Uri = new Uri("https://harvestapp.com/users/"); data.CreatedDate = new DateTimeOffset(input.created_at); data.ModifiedDate = new DateTimeOffset(input.updated_at); var vocab = new UserVocabulary(); data.Properties[vocab.CanCreateInvoices] = input.can_create_invoices.PrintIfAvailable(); data.Properties[vocab.CostRate] = input.cost_rate.PrintIfAvailable(); data.Properties[vocab.DefaultHourlyRate] = input.default_hourly_rate.PrintIfAvailable(); data.Properties[vocab.Email] = input.email.PrintIfAvailable(); data.Properties[vocab.IsActive] = input.is_active.PrintIfAvailable(); data.Properties[vocab.IsContractor] = input.is_contractor.PrintIfAvailable(); data.Properties[vocab.IsProjectManager] = input.is_project_manager.PrintIfAvailable(); data.Properties[vocab.PhoneNumber] = input.telephone.PrintIfAvailable(); if (input.roles.Count > 0) { var tmp = ""; foreach (var r in input.roles) { tmp += r + ", "; } tmp = tmp.Substring(0, tmp.Length - 2); data.Properties[vocab.Roles] = tmp.PrintIfAvailable(); } data.Properties[vocab.WeeklyCapacity] = input.weekly_capacity.PrintIfAvailable(); bool hasConnection = false; if (input.expense_ids != null) { foreach (var expId in input.expense_ids) { _factory.CreateOutgoingEntityReference(clue, EntityType.Form, EntityEdgeType.Created, expId.ToString()); hasConnection = true; } } if (input.time_entry_ids != null) { foreach (var timEtrId in input.time_entry_ids) { _factory.CreateOutgoingEntityReference(clue, EntityType.Form, EntityEdgeType.Created, timEtrId.ToString(), timEtrId.ToString()); hasConnection = true; } } if (!hasConnection) { _factory.CreateEntityRootReference(clue, EntityEdgeType.Parent); } return(clue); }