public void Execute(IJobExecutionContext context) { PropertyModel PropertyModel = new Models.PropertyModel(); JobDataMap dataMap = context.JobDetail.JobDataMap; int PropertyId = Convert.ToInt32(dataMap.GetString("PropertyId")); string Subject = dataMap.GetString("Subject"); string Body = dataMap.GetString("Body"); string PropertyTypeStatus = dataMap.GetString("PropertyTypeStatus"); CommonClass CommonClass = new Services.CommonClass(); string QStr = ""; DataTable dt = new DataTable(); QStr = "select p.PropertyId,p.Style,p.LocationPrefered,p.PropertyType,c.TrebId,c.FirstName,c.MiddleName,c.LastName,c.EmailId from Property p,Customer c where p.CustomerId=c.CustomerId and p.PropertyId=" + PropertyId; dt = CommonClass.GetDataSet(QStr).Tables[0]; if (dt.Rows.Count > 0) { string FirstName = dt.Rows[0]["FirstName"].ToString() + " " + dt.Rows[0]["MiddleName"].ToString() + " " + dt.Rows[0]["LastName"].ToString(); string EmailId = dt.Rows[0]["EmailId"].ToString(); PropertyModel.PropertyTypeStatus = PropertyTypeStatus; PropertyModel.Style = dt.Rows[0]["Style"].ToString(); PropertyModel.PropertyType = dt.Rows[0]["PropertyType"].ToString(); PropertyModel.LocationPrefered = dt.Rows[0]["LocationPrefered"].ToString(); PropertyModel.CustomerTrebId = dt.Rows[0]["TrebId"].ToString(); SendMailToUser(FirstName, EmailId, PropertyModel); SendMailToAdmin(FirstName, EmailId, PropertyModel, Subject, Body); } }
// public INotification _Notification { get; set; } // public OpenHouseNotificationJob(INotification Notification) //{ // this._Notification = Notification;// //} public void Execute(IJobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; int AgentId = Convert.ToInt32(dataMap.GetString("AgentId")); string Flag = dataMap.GetString("Flag"); string Message = dataMap.GetString("Message"); CommonClass CommonClass = new Services.CommonClass(); string QStr = ""; DataTable dt = new DataTable(); QStr = "Select CustomerId,ParentId From Agent where AgentId= " + AgentId; dt = CommonClass.GetDataSet(QStr).Tables[0]; int count = 0; if (dt.Rows.Count > 0) { //Save Notification //Notification Notification = new Notification(); //Notification.NotificationSendBy = 1; //Notification.NotificationSendTo = Convert.ToInt32(dt.Rows[0]["CustomerId"]); //Notification.IsRead = false; //Notification.RequestMessage = Message; //_Notification.InsertNotification(Notification); // count = _Notification.GetNotifications().Where(c => c.NotificationSendTo == Convert.ToInt32(dt.Rows[0]["CustomerId"]) && c.IsRead == false).ToList().Count(); SendNotificationsToUsers(Convert.ToInt32(dt.Rows[0]["CustomerId"]), Convert.ToInt32(dt.Rows[0]["ParentId"]), Flag, count); } }
//public INotification _Notification { get; set; } //public SendNotification(INotification Notification) //{ // this._Notification = Notification;// //} public void Execute(IJobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; int PropertyId = Convert.ToInt32(dataMap.GetString("PropertyId")); string Flag = dataMap.GetString("Flag"); string Message = dataMap.GetString("Message"); CommonClass CommonClass = new Services.CommonClass(); string QStr = ""; DataTable dt = new DataTable(); QStr = "Select CustomerId From Property where PropertyId= " + PropertyId; dt = CommonClass.GetDataSet(QStr).Tables[0]; int count = 0; if (dt.Rows.Count > 0) { //Save Notification Notification Notification = new Notification(); Notification.NotificationSendBy = 1; Notification.NotificationSendTo = Convert.ToInt32(dt.Rows[0]["CustomerId"]); Notification.IsRead = false; Notification.RequestMessage = Message; SendNotificationsToUsers(Convert.ToInt32(dt.Rows[0]["CustomerId"]), Message, Flag, count); } }
//public INotification _Notification { get; set; } //public SendMessageJob(INotification Notification) //{ // this._Notification = Notification;// //} public void Execute(IJobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; int Admin = Convert.ToInt32(dataMap.GetString("AdminId")); string CustomerIds = dataMap.GetString("CustomerIds"); string Heading = dataMap.GetString("Heading"); string Message = dataMap.GetString("Message");// string ImageUrl = dataMap.GetString("ImageUrl"); string IsWithImage = dataMap.GetString("IsWithImage"); CommonClass CommonClass = new Services.CommonClass(); string QStr = ""; DataTable dt = new DataTable(); QStr = "select CustomerId from Customer where ParentId=" + Admin; dt = CommonClass.GetDataSet(QStr).Tables[0]; var Ids = CustomerIds.Split(','); int count = 0; if (Ids != null) { foreach (var CustomerId in Ids) { //Save Notification //Notification Notification = new Notification(); //Notification.NotificationSendBy = 1; //Notification.NotificationSendTo =Convert.ToInt32( CustomerId); //Notification.IsRead = false; //Notification.RequestMessage = Message; //_Notification.InsertNotification(Notification); //count = _Notification.GetNotifications().Where(c => c.NotificationSendTo == Convert.ToInt32(CustomerId) && c.IsRead == false).ToList().Count(); SendNotificationsToUsers(Convert.ToInt32(CustomerId), Heading, Message, ImageUrl, IsWithImage, count); } } else { if (dt.Rows.Count > 0) { //Save Notification //Notification Notification = new Notification(); //Notification.NotificationSendBy = 1; //Notification.NotificationSendTo = Convert.ToInt32(dt.Rows[0]["CustomerId"]); //Notification.IsRead = false; //Notification.RequestMessage = Message; //_Notification.InsertNotification(Notification); //count = _Notification.GetNotifications().Where(c => c.NotificationSendTo == Convert.ToInt32(dt.Rows[0]["CustomerId"]) && c.IsRead == false).ToList().Count(); SendNotificationsToUsers(Convert.ToInt32(dt.Rows[0]["CustomerId"]), Heading, Message, ImageUrl, IsWithImage, count); } } }
public void UpdateActiveUser(DateTime LastUpdatedOn, int CustomerId) { TimeSpan ts = DateTime.Now - Convert.ToDateTime(LastUpdatedOn); if (ts.Days > 0) { CommonClass CommonClass = new Services.CommonClass(); string QStr = ""; DataTable dt = new DataTable(); QStr = "Select * From Customer where CustomerId=" + CustomerId; dt = CommonClass.GetDataSet(QStr).Tables[0]; if (dt.Rows.Count > 0) { QStr = "update Customer set IsAvailable=0 where CustomerId=" + CustomerId; CommonClass.GetDataSet(QStr); } } }
public void Execute(IJobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; //check which person shutdown your phone without logout. CommonClass CommonClass = new Services.CommonClass(); string QStr = ""; DataTable dt = new DataTable(); QStr = "Select * From Customer"; dt = CommonClass.GetDataSet(QStr).Tables[0]; if (dt.Rows.Count > 0) { if (dt.Rows[0]["LastUpdatedOn"] != DBNull.Value) { UpdateActiveUser(Convert.ToDateTime(dt.Rows[0]["LastUpdatedOn"]), Convert.ToInt32(dt.Rows[0]["CustomerId"])); } } //end }
public void SendNotificationsToUsers(int CustomerId, string Heading, string Message, string ImageUrl, string IsWithImage, int count) { string Flag = "15"; //send notification // var Customers = _CustomerService.GetCustomers().Where(c => c.CustomerId != CustomerId && c.IsActive == true).ToList(); CommonClass CommonClass = new Services.CommonClass(); string QStr = ""; DataTable dt = new DataTable(); QStr = "Select * From Customer where CustomerId = " + CustomerId + " and IsActive=1"; dt = CommonClass.GetDataSet(QStr).Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { var ApplicationId = dr["ApplicationId"].ToString(); var DeviceType = dr["DeviceType"].ToString(); //var IsNotificationSoundOn = Convert.ToBoolean(dr["IsNotificationSoundOn"]); var IsNotificationSoundOn = true; string sql = "insert into [notification](RequestMessage,NotificationSendTo,NotificationSendBy,Flag,IsRead) values(@RequestMessage,@NotificationSendTo,@NotificationSendBy,@Flag,@IsRead)"; try { string constring = ConfigurationManager.ConnectionStrings["DataContext"].ConnectionString; using (SqlConnection con = new SqlConnection(constring)) { using (SqlCommand cmd = new SqlCommand(sql, con)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@RequestMessage", Message); cmd.Parameters.AddWithValue("@NotificationSendTo", dr["CustomerId"].ToString()); cmd.Parameters.AddWithValue("@NotificationSendBy", CustomerId); cmd.Parameters.AddWithValue("@Flag", Flag); cmd.Parameters.AddWithValue("@IsRead", false); con.Open(); int rowsAffected = cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); con.Dispose(); } } } catch (Exception ex) { } if (ApplicationId != null && ApplicationId != "") { bool NotificationStatus = true; string JsonMessage = "{\"Flag\":\"" + Flag + "\",\"Message\":\"" + Message + "\",\"Heading\":\"" + Heading + "\",\"ImageUrl\":\"" + ImageUrl + "\",\"IsWithImage\":\"" + IsWithImage + "\"}"; if (DeviceType == EnumValue.GetEnumDescription(EnumValue.DeviceType.Android)) { CommonCls.SendGCM_Notifications(ApplicationId, JsonMessage, true); } else { string constring = ConfigurationManager.ConnectionStrings["DataContext"].ConnectionString; using (SqlConnection con = new SqlConnection(constring)) { con.Open(); using (SqlCommand thisCommand = new SqlCommand("SELECT COUNT(*) FROM Notification where NotificationSendTo=@NotificationSendTo and isread=0 ", con)) { thisCommand.Parameters.AddWithValue("@NotificationSendTo", Convert.ToInt32(dr["CustomerId"].ToString())); count = (int)(thisCommand.ExecuteScalar()); } con.Close(); con.Dispose(); } //Dictionary<string, object> Dictionary = new Dictionary<string, object>(); //Dictionary.Add("Flag", Flag); //Dictionary.Add("Message", Message); //NotificationStatus = PushNotificatinAlert.SendPushNotification(ApplicationId, Message, Flag.ToString(), JsonMessage, Dictionary, 1, Convert.ToBoolean(IsNotificationSoundOn)); CommonCls.TestSendFCM_Notifications(ApplicationId, JsonMessage, Message, count, true); } } } } }
public void Execute(IJobExecutionContext context) { NewsletterModel model = new NewsletterModel(); JobDataMap dataMap = context.JobDetail.JobDataMap; int Admin = Convert.ToInt32(dataMap.GetString("AdminId")); model.CustomerIds = dataMap.GetString("CustomerIds"); model.P1 = dataMap.GetString("P1"); model.P2 = dataMap.GetString("P2"); model.P3 = dataMap.GetString("P3"); model.P4 = dataMap.GetString("P4"); model.P5 = dataMap.GetString("P5"); model.P6 = dataMap.GetString("P6"); model.P7 = dataMap.GetString("P7"); model.PP1 = dataMap.GetString("PP1"); model.PP2 = dataMap.GetString("PP2"); model.PP3 = dataMap.GetString("PP3"); model.PP4 = dataMap.GetString("PP4"); model.PP5 = dataMap.GetString("PP5"); model.PP6 = dataMap.GetString("PP6"); model.PG1 = dataMap.GetString("PG1"); model.PG2 = dataMap.GetString("PG2"); model.PG3 = dataMap.GetString("PG3"); model.PG4 = dataMap.GetString("PG4"); model.PG5 = dataMap.GetString("PG5"); model.PG6 = dataMap.GetString("PG6"); model.PG7 = dataMap.GetString("PG7"); model.PPG1 = dataMap.GetString("PPG1"); model.PPG2 = dataMap.GetString("PPG2"); model.PPG3 = dataMap.GetString("PPG3"); model.PPG4 = dataMap.GetString("PPG4"); model.PPG5 = dataMap.GetString("PPG5"); model.PPG6 = dataMap.GetString("PPG6"); model.PropertyPhoto = dataMap.GetString("PropertyPhoto");// model.AdminLogo = dataMap.GetString("AdminLogo"); model.FirstContent = dataMap.GetString("FirstContent"); model.SecondContent = dataMap.GetString("SecondContent"); model.ThirdContent = dataMap.GetString("ThirdContent"); model.TemplateType = dataMap.GetString("TemplateType"); CommonClass CommonClass = new Services.CommonClass(); string QStr = ""; DataTable dt = new DataTable(); QStr = "select CustomerId from Customer where ParentId=" + Admin; dt = CommonClass.GetDataSet(QStr).Tables[0]; var Ids = model.CustomerIds.Split(','); if (Ids != null) { foreach (var CustomerId in Ids) { try { QStr = ""; DataTable dt2 = new DataTable(); QStr = "Select * From Customer where CustomerId = " + CustomerId + " and IsActive=1"; dt2 = CommonClass.GetDataSet(QStr).Tables[0]; if (dt2.Rows.Count > 0) { foreach (DataRow dr in dt2.Rows) { var EmailId = dr["EmailId"].ToString(); //Send mail MailMessage mail = new MailMessage(); string FromEmailID = WebConfigurationManager.AppSettings["FromEmailID"]; string FromEmailPassword = WebConfigurationManager.AppSettings["FromEmailPassword"]; SmtpClient smtpClient = new SmtpClient(ConfigurationManager.AppSettings["SmtpServer"]); int _Port = Convert.ToInt32(WebConfigurationManager.AppSettings["Port"].ToString()); Boolean _UseDefaultCredentials = Convert.ToBoolean(WebConfigurationManager.AppSettings["UseDefaultCredentials"].ToString()); Boolean _EnableSsl = Convert.ToBoolean(WebConfigurationManager.AppSettings["EnableSsl"].ToString()); mail.To.Add(new MailAddress(EmailId)); mail.From = new MailAddress(FromEmailID); mail.Subject = "News Letter"; string msgbody = ""; var Template = ""; if (model.TemplateType == "first_NwsLtr") { Template = "Templates/FirstTemplate.html"; } else if (model.TemplateType == "second_NwsLtr") { Template = "Templates/SecondTemplate.html"; } else if (model.TemplateType == "thirld_NwsLtr") { Template = "Templates/ThirldNewsLetter.html"; } else if (model.TemplateType == "fourth_NwsLtr") { Template = "Templates/FourthNewsLetter.html"; } else if (model.TemplateType == "fifth_NwsLtr") { Template = "Templates/FifthNewsLetter.html"; } else if (model.TemplateType == "sixth_NwsLtr") { Template = "Templates/SixthNewsLetter.html"; } // using (StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath(Template))) using (StreamReader reader = new StreamReader(Path.Combine(HttpRuntime.AppDomainAppPath, Template))) { msgbody = reader.ReadToEnd(); //Replace UserName and Other variables available in body Stream msgbody = msgbody.Replace("{PropertyPhoto}", model.PropertyPhoto); msgbody = msgbody.Replace("{logopath}", model.AdminLogo); msgbody = msgbody.Replace("{SecondContent}", model.SecondContent); msgbody = msgbody.Replace("{ThirdContent}", model.ThirdContent); if (model.TemplateType == "first_NwsLtr") { //first template editing msgbody = FirstNewsletter(model, msgbody); } else if (model.TemplateType == "second_NwsLtr") { //second template editing msgbody = SecondNewsletter(model, msgbody); } } mail.BodyEncoding = System.Text.Encoding.UTF8; mail.SubjectEncoding = System.Text.Encoding.UTF8; System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(System.Text.RegularExpressions.Regex.Replace(msgbody, @"<(.|\n)*?>", string.Empty), null, "text/plain"); System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(msgbody, null, "text/html"); mail.AlternateViews.Add(plainView); mail.AlternateViews.Add(htmlView); // mail.Body = msgbody; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Host = "smtp.gmail.com"; //_Host; smtp.Port = _Port; //smtp.UseDefaultCredentials = _UseDefaultCredentials; smtp.Credentials = new System.Net.NetworkCredential(FromEmailID, FromEmailPassword);// Enter senders User name and password smtp.EnableSsl = _EnableSsl; smtp.Send(mail); } } } catch (Exception ex) { string ErrorMsg = ex.ToString(); } } } }