public async Task <List <VocCardVM> > GetControlVocCardVMs(VocCardVM vocCardVM) { List <VocCardVM> vocCardVMs = new List <VocCardVM>(); List <Voc> Vocs = appDbContext.Vocs.Where(x => x.Id > 100 && x.Id <= 120).ToList(); foreach (var voc in Vocs) { VocCardVM vocCardVM1 = new VocCardVM(); vocCardVM1.Voc = voc; vocCardVM1.VocAudios = await appDbContext.VocAudios.Where(x => x.VocId == voc.Id).ToListAsync(); vocCardVM1.Definitions = await appDbContext.Definitions.Where(x => x.VocId == voc.Id).Include(e => e.Examples).ToListAsync(); vocCardVM1.Images = await appDbContext.Images.Where(x => x.VocId == voc.Id).ToListAsync(); vocCardVM1.Synonyms = await appDbContext.Synonyms.Where(x => x.VocId == voc.Id).ToListAsync(); vocCardVM1.Translates = await appDbContext.Translates.Where(x => x.VocId == voc.Id).ToListAsync(); vocCardVMs.Add(vocCardVM1); //vocCardVMs.Add(new VocCardVM //{ // Voc = voc, // VocAudios = await appDbContext.VocAudios.Where(x => x.VocId == voc.Id).ToListAsync(), // Definitions = await appDbContext.Definitions.Where(x => x.VocId == voc.Id).Include(e => e.Examples).ToListAsync(), // Images = await appDbContext.Images.Where(x => x.VocId == voc.Id).ToListAsync(), // Synonyms = await appDbContext.Synonyms.Where(x => x.VocId == voc.Id).ToListAsync(), // Translates = await appDbContext.Translates.Where(x => x.VocId == voc.Id).ToListAsync() //}); } return(vocCardVMs); }
public async Task <VocCardVM> AddVocCardVM(VocCardVM vocCardVM) { using (var dbContextTransaction = appDbContext.Database.BeginTransaction()) { try { await appDbContext.VocAudios.AddRangeAsync(vocCardVM.VocAudios); await appDbContext.Definitions.AddRangeAsync(vocCardVM.Definitions); await appDbContext.Synonyms.AddRangeAsync(vocCardVM.Synonyms); await appDbContext.Translates.AddRangeAsync(vocCardVM.Translates); await appDbContext.SaveChangesAsync(); dbContextTransaction.Commit(); } catch (Exception ex) { throw; } } //await appDbContext.SaveChangesAsync(); ; return(vocCardVM); }
public async Task CamDifHandlerForDatabase(VocCardVM vocCardVM) { await FillGetHtmlHelper(vocCardVM); await GetAudioUri(); await GetSynonyms(); //await GetTranslation(); await GetFromCambridgeDic(vocCardVM.Voc.Text); //int contentPageStart, contentPageEnd, start, end; string pageContent, txt; using (WebClient client = new WebClient()) pageContent = client.DownloadString($"{GetHtmlHelper[1].Uri}{GetHtmlHelper[1].VocText}"); txt = pageContent; Difs.Clear(); definitions.Clear(); while (pageContent.Contains(GetHtmlHelper[1].Key)) { Dif dif = new Dif(); var x = await GetCambText(pageContent, GetHtmlHelper[1].Key, GetHtmlHelper[1].KeyEnd, GetHtmlHelper[1].SmallKey, GetHtmlHelper[1].SmallKeyEnd); dif.Text = x.Text; //if(string.IsNullOrEmpty(dif.Text)) definitions.Add(new Definition { Text = dif.Text, VocId = Voc.Id}); pageContent = x.PageContent; while (pageContent.Contains(GetHtmlHelper[2].Key) && pageContent.IndexOf(GetHtmlHelper[2].Key) < pageContent.IndexOf(GetHtmlHelper[1].Key)) { var y = await GetCambText(pageContent, GetHtmlHelper[2].Key, GetHtmlHelper[2].KeyEnd, GetHtmlHelper[2].SmallKey, GetHtmlHelper[2].SmallKeyEnd); dif.Examples.Add(y.Text); //if (definitions.Count > 0) definitions[definitions.Count - 1].Examples.Add(new Example { Text = y.Text, VocId = Voc.Id}); pageContent = y.PageContent; } Difs.Add(dif); if (!string.IsNullOrEmpty(dif.Text)) { List <Example> examples = new List <Example>(); foreach (var ex in dif.Examples) { examples.Add(new Example { Text = ex.Trim(), VocId = vocCardVM.Voc.Id }); } definitions.Add(new Definition { Text = dif.Text.Trim(), Examples = examples, VocId = vocCardVM.Voc.Id }); } } }
public async Task <ActionResult <List <VocCardVM> > > GetControlVocCardVMs(VocCardVM vocCardVM) { try { return(await vocRepository.GetControlVocCardVMs(vocCardVM)); } catch (DbUpdateException Ex) { return(StatusCode(StatusCodes.Status500InternalServerError, Ex.InnerException.Message)); } }
public async Task <VocCardVM> AddVocCardVM(VocCardVM vocCardVM) { var response = await httpService.PostAsync($"{url}/AddVocCardVM", vocCardVM); if (response.Success) { vocCardVM = await DeserializeAsync <VocCardVM>(response.HttpResponseMessage, defaultJsonSerializerOptions); } else { vocCardVM.Exception = await response.GetBody(); } return(vocCardVM); }
public async Task <List <VocCardVM> > GetControlVocCardVMs(VocCardVM vocCardVM) { List <VocCardVM> vocCardVMs = new List <VocCardVM>(); var response = await httpService.PostAsync(url + "/GetControlVocCardVMs", vocCardVM); if (response.Success) { vocCardVMs = await Deserialize <List <VocCardVM> >(response.HttpResponseMessage, defaultJsonSerializerOptions); } else { vocCardVMs.Add(new VocCardVM { Exception = await response.GetBody() }); } return(vocCardVMs); }
public async Task <ActionResult <VocCardVM> > AddVocCardVM(VocCardVM vocCardVM) { try { if (vocCardVM == null) { return(BadRequest()); } await uservocRepository.AddVocCardVM(vocCardVM); return(vocCardVM); } catch (DbUpdateException Ex) { return(StatusCode(StatusCodes.Status500InternalServerError, Ex.InnerException.Message)); } }
public async Task FillDataBaseVocCard() { VocCardVM vocCardVM = new VocCardVM(); List <Synonym> synonyms = new List <Synonym>(); List <Translate> translates = new List <Translate>(); foreach (var newVocCard in VocMasterVM.News) { await CamDifHandlerForDatabase(newVocCard); synonyms.Clear(); foreach (var syn in Synonyms) { synonyms.Add(new Synonym { Text = syn, VocId = newVocCard.Voc.Id }); } translates.Clear(); foreach (var tran in Translation) { translates.Add(new Translate { Text = tran, VocId = newVocCard.Voc.Id }); } vocCardVM.Voc = newVocCard.Voc; vocCardVM.VocAudios = new List <VocAudio> { new VocAudio { Uri = GetHtmlHelper[0].Text, Phon = phon, VocId = newVocCard.Voc.Id } }; vocCardVM.Definitions = definitions; vocCardVM.Synonyms = synonyms; vocCardVM.Translates = translates; await UserVocService.AddVocCardVM(vocCardVM); } }
public async Task FillGetHtmlHelper(VocCardVM vocCardVM) { GetHtmlHelper.Clear(); GetHtmlHelper.Add(new GetHtmlHelper() { Id = 0, VocText = vocCardVM.Voc.Text, Uri = "https://www.oxfordlearnersdictionaries.com/definition/english/", Key = "sound audio_play_button pron-us icon-audio\" data-src-mp3=\"", KeyEnd = "data-src-ogg", SmallKey = "class=\"phon\">", SmallKeyEnd = "</span>", SiteName = "Oxford", Target = "Pronouciation" }); GetHtmlHelper.Add(new GetHtmlHelper() { Id = 1, VocText = vocCardVM.Voc.Text, Uri = "https://dictionary.cambridge.org/dictionary/english/", Key = "def ddef_d db\">", KeyEnd = "</div>", SmallKey = ">", SmallKeyEnd = "<", SiteName = "Cambridg", Target = "Difinition" }); GetHtmlHelper.Add(new GetHtmlHelper() { Id = 2, VocText = vocCardVM.Voc.Text, Uri = "https://dictionary.cambridge.org/dictionary/english/", Key = "examp dexamp\">", KeyEnd = "</span></div>", SmallKey = ">", SmallKeyEnd = "<", SiteName = "Cambridg", Target = "Examples" }); GetHtmlHelper.Add(new GetHtmlHelper() { Id = 3, VocText = vocCardVM.Voc.Text, Uri = "https://www.thesaurus.com/browse/", Key = "class=\"css-18rr30y etbu2a31\">", KeyEnd = "</a>", SiteName = "Thesurus", Target = "Synonyms" }); GetHtmlHelper.Add(new GetHtmlHelper() { Id = 4, VocText = vocCardVM.Voc.Text, Uri = "https://dictionary.cambridge.org/dictionary/english-arabic/", Key = "<span class=\"trans dtrans dtrans-se \" lang=\"ar\">", KeyEnd = "</span>", SiteName = "Cambridg", Target = "ArabicTranslation" }); }