public IActionResult SendFeedback([FromBody] SendFeedbackRequest request) { var allowedFeedbacks = _dbContext.ReportAllowedFeedbacks.Where(r => r.ReportId == request.ReportId && r.Feedback.IsEnabled).Select(f => f.FeedbackId).ToList(); var userId = User.GetUserId(); if (!userId.HasValue) { throw new HttpStatusException(HttpStatusCode.Unauthorized); } if (!allowedFeedbacks.Contains(request.FeedbackId)) { throw new HttpStatusException(HttpStatusCode.BadRequest, "Invalid feedback id"); } var existingFeedback = _dbContext.ReportFeedbacks.FirstOrDefault(rf => rf.UserId == userId && rf.ReportId == request.ReportId && rf.InvalidatedDate == null); if (existingFeedback != null) { // No change if (existingFeedback.FeedbackId == request.FeedbackId) { return(Ok()); } existingFeedback.InvalidatedByUserId = userId.Value; existingFeedback.InvalidatedDate = DateTime.UtcNow; existingFeedback.InvalidationReason = "Feedback changed"; } _dbContext.ReportFeedbacks.Add(new DbReportFeedback { FeedbackId = request.FeedbackId, ReportId = request.ReportId, UserId = userId.Value }); _dbContext.SaveChanges(); _dbContext.ProcessReport(request.ReportId); _dbContext.SaveChanges(); return(Ok()); }
public async Task <SendFeedbackResponse> SendFeedback(SendFeedbackRequest request) { var response = new SendFeedbackResponse(); var user = await _sessionManager.GetUser(); if (user != null) { await _emailManager.SendFeedback(new Models.ServiceModels.Email.SendFeedbackRequest() { Name = user.First_Name, EmailAddress = user.Email_Address, Message = request.Message }); } response.Notifications.Add("Thank you for your feedback, we will read it as soon as possible", NotificationTypeEnum.Success); return(response); }
public async Task SendFeedback(SendFeedbackRequest request) { var configuration = await _cache.Configuration(); var baseUrl = _httpContextAccessor.HttpContext.Request.GetBaseUrl(); var templateHtml = await _emailTemplateRepo.GetSendFeedbackHTML(); var template = new SendFeedbackTemplate(templateHtml, baseUrl) { Name = request.Name, EmailAddress = request.EmailAddress, Message = request.Message }; await _emailProvider.Send(new Infrastructure.Email.Models.SendRequest() { FromAddress = configuration.System_From_Email_Address, ToAddress = configuration.Contact_Email_Address, Subject = template.Subject, Body = template.GetHTMLContent() }); }
public FeedbackModel(IAccountService service) { _service = service; FormData = new SendFeedbackRequest(); }