Ejemplo n.º 1
0
        public async Task <ActionResult <UserModel> > Put(int id, WordUpdateDto wordData)
        {
            var word = _dao.GetWordByIdAsync(id).Result.Data;

            var categoryDao = new CategoryDao();

            var category = await categoryDao.GetCategoryByIdAsync(wordData.CategoryId);

            if (word != null)
            {
                if (category.Data != null)
                {
                    var categoryWords = _dao.GetCategoryWordsAsync(wordData.CategoryId).Result.Data.Where(w => w.Lexeme.Lexeme == wordData.Lexeme).ToList();

                    if (categoryWords.Count() != 0 || string.IsNullOrEmpty(wordData.Lexeme))
                    {
                        return(BadRequest(new DataResult <WordModel>(null, "WORD_WITH_SAME_LEXEME_AlREADY_EXISTS_IN_THIS_CATEGORY")));
                    }
                    else
                    {
                        word.Lexeme.Lexeme = wordData.Lexeme;
                        word.Transcription.Transcription = wordData.Transcription;
                        word.Translation.Translation     = wordData.Translation;
                        word.CategoryId = wordData.CategoryId;
                        var result = await _dao.UpdateWordAsync(word);

                        return(Ok(result));
                    }
                }

                return(BadRequest(new DataResult <CategoryModel>(null, "CATEGORY_NOT_EXISTS")));
            }

            return(NotFound(new DataResult <CategoryModel>(null, "WORD_NOT_EXISTS")));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <CategoryModel> > GetCategory(int id)
        {
            var result = await _dao.GetCategoryByIdAsync(id);

            if (result.Data != null && result.Succeded && result.Exception == null && string.IsNullOrEmpty(result.ErrorMessage))
            {
                return(Ok(result));
            }
            else if (result.Exception == null)
            {
                return(NotFound(result));
            }
            else
            {
                return(BadRequest(result));
            }
        }