示例#1
0
        public async Task <IActionResult> AnswerMesage([FromBody] ContactAnswerRequest answerRequest)
        {
            var loggedUser = User.GetUserIdFromToken();
            await _contactUsService.AnswerMmessageAsync(loggedUser, answerRequest);

            return(Ok());
        }
示例#2
0
        public async Task AnswerMmessageAsync(int loggedUser, ContactAnswerRequest answerRequest)
        {
            // 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 contactUs = await _uow.ContactUsRepository.GetAsync(answerRequest.ContactUsId);

            if (contactUs is null)
            {
                throw new NotFoundException(ExceptionConstants.NOT_FOUND, "Contact Us");
            }

            var list = new List <string>();

            list.Add(answerRequest.UserEmail);

            await _emailService.SendEmailResponseAsync("RE: " + contactUs.Subject, answerRequest.Body, list);

            contactUs.IsAnswered = true;

            _uow.ContactUsRepository.Update(contactUs);
            await _uow.CommitAsync();
        }