Example #1
0
        public async Task <List <Vid> > GetVids(VocVM vocVM)
        {
            List <VocSubtitle> vocSubtitles = new List <VocSubtitle>();
            List <Vid>         vids         = new List <Vid>();

            vocVM.Voc = appDbContext.Vocs.FirstOrDefault(x => x.Text == vocVM.Voc.Text);
            if (vocVM.Voc != null)
            {
                vocSubtitles = await appDbContext.VocsSubtitless.Where(x => x.VocId == vocVM.Voc.Id).Include(x => x.Subtitle).ThenInclude(x => x.Movie).ThenInclude(x => x.Subtitles).ToListAsync();

                foreach (var vocSubtitle in vocSubtitles)
                {
                    vids.Add(new Vid
                    {
                        YouTubeId = vocSubtitle.Subtitle.Movie.MovieId,
                        Subs      = vocSubtitle.Subtitle.Movie.Subtitles.Select(x => new Sub {
                            StartTime = x.StartTime, EndTime = x.EndtTime, Text = x.Text
                        }).ToList(),
                        StartTime = vocSubtitle.Subtitle.StartTime
                    });
                }
            }

            return(vids);
        }
Example #2
0
        public async Task <ActionResult <VocVM> > CreateVoc(VocVM vocVM)
        {
            try
            {
                if (vocVM == null)
                {
                    return(BadRequest());
                }

                // Add custom model validation error
                Voc voc = await vocRepository.GetVocByname(vocVM.Voc);

                if (voc != null)
                {
                    ModelState.AddModelError("Name", $"Voc name: {vocVM.Voc.Text} already in use");
                    return(BadRequest(ModelState));
                }

                await vocRepository.CreateVoc(vocVM);

                return(CreatedAtAction(nameof(GetVoc),
                                       new { id = vocVM.Voc.Id }, vocVM));
            }
            catch (DbUpdateException Ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  Ex.InnerException.Message));
            }
        }
Example #3
0
        public async Task <VocVM> GetVoc(int id)
        {
            VocVM vocVM = new VocVM();

            vocVM.Voc = await appDbContext.Vocs.FirstOrDefaultAsync(e => e.Id == id);

            return(vocVM);
        }
Example #4
0
        public async Task <VocVM> CreateVoc(VocVM vocVM)
        {
            var result = await appDbContext.Vocs.AddAsync(vocVM.Voc);

            await appDbContext.SaveChangesAsync();

            vocVM.Voc = result.Entity;
            return(vocVM);
        }
        public static void EditClick(VocVM voc, VocWpfItem wpf_item, StackPanel item_line)
        {
            var edited = new VocVM(voc.Id,
                                   wpf_item.Words.Text,
                                   wpf_item.Answer.Text,
                                   wpf_item.Def.Text,
                                   wpf_item.Ptbr.Text,
                                   (Importance)(wpf_item.Imp).SelectedValue,
                                   wpf_item.IsActive.IsActived);

            EditQuestion(voc, edited, item_line);
        }
Example #6
0
        protected static bool RemoveVocabulary(VocVM Voc)
        {
            string query = string.Format(RemoveSQL, Model.Voc.ToDesc(), Voc.Id);

            if (!SendQuery(query))
            {
                return(false);
            }

            Vocabularies.Remove(Voc);

            return(true);
        }
Example #7
0
        public async Task <List <Image> > GetImages(VocVM vocVM)
        {
            List <Image> images = new List <Image>();

            vocVM.Voc = await appDbContext.Vocs.FirstOrDefaultAsync(x => x.Text == vocVM.Voc.Text);

            if (vocVM.Voc != null)
            {
                images = await appDbContext.Images.Where(x => x.VocId == vocVM.Voc.Id).ToListAsync();
            }

            return(images);
        }
Example #8
0
        public async Task <VocVM> GetVocVMByText(VocVM vocVM)
        {
            var response = await httpService.PostAsync($"{url}/GetVocVMByText", vocVM);

            if (response.Success)
            {
                vocVM = await DeserializeAsync <VocVM>(response.HttpResponseMessage, defaultJsonSerializerOptions);
            }
            else
            {
                vocVM.Exception = response.HttpResponseMessage.Content.ToString();
            }

            return(vocVM);
        }
Example #9
0
        private async Task <VocVM> CheckDeserialize(HttpResponseWrapper <VocVM> httpResponseWrapper)
        {
            VocVM vocVM = new VocVM();

            if (httpResponseWrapper.Success)
            {
                vocVM = await Deserialize <VocVM>(httpResponseWrapper.HttpResponseMessage, defaultJsonSerializerOptions);
            }
            else
            {
                vocVM.Exception = await httpResponseWrapper.GetBody();
            }

            return(vocVM);
        }
Example #10
0
        public async Task <List <Vid> > GetVids(VocVM vocVM)
        {
            List <Vid> vids = new List <Vid>();

            var response = await httpService.PostAsync($"{url}/GetVids", vocVM);

            if (response.Success)
            {
                vids = await DeserializeAsync <List <Vid> >(response.HttpResponseMessage, defaultJsonSerializerOptions);
            }
            else
            {
                vocVM.Exception = response.HttpResponseMessage.Content.ToString();
            }

            return(vids);
        }
Example #11
0
        public async Task <ActionResult <List <Vid> > > GetVids(VocVM vocVM)
        {
            try
            {
                if (vocVM == null)
                {
                    return(BadRequest());
                }

                return(await searchResultRepository.GetVids(vocVM));
            }
            catch (DbUpdateException Ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  Ex.InnerException.Message));
            }
        }
Example #12
0
        public async Task <List <pro_Models.Models.Image> > GetImagesByText(VocVM vocVM)
        {
            List <pro_Models.Models.Image> images = new List <pro_Models.Models.Image>();

            var response = await httpService.PostAsync($"{url}/GetImagesByText", vocVM);

            if (response.Success)
            {
                images = await DeserializeAsync <List <pro_Models.Models.Image> >(response.HttpResponseMessage, defaultJsonSerializerOptions);
            }
            else
            {
                vocVM.Exception = response.HttpResponseMessage.Content.ToString();
            }

            return(images);
        }
        public async Task <ActionResult <List <Image> > > GetImagesByText(VocVM vocVM)
        {
            try
            {
                if (vocVM == null)
                {
                    return(BadRequest());
                }

                return(await vocMasterRepository.GetImagesByText(vocVM));
            }
            catch (DbUpdateException Ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  Ex.InnerException.Message));
            }
        }
        private static void InsertClick(StackPanel stk_items, VocWpfHeader wpf_header)
        {
            var Voc = new VocVM(wpf_header.Txt_words.Text,
                                wpf_header.Txt_answer.Text,
                                wpf_header.Txt_def.Text,
                                wpf_header.Txt_ptbr.Text,
                                (Importance)wpf_header.Cob_imp.SelectedIndex,
                                wpf_header.Btn_isActive.IsActived);

            if (QuestControl.Insert(Voc))
            {
                wpf_header.Txt_words.Text  = string.Empty;
                wpf_header.Txt_answer.Text = string.Empty;
                wpf_header.Txt_def.Text    = string.Empty;
                wpf_header.Txt_ptbr.Text   = string.Empty;

                InsertQuestion(stk_items, Model.Voc);
            }
        }
Example #15
0
        public async Task <VocVM> UpdateVoc(VocVM vocVM)
        {
            Voc result = await appDbContext.Vocs
                         .FirstOrDefaultAsync(e => e.Id == vocVM.Voc.Id);

            if (result != null)
            {
                appDbContext.Entry(result).State = EntityState.Detached;
                result = mapper.Map(vocVM.Voc, result);
                appDbContext.Entry(result).State = EntityState.Modified;

                await appDbContext.SaveChangesAsync();

                return(new VocVM {
                    Voc = result
                });
            }

            return(null);
        }
Example #16
0
        public async Task <VocVM> GetVocCheck(string userId)
        {
            VocVM vocVM = new VocVM();

            List <UserVoc> userVoc = await appDbContext.UserVocs
                                     .Where(x => x.UserId == userId).ToListAsync();

            userVoc = userVoc.Where(x => x.NextReviewTime < DateTime.UtcNow).ToList();

            var x = userVoc
                    .OrderByDescending(x => x.NextReviewTime)
                    .First();

            if (userVoc != null)
            {
                vocVM.Voc = await appDbContext.Vocs.FirstOrDefaultAsync(e => e.Id == x.VocId);
            }

            return(vocVM);
        }
Example #17
0
        public async Task <ActionResult <VocVM> > UpdateVoc(int id, VocVM vocVM)
        {
            try
            {
                if (id != vocVM.Voc.Id)
                {
                    return(BadRequest("Voc ID mismatch"));
                }

                // Add custom model validation error
                Voc voc = await vocRepository.GetVocByname(vocVM.Voc);

                if (voc != null)
                {
                    ModelState.AddModelError("Name", $"Voc name: {vocVM.Voc.Text} already in use");
                    return(BadRequest(ModelState));
                }

                var vocToUpdate = await vocRepository.GetVoc(id);

                if (vocToUpdate == null)
                {
                    return(NotFound($"Voc with Id = {id} not found"));
                }

                await vocRepository.UpdateVoc(vocVM);

                return(CreatedAtAction(nameof(GetVoc), new { id = vocVM.Voc.Id }, vocVM));
            }

            catch (DbUpdateException Ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  Ex.InnerException.Message));
            }
        }
Example #18
0
        public async Task <ActionResult <VocVM> > GetVocVMByText(VocVM vocVM)
        {
            try
            {
                if (vocVM == null || string.IsNullOrEmpty(vocVM.Voc.Text))
                {
                    return(NotFound());
                }

                var result = await vocRepository.GetVocVMByText(vocVM);

                if (result == null)
                {
                    return(NotFound());
                }

                return(result);
            }
            catch (DbUpdateException Ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  Ex.InnerException.Message));
            }
        }
Example #19
0
        public async Task <VocVM> GetVocCheck(VocVM vocVM)
        {
            var response = await httpService.PostAsync($"{url}/check", vocVM);

            return(await CheckDeserialize(response));
        }
Example #20
0
        public async Task <VocVM> UpdateVoc(int id, VocVM vocVM)
        {
            var response = await httpService.Put($"{url}/{id}", vocVM);

            return(await CheckDeserialize(response));
        }
Example #21
0
        public async Task <VocVM> GetVocVMByText(VocVM vocVM)
        {
            vocVM.Voc = await appDbContext.Vocs.FirstOrDefaultAsync(n => n.Text == vocVM.Voc.Text);

            return(vocVM);
        }
Example #22
0
        public static Button Insert_Bulk(Grid parent, IQuestWpfHeader header)
        {
            var btn = new Button();

            btn.VerticalAlignment = VerticalAlignment.Center;
            btn.Margin            = new Thickness(1, 0, 1, 0);
            Get(btn, 1, 1, parent, "Insert");

            btn.Click += (source, e) =>
            {
                var watcher = new Stopwatch();
                watcher.Start();

                var lines = header.Txt_bulk_insert.Text.Replace("\r", "").Split('\n');

                header.Txt_bulk_insert.Text = "// format:  words;answer";

                var successful = new List <bool>();

                var inserts = new List <string>();
                var imp     = (Importance)header.Cob_bulk_imp.SelectedIndex;

                foreach (var line in lines)
                {
                    if (line.StartsWith("//") || line.StartsWith("Insert failed") || line.IsEmpty())
                    {
                        continue;
                    }

                    //if (line.Count(x => x == '1') != 1)
                    //{
                    //    successful.Add(false);
                    //    header.Txt_bulk_insert.Text += "\nInsert failed (must has 1 ';'): " + line;
                    //    continue;
                    //}

                    var parts = line.Split(';');

                    if (parts.Count() != 2 && !(header is SpellWpfController))
                    {
                        successful.Add(false);
                        header.Txt_bulk_insert.Text += "\nInsert failed (must has 2 parts): " + line;
                        continue;
                    }

                    var part1 = parts[0];
                    var part2 = parts[1];

                    if (header is VocWpfController)
                    {
                        if (!part1.IsLettersOnly() || !part2.IsLettersOnly())
                        {
                            successful.Add(false);
                            header.Txt_bulk_insert.Text += "\nInsert failed (parts must have only letters): " + line;
                            continue;
                        }
                    }

                    var vm = new QuestVM();

                    if (header is VocWpfHeader)
                    {
                        vm = new VocVM(part1, part2, "", "", imp, true);
                    }
                    if (header is PronWpfHeader)
                    {
                        vm = new PronVM(part1, part2, imp, true);
                    }
                    if (header is SpellWpfHeader)
                    {
                        vm = new SpellVM(part1, imp, true);
                    }

                    if (QuestControl.Insert(vm))
                    {
                        SuccessfulInserted(header, successful);
                    }
                    else
                    {
                        FailedInsert(header, successful, line);
                    }
                }
                Footer.Log("Of a total of " + successful.Count + " attempts, " +
                           successful.Where(x => x).Count() + " were inserted, while " +
                           successful.Where(x => !x).Count() + " failed. Time spent: " +
                           Math.Round(watcher.Elapsed.TotalSeconds, 2) + " seconds.");
            };

            return(btn);
        }
Example #23
0
        public async Task <VocVM> CreateVoc(VocVM vocVM)
        {
            var response = await httpService.PostAsync(url, vocVM);

            return(await CheckDeserialize(response));
        }