public async Task <Unit> Handle(CreateWordCategoryCommand request, CancellationToken cancellationToken)
            {
                var entity = new WordCategory(request.LanguageId, request.Name);

                _context.WordCategories.Add(entity);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
예제 #2
0
            public async Task <Unit> Handle(CreateWordCommand request, CancellationToken cancellationToken)
            {
                var user = await _authorizationProvider.GetCurrentUser();

                var entity = new Word(request.LanguageId, request.Text.ToLower(), request.Translation.ToLower(), user.Id, request.WordCategoryId);

                _context.Words.Add(entity);

                await _context.SaveChangesAsync(cancellationToken);

                await _textToSpeechService.GenerateSpeechFile(entity.Text, $"wwwroot/Assets/Mp3/{entity.Text}.mp3");

                return(Unit.Value);
            }
예제 #3
0
            public async Task <Unit> Handle(DeleteWordCategoryCommand request, CancellationToken cancellationToken)
            {
                var entity = await _context.WordCategories.FindAsync(request.Id);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(WordCategory), request.Id);
                }

                _context.WordCategories.Remove(entity);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
예제 #4
0
            public async Task <Unit> Handle(UpdateWordCategoryCommand request, CancellationToken cancellationToken)
            {
                var entity = await _context.WordCategories.SingleOrDefaultAsync(w => w.Id == request.Id, cancellationToken);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(WordCategory), request.Id);
                }

                entity.Update(request.Name);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <Unit> Handle(ToggleIsActiveCommand request, CancellationToken cancellationToken)
            {
                var entity = await _context.Words.FindAsync(request.Id);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(Word), request.Id);
                }

                entity.ToggleIsActive();

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
예제 #6
0
            public async Task <Unit> Handle(DeleteWordCommand request, CancellationToken cancellationToken)
            {
                var entity = await _context.Words.FindAsync(request.Id);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(Word), request.Id);
                }

                File.Delete($"wwwroot/Assets/Mp3/{entity.Text}.mp3");

                _context.Words.Remove(entity);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <Unit> Handle(PostPracticeResultCommand request, CancellationToken cancellationToken)
            {
                var correctWords = await _context.Words.Where(w => request.Correct.Contains(w.Id)).ToListAsync();

                var wrongWords = await _context.Words.Where(w => request.Wrong.Contains(w.Id)).ToListAsync();

                foreach (var word in correctWords)
                {
                    word.UpdateCount(true);
                }

                foreach (var word in wrongWords)
                {
                    word.UpdateCount(false);
                }

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
예제 #8
0
            public async Task <Unit> Handle(UpdateWordCommand request, CancellationToken cancellationToken)
            {
                var entity = await _context.Words.SingleOrDefaultAsync(w => w.Id == request.Id, cancellationToken);

                if (entity == null)
                {
                    throw new NotFoundException(nameof(Word), request.Id);
                }

                if (entity.Text != request.Text)
                {
                    File.Delete($"wwwroot/Assets/Mp3/{entity.Text}.mp3");
                    _textToSpeechService.GenerateSpeechFile(request.Text, $"wwwroot/Assets/Mp3/{request.Text}.mp3");
                }

                entity.Update(request.Text.ToLower(), request.Translation.ToLower(), request.WordCategoryId);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }