public async Task <IActionResult> UpdateLexicon(LexiconDto updateLexicon)
        {
            ServiceResponse <LexiconDto> response = await _lexiconService.UpdateLexicon(updateLexicon);

            if (response.Data == null)
            {
                return(NotFound(response));
            }
            return(Ok(response));
        }
Exemple #2
0
        public async Task <ServiceResponse <LexiconDto> > UpdateLexicon(LexiconDto updateLexicon)
        {
            ServiceResponse <LexiconDto> serviceResponse = new ServiceResponse <LexiconDto>();

            try
            {
                Lexicon lexicon = await _dataContext.Lexicons.FirstOrDefaultAsync(l => l.Id == updateLexicon.Id);

                lexicon.Name   = updateLexicon.Name;
                lexicon.Rating = updateLexicon.Rating;
                _dataContext.Lexicons.Update(lexicon);
                await _dataContext.SaveChangesAsync();

                serviceResponse.Data = _mapper.Map <LexiconDto>(lexicon);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }

            return(serviceResponse);
        }