public ProspectManagementModel GetProspectDetails(int id)
        {
            ShomaRMEntities         db    = new ShomaRMEntities();
            ProspectManagementModel model = new ProspectManagementModel();

            model.CreatedDate = DateTime.Now;
            var prospectData = db.tbl_Prospect.Where(p => p.PID == id).FirstOrDefault();

            if (prospectData != null)
            {
                model.PID               = prospectData.PID;
                model.FirstName         = prospectData.FirstName;
                model.LastName          = prospectData.LastName;
                model.PhoneNo           = prospectData.PhoneNo;
                model.EmailId           = prospectData.EmailId;
                model.State             = prospectData.State;
                model.City              = prospectData.City;
                model.Address           = prospectData.Address;
                model.Message           = prospectData.Message;
                model.HavingPets        = prospectData.HavingPets;
                model.PropertyID        = prospectData.PropertyID;
                model.UnitID            = prospectData.UnitID;
                model.CreatedBy         = 1;
                model.CreatedDate       = prospectData.CreatedDate;
                model.VisitDateTime     = prospectData.VisitDateTime;
                model.RequiredDate      = prospectData.RequiredDate;
                model.MarketSource      = prospectData.MarketSource;
                model.PetsDetails       = prospectData.PetsDetails;
                model.AssignAgentID     = prospectData.AssignAgentId != null ? prospectData.AssignAgentId.Value : 0;
                model.AppointmentStatus = prospectData.AppointmentStatus != null ? prospectData.AppointmentStatus.Value : 0;
                model.OutlookID         = prospectData.OutlookID;
            }

            return(model);
        }
        public string SaveProspectForm(ProspectManagementModel model)
        {
            string          msg         = "";
            ShomaRMEntities db          = new ShomaRMEntities();
            var             prospData   = db.tbl_Prospect.Where(p => p.PID == model.PID).FirstOrDefault();
            string          message     = "";
            string          phonenumber = prospData.PhoneNo;
            long            assignAgeID = prospData.AssignAgentId != null?Convert.ToInt64(prospData.AssignAgentId) : 0;

            if (model.PID != 0)
            {
                if (prospData != null)
                {
                    prospData.AssignAgentId     = model.AssignAgentID;
                    prospData.AppointmentStatus = model.AppointmentStatus;
                    prospData.VisitDateTime     = model.VisitDateTime;
                    db.SaveChanges();
                    msg = "Progress Saved";

                    if (model.AppointmentStatus != 3)
                    {
                        if (assignAgeID != model.AssignAgentID)
                        {
                            var info = db.tbl_Login.Where(p => p.UserID == prospData.AssignAgentId).FirstOrDefault();

                            string reportHTML = "";
                            string filePath   = HttpContext.Current.Server.MapPath("~/Content/Templates/");
                            reportHTML = System.IO.File.ReadAllText(filePath + "EmailTemplateAmenity.html");
                            reportHTML = reportHTML.Replace("[%ServerURL%]", ServerURL);
                            reportHTML = reportHTML.Replace("[%TodayDate%]", DateTime.Now.ToString("dddd,dd MMMM yyyy"));

                            string emailBody = "";
                            emailBody += "<p style=\"margin-bottom: 0px;\">Dear " + prospData.FirstName + " " + prospData.LastName + "</p>";
                            emailBody += "<p style=\"margin-bottom: 0px;\">This is a confirmation email to your appointment with  <b>" + info.FirstName + " " + info.LastName + " </b> Dated on <b>" + model.RequiredDateText + "</b> at office. If you have queries or require any clarifications or any assistance in finding the location  please do not hesitate to contact me at <i>" + info.CellPhone + "</i>, " + info.Email + ". I genuinely appreciate a prompt confirmation from your side. Looking forward to meeting you there.</p>";
                            reportHTML = reportHTML.Replace("[%EmailBody%]", emailBody);

                            //reportHTML = reportHTML.Replace("[%TenantName%]", prospData.FirstName + " " + prospData.LastName);
                            //reportHTML = reportHTML.Replace("[%EmailBody%]", " <p style='font-size: 14px; line-height: 21px; text-align: justify; margin: 0;'>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; This is a confirmation email to your appointment with  <b>" + info.FirstName + " " + info.LastName + " </b> Dated on <b>" + model.RequiredDateText + "</b> at office. If you have queries or require any clarifications or any assistance in finding the location  please do not hesitate to contact me at <i>" + info.CellPhone + "</i>, " + info.Email + ". I genuinely appreciate a prompt confirmation from your side. Looking forward to meeting you there. </p>");
                            //reportHTML = reportHTML.Replace("[%LeaseNowButton%]", "");

                            string body = reportHTML;
                            new EmailSendModel().SendEmail(prospData.EmailId, "Your Appointment is Confirmed", body);

                            message = "This is a confirmation message for your appointment. Please check the email for detail.";
                            if (SendMessage == "yes")
                            {
                                if (!string.IsNullOrWhiteSpace(phonenumber))
                                {
                                    new TwilioService().SMS(phonenumber, message);
                                }
                            }

                            string reportHTMLAgent = "";
                            string filePathAg      = HttpContext.Current.Server.MapPath("~/Content/Templates/");
                            reportHTMLAgent = System.IO.File.ReadAllText(filePathAg + "EmailTemplateAmenity.html");
                            reportHTMLAgent = reportHTMLAgent.Replace("[%ServerURL%]", ServerURL);
                            reportHTMLAgent = reportHTMLAgent.Replace("[%TodayDate%]", DateTime.Now.ToString("dddd,dd MMMM yyyy"));

                            string emailBodyAgent = "";
                            emailBodyAgent += "<p style=\"margin-bottom: 0px;\">Dear " + info.FirstName + " " + info.LastName + "</p>";
                            emailBodyAgent += "<p style=\"margin-bottom: 0px;\">Please be informed that a meeting has been scheduled  with <b> " + prospData.FirstName + " " + prospData.LastName + " </b> Dated on  <b>" + model.RequiredDateText + "</b>.We shall meet at office . Please inform me if you'd like to add anything to list above. All suggestions and questions are highly welcomed.Kindly signal that you received this email and confirm your attendance.Please make sure to be on time as you always do.Looking forward to seeing you there.</p>";
                            reportHTMLAgent = reportHTMLAgent.Replace("[%EmailBody%]", emailBodyAgent);

                            //reportHTML = reportHTML.Replace("[%EmailHeader%]", "Application Submission");
                            //reportHTMLAgent = reportHTMLAgent.Replace("[%TenantName%]", info.FirstName + " " + info.LastName);
                            //reportHTMLAgent = reportHTMLAgent.Replace("[%EmailBody%]", " <p style='font-size: 14px; line-height: 21px; text-align: justify; margin: 0;'>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Please be informed that a meeting has been scheduled  with <b> " + prospData.FirstName + " " + prospData.LastName + " </b> Dated on  <b>" + model.RequiredDateText + "</b>.We shall meet at office . Please inform me if you'd like to add anything to list above. All suggestions and questions are highly welcomed.Kindly signal that you received this email and confirm your attendance.Please make sure to be on time as you always do.Looking forward to seeing you there.</p>");
                            //reportHTMLAgent = reportHTMLAgent.Replace("[%LeaseNowButton%]", "");

                            string bodyAg = reportHTMLAgent;
                            new EmailSendModel().SendEmail(info.Email, "Appointment for " + prospData.FirstName + " " + prospData.LastName + " on " + model.RequiredDateText, bodyAg);

                            string message1 = "Please to be informed that a meeting has been scheduled. Please check the email for detail.";

                            if (SendMessage == "yes")
                            {
                                if (!string.IsNullOrWhiteSpace(phonenumber))
                                {
                                    new TwilioService().SMS(phonenumber, message1);
                                }
                            }
                        }
                    }
                    else
                    {
                        var info = db.tbl_Login.Where(p => p.UserID == prospData.AssignAgentId).FirstOrDefault();

                        string reportHTML = "";
                        string filePath   = HttpContext.Current.Server.MapPath("~/Content/Templates/");
                        reportHTML = System.IO.File.ReadAllText(filePath + "EmailTemplateAmenity.html");

                        reportHTML = reportHTML.Replace("[%ServerURL%]", ServerURL);
                        reportHTML = reportHTML.Replace("[%TodayDate%]", DateTime.Now.ToString("dddd,dd MMMM yyyy"));

                        string emailBody = "";
                        emailBody += "<p style=\"margin-bottom: 0px;\">Dear " + prospData.FirstName + " " + prospData.LastName + "</p>";
                        emailBody += "<p style=\"margin-bottom: 0px;\">" + info.FirstName + " " + info.LastName + " was unfortunately not able to make the meeting, please contact us back so we can schedule another tour at your earliest convenience.</p>";
                        reportHTML = reportHTML.Replace("[%EmailBody%]", emailBody);

                        //reportHTML = reportHTML.Replace("[%TenantName%]", prospData.FirstName + " " + prospData.LastName);
                        //reportHTML = reportHTML.Replace("[%EmailBody%]", " <p style='font-size: 14px; line-height: 21px; text-align: justify; margin: 0;'>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; " + info.FirstName + " " + info.LastName + " was unfortunately not able to make the meeting, please contact us back so we can schedule another tour at your earliest convenience. </p>");
                        //reportHTML = reportHTML.Replace("[%LeaseNowButton%]", "");

                        string body = reportHTML;
                        new EmailSendModel().SendEmail(prospData.EmailId, "Your Appointment is Cancelled", body);

                        message = "This is a cancellation message for your shoma appointment. Please check the email for detail.";
                        if (SendMessage == "yes")
                        {
                            if (!string.IsNullOrWhiteSpace(phonenumber))
                            {
                                new TwilioService().SMS(phonenumber, message);
                            }
                        }
                    }
                }
                ;
            }
            return(msg);
        }
        public List <ProspectManagementModel> GetProspectList(DateTime FromDate, DateTime ToDate)
        {
            ShomaRMEntities db = new ShomaRMEntities();
            List <ProspectManagementModel> lstpr = new List <ProspectManagementModel>();

            try
            {
                DataTable dtTable = new DataTable();
                using (var cmd = db.Database.Connection.CreateCommand())
                {
                    db.Database.Connection.Open();
                    cmd.CommandText = "usp_GetProspectList";
                    cmd.CommandType = CommandType.StoredProcedure;

                    DbParameter paramF = cmd.CreateParameter();
                    paramF.ParameterName = "FromDate";
                    paramF.Value         = FromDate;
                    cmd.Parameters.Add(paramF);

                    DbParameter paramC = cmd.CreateParameter();
                    paramC.ParameterName = "ToDate";
                    paramC.Value         = ToDate;
                    cmd.Parameters.Add(paramC);

                    DbDataAdapter da = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateDataAdapter();
                    da.SelectCommand = cmd;
                    da.Fill(dtTable);
                    db.Database.Connection.Close();
                }
                foreach (DataRow dr in dtTable.Rows)
                {
                    ProspectManagementModel pr = new ProspectManagementModel();
                    DateTime?createdDate       = null;
                    try
                    {
                        createdDate = Convert.ToDateTime(dr["CreatedDate"].ToString());
                    }
                    catch
                    {
                    }
                    DateTime?visitDate = null;
                    try
                    {
                        visitDate = Convert.ToDateTime(dr["VisitDateTime"].ToString());
                    }
                    catch
                    {
                    }
                    DateTime?requiredDate = null;
                    try
                    {
                        requiredDate = Convert.ToDateTime(dr["RequiredDate"].ToString());
                    }
                    catch
                    {
                    }
                    pr.PID               = Convert.ToInt32(dr["PID"].ToString());
                    pr.FirstName         = dr["FirstName"].ToString();
                    pr.LastName          = dr["LastName"].ToString();
                    pr.PhoneNo           = dr["PhoneNo"].ToString();
                    pr.EmailId           = dr["EmailId"].ToString();
                    pr.StateName         = dr["StateName"].ToString();
                    pr.CityName          = dr["CityName"].ToString();
                    pr.Address           = dr["Address"].ToString();
                    pr.Message           = dr["Message"].ToString();
                    pr.HavingPets        = Convert.ToInt32(dr["HavingPets"].ToString());
                    pr.UnitID            = Convert.ToInt32(dr["UnitID"].ToString());
                    pr.CreatedDateText   = createdDate == null ? "" : createdDate.Value.ToString("MM/dd/yyy");
                    pr.VisitDateTimeText = visitDate == null ? "" : visitDate.Value.ToString("MM/dd/yyy");
                    pr.RequiredDateText  = requiredDate == null ? "" : requiredDate.Value.ToString("MM/dd/yyy");
                    lstpr.Add(pr);
                }
                db.Dispose();
                return(lstpr.ToList());
            }
            catch (Exception ex)
            {
                db.Database.Connection.Close();
                throw ex;
            }
        }