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"))); }
public async Task <IActionResult> UpdateWord([FromBody] WordUpdateDto wordDto) { if (wordDto == null) { return(BadRequest()); } var word = _mapper.Map <Word>(wordDto); _repository.Word.Update(word); await _repository.Save(); return(Ok()); }
public async Task <IActionResult> UpdateWord([FromBody] WordUpdateDto wordDto) { if (wordDto == null) { _logger.LogInfo($"Word with id: {wordDto.Id} doesn't exist in the database."); return(NotFound()); } var word = _mapper.Map <Word>(wordDto); _service.UpdateWord(word); await _service.Save(); return(NoContent()); }