public async Task <IActionResult> ResultsTranslation([FromRoute] int id, [FromBody] ResultTranslationRequest resultTranslationRequest) { var loggedUser = User.GetUserIdFromToken(); await _resultService.ChangeResultTranslationAsync(loggedUser, resultTranslationRequest, id); return(Ok()); }
public async Task ChangeResultTranslationAsync(int loggedUser, ResultTranslationRequest resultTranslationRequest, int id) { // validate admin user var user = await _uow.UserRepository.FindByAsync(u => u.Id == loggedUser && u.Role == RoleEnum.ADMIN); if (user.Count == 0) { throw new NotAllowedException(ExceptionConstants.NOT_ALLOWED); } var result = await _uow.ResultRepository.GetAll().Where(c => c.Id == id) .FirstOrDefaultAsync(); if (result == null) { throw new NotFoundException(ExceptionConstants.NOT_FOUND, "Result"); } switch (resultTranslationRequest.Lang) { case "en": result.TextEN = resultTranslationRequest.Text; break; case "it": result.TextIT = resultTranslationRequest.Text; break; default: result.Text = resultTranslationRequest.Text; break; } _uow.ResultRepository.Update(result); await _uow.CommitAsync(); }