public void SendNotifications(int AnimalId, string Message, string _Title) { //...Get APIs for AnimalId List <NotificationAPI> NotifyList = new List <NotificationAPI>(); NotificationAPI ins; SqlConnection sqlConn = DataBaseConnection.SqlConn(); using (var con = sqlConn) { con.Open(); using (SqlCommand cmd = new SqlCommand("exec notify_GetUserAPIsForAnimal @AnimalId", con)) { cmd.Parameters.AddWithValue("@AnimalId", AnimalId); using (var drI = cmd.ExecuteReader()) { while (drI.Read()) { ins = new NotificationAPI(); ins.UserNotificationId = Convert.ToInt32(drI["UserNotificationId"]); ins.NotificationType = Convert.ToInt32(drI["NotificationType"]); ins.API = drI["API"].ToString(); NotifyList.Add(ins); } } } } sqlConn.Close(); //...Send Notifications foreach (NotificationAPI notify in NotifyList) { switch (notify.NotificationType) { case LookUpValues.Email: SendEmail(Message, notify.API, notify.UserNotificationId); break; case LookUpValues.SMS: SendSMS(Message, notify.API, notify.UserNotificationId); break; case LookUpValues.PushBullet: SendPushBullet(Message, _Title, notify.API, notify.UserNotificationId); break; default: break; } } }
public void SendNotifications(int AnimalId, string Message, string _Title) { //...Get APIs for AnimalId List<NotificationAPI> NotifyList = new List<NotificationAPI>(); NotificationAPI ins; SqlConnection sqlConn = DataBaseConnection.SqlConn(); using (var con = sqlConn) { con.Open(); using (SqlCommand cmd = new SqlCommand("exec notify_GetUserAPIsForAnimal @AnimalId", con)) { cmd.Parameters.AddWithValue("@AnimalId", AnimalId); using (var drI = cmd.ExecuteReader()) { while (drI.Read()) { ins = new NotificationAPI(); ins.UserNotificationId = Convert.ToInt32(drI["UserNotificationId"]); ins.NotificationType = Convert.ToInt32(drI["NotificationType"]); ins.API = drI["API"].ToString(); NotifyList.Add(ins); } } } } sqlConn.Close(); //...Send Notifications foreach(NotificationAPI notify in NotifyList) { switch (notify.NotificationType) { case LookUpValues.Email: SendEmail(Message, notify.API, notify.UserNotificationId); break; case LookUpValues.SMS: SendSMS(Message, notify.API, notify.UserNotificationId); break; case LookUpValues.PushBullet: SendPushBullet(Message, _Title, notify.API, notify.UserNotificationId); break; default: break; } } }