예제 #1
0
        public IHttpActionResult SendNotification(string message)
        {
            try
            {
                var Devices          = notificationManager.SelectAllDevices();
                var DevicesList      = Devices.ToList().Select(x => x.DeviceId);
                var RecepientDevices = new OneSignalLibrary.Posting.Device(new HashSet <string>(DevicesList));

                Dictionary <string, string> NotificationCOntent = new Dictionary <string, string>();
                //NotificationCOntent.Add("ar", arabicMessage);
                //NotificationCOntent.Add("message",arabicMessage);
                NotificationCOntent.Add("en", message);
                var content = new OneSignalLibrary.Posting.ContentAndLanguage(NotificationCOntent);

                try
                {
                    client.SendNotification(RecepientDevices, content, null, null);
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #2
0
        public IHttpActionResult SendCarDeliveryOrderNotification(string carDeliveryOrderId, string message)
        {
            try
            {
                var hourlyAppointment = notificationManager.GetContactIdByCarDeliveryOrderId(carDeliveryOrderId);
                var Devices           = notificationManager.SelectDevicesByCrmUserId(hourlyAppointment.new_Contact);
                var DevicesList       = Devices.ToList().Select(x => x.DeviceId);
                var RecepientDevices  = new OneSignalLibrary.Posting.Device(new HashSet <string>(DevicesList));

                Dictionary <string, string> NotificationCOntent = new Dictionary <string, string>();
                //var message = " يوجد لديك زيارة غداً بخصوص العقد رقم {0} من {1} الى {2} ";

                //message = String.Format(message, hourlyAppointment.new_contractnumber
                //    , hourlyAppointment.ShiftStart.HasValue ? hourlyAppointment.ShiftStart.Value.ToShortTimeString() : ""
                //    , hourlyAppointment.ShiftEnd.HasValue ? hourlyAppointment.ShiftEnd.Value.ToShortTimeString() : "");

                NotificationCOntent.Add("en", message);
                var content = new OneSignalLibrary.Posting.ContentAndLanguage(NotificationCOntent);

                try
                {
                    client.SendNotification(RecepientDevices, content, null, null);
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }