Пример #1
0
        public async Task <IActionResult> TipTranslation([FromRoute] int id, [FromBody] GeneralContentTranslationRequest contentTranslationRequest)
        {
            var loggedUser = User.GetUserIdFromToken();
            await _generalContentService.ChangeContentTranslationAsync(loggedUser, contentTranslationRequest, id);

            return(Ok());
        }
Пример #2
0
        public async Task ChangeContentTranslationAsync(int loggedUser, GeneralContentTranslationRequest contentTranslationRequest, 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 content = await _uow.GeneralContentRepository.GetAll().Where(c => c.Id == id)
                          .FirstOrDefaultAsync();

            if (content == null)
            {
                throw new NotFoundException(ExceptionConstants.NOT_FOUND, "Content");
            }

            switch (contentTranslationRequest.Lang)
            {
            case "en":
                content.ContentEN = contentTranslationRequest.Content;
                break;

            case "it":
                content.ContentIT = contentTranslationRequest.Content;
                break;

            default:
                content.Content = contentTranslationRequest.Content;
                break;
            }

            _uow.GeneralContentRepository.Update(content);
            await _uow.CommitAsync();
        }