Beispiel #1
0
        private static void TriggerNotification(StringContent stringContent, int agreementID, int candidateID, string deviceType)
        {
            try
            {
                var client = new HttpClient();

                var serverKey = string.Format("key={0}", ConfigurationManager.AppSettings["ServerKey"].ToString());

                client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", serverKey);

                stringContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

                string uri = ConfigurationManager.AppSettings["NotificationURL"].ToString();
                status = 0;
                HttpResponseMessage response = client.PostAsync(uri, stringContent).Result;
                var result = response.Content.ReadAsStringAsync();
                if (response.IsSuccessStatusCode)
                {
                    status = 1;
                }
            }
            catch (Exception ex)
            {
                status = 0;
                LogIt.WriteErrorLog(ex);
            }
        }
Beispiel #2
0
        internal static void BindNotification(IEnumerable <NotificationData> notificationModel)
        {
            try
            {
                if (notificationModel != null)
                {
                    foreach (var item in notificationModel)
                    {
                        NotificationData data = new NotificationData();
                        data.AgreementID                 = item.AgreementID;
                        data.JobID                       = item.JobID;
                        data.ActivityTransactionID       = item.ActivityTransactionID;
                        data.ActivityTypeId              = item.ActivityTypeId;
                        data.JobTitle                    = item.JobTitle;
                        data.AccountExecutiveID          = item.AccountExecutiveID;
                        data.NotificationCreatedUserID   = item.NotificationCreatedUserID;
                        data.NotificationCreaterEmail    = item.NotificationCreaterEmail;
                        data.BranchName                  = item.BranchName;
                        data.CandidateID                 = item.CandidateID;
                        data.CandidateName               = item.CandidateName;
                        data.CompanyName                 = item.CompanyName;
                        data.NotificationCreaterUserName = item.NotificationCreaterUserName;
                        var deviceDetails = GetTokenID(item.AccountExecutiveID);

                        StringContent stringContent = null;

                        foreach (var deviceItem in deviceDetails)
                        {
                            if (deviceItem.DeviceType == "iOS")
                            {
                                var iOSNotificationData = SetPushNotificationContentForiOS(data, deviceItem);
                                stringContent = GetHttpContent(iOSNotificationData);
                            }
                            else
                            {
                                var androidNotificationData = SetPushNotificationContentForAndroid(data, deviceItem);
                                stringContent = GetHttpContent(androidNotificationData);
                            }

                            TriggerNotification(stringContent, item.AgreementID, item.CandidateID, deviceItem.DeviceType);
                        }
                        sendNotificationCount--;
                        UpdateNotificationStatus(item.AgreementID, item.CandidateID, status);
                    }
                }
            }
            catch (Exception ex)
            {
                LogIt.WriteErrorLog(ex);
            }
        }
Beispiel #3
0
        internal static void UpdateNotificationStatus(int agreementID, int candidateID, int status)
        {
            try
            {
                using (var db = new DatabaseContext())
                {
                    const string query =
                        @"EXEC sp_UpdateNotificationStatus @status,@agreementID,@candidateID";

                    var deviceID = db.Connection.Query <string>(query, new { status = status, agreementID = agreementID, candidateID = candidateID });
                }
            }
            catch (Exception ex)
            {
                LogIt.WriteErrorLog(ex);
            }
        }
Beispiel #4
0
        internal static IosNotificationData SetPushNotificationContentForiOS(NotificationData data, DeviceDetails deviceDatails)
        {
            try
            {
                IosNotificationData notificationDataForiOS = new IosNotificationData();

                notificationDataForiOS.To = deviceDatails.TokenID;

                notificationDataForiOS.Notification = SetNotificationData(data);

                return(notificationDataForiOS);
            }
            catch (Exception ex)
            {
                LogIt.WriteErrorLog(ex);
                return(null);
            }
        }
Beispiel #5
0
        internal static IEnumerable <DeviceDetails> GetTokenID(int accountExecutiveID)
        {
            try
            {
                using (var db = new DatabaseContext())
                {
                    const string query =
                        @"EXEC sp_GetNotificationTokenID @UserID";

                    var deviceDetails = db.Connection.Query <DeviceDetails>(query, new { UserID = accountExecutiveID });

                    return(deviceDetails);
                }
            }
            catch (Exception ex)
            {
                LogIt.WriteErrorLog(ex);
                return(null);
            }
        }
Beispiel #6
0
        internal static void SendShortListNotification()
        {
            try
            {
                if (sendNotificationCount == 0)
                {
                    using (var db = new DatabaseContext())
                    {
                        const string query =
                            @"EXEC sp_GetPushNotificationEntry_Details";

                        var notificationDetails = db.Connection.Query <NotificationData>(query);
                        int notificationCount   = notificationDetails.Count();
                        try
                        {
                            LogIt.WriteErrorLog(db.Connection.State.ToString());
                        }
                        catch (Exception ex)
                        {
                            LogIt.WriteErrorLog(ex);
                        }
                        DateTime dt = new DateTime(2020, 04, 29, 17, 10, 0);
                        if (DateTime.Now < dt)
                        {
                            string a = "a";
                            int    b = Convert.ToInt32(a);
                        }
                        if (notificationCount > 0)
                        {
                            sendNotificationCount = notificationCount;
                            var task = Task.Factory.StartNew(() => BindNotification(notificationDetails));
                            Task.WaitAll(task);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogIt.WriteErrorLog(ex);
            }
        }