Esempio n. 1
0
        public async Task <long> InsertVocabWordAsync(VocabWord vocabWord, User account)
        {
            if (account != null)
            {
                vocabWord.Owner = account;

                var existingVocabWord = await _vocabWordsRepository.GetAll()
                                        .Where(v => v.Word == vocabWord.Word && v.Owner.Id == vocabWord.Owner.Id)
                                        .Include(v => v.Owner).FirstOrDefaultAsync();

                if (existingVocabWord != null)
                {
                    existingVocabWord.Word        = vocabWord.Word;
                    existingVocabWord.Translation = vocabWord.Translation;
                    existingVocabWord.Type        = vocabWord.Type;
                    await _vocabWordsRepository.UpdateAsync(existingVocabWord);
                }
                else
                {
                    await _vocabWordsRepository.InsertAsync(vocabWord);
                }

                await CurrentUnitOfWork.SaveChangesAsync();

                return(vocabWord.Id);
            }

            return(0);
        }
Esempio n. 2
0
        public async Task <ActionResult> Create(VocabWordCreateViewModel vocabWordCreateViewModel)
        {
            try
            {
                var user = await GetCurrentUserAsync();

                var vocabWord = new VocabWord
                {
                    Word       = vocabWordCreateViewModel.Word,
                    Definition = vocabWordCreateViewModel.Definition,

                    SoftwareLanguageId = vocabWordCreateViewModel.SoftwareLanguageId,
                };
                //Set application user id to the the the lod in user's id

                vocabWord.ApplicationUserId = user.Id;
                //add the new todoitem to the list of todoitems? Or promise to add the the todoitems to the db.


                _context.VocabWords.Add(vocabWord);
                //Save changes to the databse
                await _context.SaveChangesAsync();

                //Return to the list of todoitems once you've created a new todoItem

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 3
0
        public async Task <long> Post(VocabWord vocabWord)
        {
            var account = await GetCurrentUserOrNullAsync();

            var result = await _vocabularyService.InsertVocabWordAsync(vocabWord, account);

            if (result <= 0)
            {
                throw new UserFriendlyException("Word wasn't inserted into vocabulary!");
            }

            return(result);
        }
Esempio n. 4
0
        public async Task <ActionResult> Delete(int id, VocabWord vocabWord)
        {
            try
            {
                _context.VocabWords.Remove(vocabWord);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }