public static async Task BlockedMessageUpdate(IHttpContext context) { Dictionary <string, string> payload = Server.Payload(context); payload.TryGetValue("MsgId", out string idStr); payload.TryGetValue("Message", out string message); payload.TryGetValue("Mo", out string mo); payload.TryGetValue("Tu", out string tu); payload.TryGetValue("We", out string we); payload.TryGetValue("Th", out string th); payload.TryGetValue("Fr", out string fr); payload.TryGetValue("Sa", out string sa); payload.TryGetValue("Su", out string su); payload.TryGetValue("Start", out string startStr); payload.TryGetValue("End", out string endStr); int.TryParse(idStr, out int id); int.TryParse(startStr, out int startHour); int.TryParse(endStr, out int endHour); MelBoxSql.Tab_Message.BlockedDays blockedDays = Tab_Message.BlockedDays.None; if (mo != null) { blockedDays |= MelBoxSql.Tab_Message.BlockedDays.Mo; } if (tu != null) { blockedDays |= MelBoxSql.Tab_Message.BlockedDays.Di; } if (we != null) { blockedDays |= MelBoxSql.Tab_Message.BlockedDays.Mi; } if (th != null) { blockedDays |= MelBoxSql.Tab_Message.BlockedDays.Do; } if (fr != null) { blockedDays |= MelBoxSql.Tab_Message.BlockedDays.Fr; } if (sa != null) { blockedDays |= MelBoxSql.Tab_Message.BlockedDays.Sa; } if (su != null) { blockedDays |= MelBoxSql.Tab_Message.BlockedDays.So; } Message set = new Message { BlockedDays = blockedDays, StartBlockHour = startHour, EndBlockHour = endHour }; string alert; if (!Tab_Message.Update(set, id)) { alert = Html.Alert(1, "Nachricht aktualisieren fehlgeschlagen", $"Die Nachricht {idStr}<p><i>{message}</i></p> konnte nicht geändert werden."); } else { alert = Html.Alert(2, "Nachricht aktualisiert", $"Änderungen für die Nachricht {idStr}<p><i>{message}</i></p>gespeichert."); } System.Data.DataTable sent = MelBoxSql.Sql.Blocked_View(); string table = Html.FromTable(sent); await Server.PageAsync(context, "Nachricht aktualisiert", alert + table); }
private static void Gsm_SmsRecievedEvent(object sender, ParseSms e) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(e.Sender + ":\r\n" + e.Message); Console.ForegroundColor = ConsoleColor.Gray; #region SMS-Empfang in Datenbank protokollieren int fromId = GetSmsSenderID(e.Sender, e.Message); int messageId = MelBoxSql.Tab_Message.SelectOrCreateMessageId(e.Message); Recieved recieved1 = new Recieved() { FromId = fromId, ContentId = messageId, RecTime = DateTime.UtcNow }; MelBoxSql.Tab_Recieved.Insert(recieved1); #endregion #region Weiterleiten per EMail oder SMS MailAddressCollection emailRecievers = new MailAddressCollection(); string emailSuffix = string.Empty; Random ran = new Random(); int emailId = ran.Next(256, 9999); // Pseudo-Id für Sendungsverfolgung if (e.Message.ToLower().Trim() == SmsWayValidationTrigger.ToLower()) // SmsAbruf? { #region Meldelinientest 'SmsAbruf' MelBoxGsm.Gsm.Ask_SmsSend(e.Sender, e.Message.Trim() + " um " + DateTime.Now.ToString("HH:mm:ss") + " Uhr."); Sent sent = new Sent(fromId, messageId, Tab_Contact.Communication.Sms) { SentTime = DateTime.UtcNow }; MelBoxSql.Tab_Sent.Insert(sent); #endregion } else if (Tab_Message.IsMessageBlockedNow(messageId)) // Nachricht zum jetzigen Zeitpunkt gesperrt? { emailSuffix += Environment.NewLine + "Keine Weiterleitung an Bereitschaftshandy da SMS zur Zeit gesperrt."; } else // An Bereitschaft senden { #region An Bereitschaft senden //Bereitschaft ermitteln List <MelBoxSql.Shift> currentShifts = MelBoxSql.Tab_Shift.SelectOrCreateCurrentShift(); Console.WriteLine("Aktuelle Bereitschaft: "); //an Bereitschaft weiterleiten foreach (var shift in currentShifts) { Contact to = MelBoxSql.Tab_Contact.SelectContact(shift.ContactId); Console.WriteLine($"Id [{shift.Id}] >{to.Name}< von >{shift.Start}< bis >{shift.End}<"); //Email freigegeben und gültig? if ((to.Via & Tab_Contact.Communication.Email) > 0 && Tab_Contact.IsEmail(to.Email)) { emailRecievers.Add(new MailAddress(to.Email, to.Name)); Sent sent = new Sent(shift.ContactId, messageId, Tab_Contact.Communication.Email) { Confirmation = Tab_Sent.Confirmation.AwaitingRefernece, Reference = emailId, SentTime = DateTime.UtcNow }; MelBoxSql.Tab_Sent.Insert(sent); } //SMS? if ((to.Via & Tab_Contact.Communication.Sms) > 0) { Sent sent = new Sent(shift.ContactId, messageId, Tab_Contact.Communication.Sms) { Confirmation = Tab_Sent.Confirmation.NaN, SentTime = DateTime.UtcNow }; MelBoxSql.Tab_Sent.Insert(sent); MelBoxGsm.Gsm.Ask_SmsSend("+" + to.Phone.ToString(), e.Message); } } if (currentShifts.Count == 0) { Console.WriteLine("z.Zt. keine aktive Bereitschaft"); emailSuffix += Environment.NewLine + "Keine Weiterleitung an Bereitschaftshandy während der Geschäftszeit."; } else { emailSuffix += Environment.NewLine + "Weiterleitung an Bereitschaftshandy außerhalb Geschäftszeiten ist erfolgt."; } #endregion } //Emails an Bereitschaft und ständige Empfänger senden. string subject = $"SMS-Eingang >{MelBoxSql.Tab_Contact.SelectName_Company_City(fromId)}<, Text >{e.Message}<"; string body = $"Absender >{e.Sender}<\r\nText >{e.Message}<\r\nSendezeit >{e.TimeUtc.ToLocalTime().ToLongTimeString()}<\r\n" + emailSuffix; Email.Send(emailRecievers, body, subject, emailId); #endregion }