Exemplo n.º 1
0
        public async Task <IActionResult> Create(AlertOptions alertOptions)
        {
            Request.Headers.TryGetValue("OrganizationID", out var orgID);

            DataService.WriteEvent("Alert created.  Alert Options: " + JsonSerializer.Serialize(alertOptions), orgID);

            if (alertOptions.ShouldAlert)
            {
                try
                {
                    await DataService.AddAlert(alertOptions, orgID);
                }
                catch (Exception ex)
                {
                    DataService.WriteEvent(ex, orgID);
                }
            }

            if (alertOptions.ShouldEmail)
            {
                try
                {
                    await EmailSender.SendEmailAsync(alertOptions.EmailTo,
                                                     alertOptions.EmailSubject,
                                                     alertOptions.EmailBody,
                                                     orgID);
                }
                catch (Exception ex)
                {
                    DataService.WriteEvent(ex, orgID);
                }
            }

            if (alertOptions.ShouldSendApiRequest)
            {
                try
                {
                    var httpRequest = WebRequest.CreateHttp(alertOptions.ApiRequestUrl);
                    httpRequest.Method      = alertOptions.ApiRequestMethod;
                    httpRequest.ContentType = "application/json";
                    foreach (var header in alertOptions.ApiRequestHeaders)
                    {
                        httpRequest.Headers.Add(header.Key, header.Value);
                    }
                    using (var rs = httpRequest.GetRequestStream())
                        using (var sw = new StreamWriter(rs))
                        {
                            sw.Write(alertOptions.ApiRequestBody);
                        }
                    var response = (HttpWebResponse)httpRequest.GetResponse();
                    DataService.WriteEvent($"Alert API Response Status: {response.StatusCode}.", orgID);
                }
                catch (Exception ex)
                {
                    DataService.WriteEvent(ex, orgID);
                }
            }

            return(Ok());
        }
Exemplo n.º 2
0
        public void AddDeviceAlert(string alertMessage)
        {
            var options = new AlertOptions()
            {
                AlertDeviceID = Device.ID,
                AlertMessage  = alertMessage,
                ShouldAlert   = true
            };

            DataService.AddAlert(options, Device.OrganizationID);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPost(string deviceID)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var orgID = DataService.GetDevice(deviceID)?.OrganizationID;

            var alertMessage = $"{Input.Name} is requesting support.  " +
                               $"Email: {Input.Email}.  " +
                               $"Phone: {Input.Phone}.  " +
                               $"Chat OK: {Input.ChatResponseOk}.";

            await DataService.AddAlert(deviceID, orgID, alertMessage);

            StatusMessage = "We got it!  Someone will contact you soon.";

            return(RedirectToPage("GetSupport", new { deviceID }));
        }