// Read Alerts log Table
        public List <SmsLog> GetZ_AlertLogs()
        {
            List <SMS_GetZ_AlertLogsByDate_Result> result = new List <SMS_GetZ_AlertLogsByDate_Result>();
            List <SmsLog> sl = new List <SmsLog>();

            DateTime?dt = GetTorontoLocalDateTime();

            //DateTime? dt = DateTime.Parse("2020-08-5");

            try
            {
                using (DB_A4A060_csEntities context = new DB_A4A060_csEntities())
                {
                    result = context.SMS_GetZ_AlertLogsByDate(dt.Value).ToList();
                }
                //remove record with Gaps > 5%
                if (result.Count > 0)
                {
                    result = RemoveBigGapsData(result, Properties.Settings.Default.GapsLimit);
                }
                else
                {
                    return(sl);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            //Write records to Smslog table database

            foreach (var item in result)
            {
                SmsLog slitem = new SmsLog();
                slitem.@event        = item.@event;
                slitem.message       = item.message;
                slitem.phonenumber   = item.Phone;
                slitem.status        = "prepared to sending";
                slitem.datemark      = item.date_emailsent;
                slitem.smscId        = "0";
                slitem.AspNetUser_Id = item.AspNetUser_ID;
                sl.Add(slitem);
                slitem = null;
            }

            //check if records were saved today
            var rdonetoday = RemoveItemsSaved(sl);

            return(rdonetoday);
        }
        private static List <SmsLog> SaveSMSinDatabase(List <SmsLog> alerts_ruled)
        {
            List <SmsLog> sl = new List <SmsLog>();

            foreach (var item in alerts_ruled)
            {
                SmsLog slitem = new SmsLog();
                slitem.@event        = item.@event;
                slitem.message       = item.message;
                slitem.phonenumber   = item.phonenumber;
                slitem.status        = "prepared to sending";
                slitem.datemark      = item.datemark;
                slitem.smscId        = "0";
                slitem.AspNetUser_Id = item.AspNetUser_Id;
                sl.Add(slitem);
                slitem = null;
            }
            //update database
            try
            {
                using (DB_A4A060_csEntities context = new DB_A4A060_csEntities())
                {
                    context.SmsLogs.AddRange(sl);
                    context.SaveChanges();
                    int rowsnumber = sl.Count;
                    sl.Clear();
                    sl = context.SmsLogs.OrderByDescending(x => x.id).Where(x => x.status == "prepared to sending" && x.smscId == "0").Take(rowsnumber).ToList();
                }
            }
            catch (Exception ex)
            {
                var x = ex.Message;
                sl = null;
            }
            return(sl);
        }