예제 #1
0
        public async Task ChangeTipTranslationAsync(int loggedUser, TipTranslationRequest tipTranslationRequest, 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 tip = await _uow.TipRepository.GetAll().Where(c => c.Id == id)
                      .FirstOrDefaultAsync();

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

            switch (tipTranslationRequest.Lang)
            {
            case "en":
                tip.ContentEN = tipTranslationRequest.Content;
                break;

            case "it":
                tip.ContentIT = tipTranslationRequest.Content;
                break;

            default:
                tip.Content = tipTranslationRequest.Content;
                break;
            }

            _uow.TipRepository.Update(tip);
            await _uow.CommitAsync();
        }
예제 #2
0
        public async Task <IActionResult> TipTranslation([FromRoute] int id, [FromBody] TipTranslationRequest tipTranslationRequest)
        {
            var loggedUser = User.GetUserIdFromToken();
            await _tipService.ChangeTipTranslationAsync(loggedUser, tipTranslationRequest, id);

            return(Ok());
        }