Ejemplo n.º 1
0
        public async Task <bool> UploadBatchStandardListItemAsync([FromForm] IFormFile file, [FromRoute] Guid standardListId)
        {
            var standardListItems = new List <StandardListItem>();

            if (file.Length > 0)
            {
                var csvUtils  = new CsvUtils();
                var wordItems = csvUtils.ReadWordItemCsv(file);
                foreach (var wordItem in wordItems)
                {
                    var standardListItem = new StandardListItem
                    {
                        Sentence         = wordItem.Sentence,
                        Word             = wordItem.Word,
                        SentenceLanguage = wordItem.SentenceLanguage,
                        WordLanguage     = wordItem.WordLanguage
                    };

                    System.Threading.Thread.Sleep(1000);
                    standardListItem.SpokenWordAsMp3 = GetGoogleSpeech(wordItem.Word, wordItem.WordLanguage);
                    System.Threading.Thread.Sleep(1000);
                    standardListItem.SpokenSentenceAsMp3 = GetGoogleSpeech(wordItem.Sentence, wordItem.SentenceLanguage);


                    standardListItems.Add(standardListItem);
                }

                var worked = await _standardListRepository.ReplaceStandardListItemsAsync(standardListId, standardListItems);
            }
            return(true);
        }
        public async Task <ActionResult <SimpleUpsertDto> > AddStandardListItemAsync([FromBody] StandardListItemDto dto)
        {
            var domainObject = new StandardListItem();

            StandardListItemDto.From(dto, domainObject);
            domainObject.SpokenSentenceAsMp3 = this.GetGoogleSpeech(domainObject.Sentence, domainObject.SentenceLanguage);
            domainObject.SpokenWordAsMp3     = this.GetGoogleSpeech(domainObject.Word, domainObject.WordLanguage);
            domainObject = await _standardListItemRepository.AddAsync(domainObject, this.AppUserId.Value);

            return(SimpleUpsertDto.From(domainObject));
        }
Ejemplo n.º 3
0
 public static void From(StandardListItemDto dto, StandardListItem domainObject)
 {
     domainObject.Id               = dto.Id;
     domainObject.StandardListId   = dto.StandardListId;
     domainObject.SentenceLanguage = dto.SentenceLanguage;
     domainObject.WordLanguage     = dto.WordLanguage;
     domainObject.Word             = dto.Word;
     domainObject.Sentence         = dto.Sentence;
     domainObject.WordLanguage     = dto.WordLanguage;
     domainObject.SentenceLanguage = dto.SentenceLanguage;
 }
Ejemplo n.º 4
0
        public static StandardListItemDto FromNoSound(StandardListItem domainObject)
        {
            var dto = new StandardListItemDto();

            dto.StandardListId   = domainObject.StandardListId;
            dto.Id               = domainObject.Id;
            dto.Word             = domainObject.Word;
            dto.Sentence         = domainObject.Sentence;
            dto.WordLanguage     = domainObject.WordLanguage;
            dto.SentenceLanguage = domainObject.SentenceLanguage;
            return(dto);
        }
Ejemplo n.º 5
0
        public async Task <bool> UploadBatchWordsAsync([FromForm] IFormFile file, [FromRoute] Guid standardListId)
        {
            var standardListItems = new List <StandardListItem>();

            if (file.Length > 0)
            {
                var csvUtils = new CsvUtils();
                var words    = csvUtils.ReadWordOnlyCsv(file);
                foreach (var word in words)
                {
                    var standardListItem = new StandardListItem
                    {
                        Word             = word.Word,
                        SentenceLanguage = "en-GB",
                        WordLanguage     = "en-GB"
                    };

                    try
                    {
                        var defintion = await _oxfordDictionaryService.GetDefinitionAsync(standardListItem.Word);

                        standardListItem.Sentence = defintion
                                                    .results.FirstOrDefault()?
                                                    .lexicalEntries.FirstOrDefault()?
                                                    .entries.FirstOrDefault()?
                                                    .senses.FirstOrDefault()?
                                                    .shortDefinitions.FirstOrDefault();
                    }
                    catch (Exception ex)
                    {
                        standardListItem.Sentence = $"No entry found for {standardListItem.Word}";
                    }


                    System.Threading.Thread.Sleep(1000);
                    standardListItem.SpokenWordAsMp3 = GetGoogleSpeech(standardListItem.Word, standardListItem.WordLanguage);
                    System.Threading.Thread.Sleep(1000);
                    standardListItem.SpokenSentenceAsMp3 = GetGoogleSpeech(standardListItem.Sentence, standardListItem.SentenceLanguage);


                    standardListItems.Add(standardListItem);
                }

                var worked = await _standardListRepository.ReplaceStandardListItemsAsync(standardListId, standardListItems);
            }
            return(true);
        }