public async Task <IActionResult> AnswerMesage([FromBody] ContactAnswerRequest answerRequest) { var loggedUser = User.GetUserIdFromToken(); await _contactUsService.AnswerMmessageAsync(loggedUser, answerRequest); return(Ok()); }
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(); }