/// <summary>
        /// Calling this will send an email to a specified agent for a general query
        /// </summary>
        /// <returns></returns>
        public ActionResult SendEmailContact()
        {
            var post = Request.Form;

            int agent_id = int.Parse(post["agent_id"]);

            string client_msg = post["body"]; // todo escape string en check security

            string client_name = post["client_name"];
            string client_phone = post["client_phone"];
            string client_email = post["client_email"];

            string subject = "General query ";

            string body = "<html><h3>Curious Client</h3>";
            body += "<h2>" + client_name + "</h2>";
            body += "<p>email: " + client_email + "</p>";
            body += "</br><p>phone number: " + client_phone + "</p>";
            body += "</br><h3>Client Message: </h3>";
            body += "</br><p>" + client_msg + "</p></html>";

            // Read agent email
            MySqlConnection connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
            connection.Open();

            MySqlCommand command = connection.CreateCommand();
            command.CommandText = "Select Agent_Name, Agent_Surname, Agent_Phone, Agent_Email from Agent where Agent_Id=@agent_id";
            command.Parameters.AddWithValue("@agent_id", agent_id);

            MySqlDataReader reader = command.ExecuteReader();

            reader.Read();

            string agent_email = reader.GetString("Agent_Email");

            string from = ConfigurationManager.AppSettings["webEmail"];

            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(from, agent_email);
            msg.Subject = subject;
            msg.Body = body;
            msg.IsBodyHtml = true;

            StandardSMTPEmailer emailer = new StandardSMTPEmailer();
            emailer.Send(msg);

            return Redirect(Request.UrlReferrer.ToString());
        }
        /// <summary>
        /// Calling this will send an email for the interested buyer to an agent with the parameters specified in post
        /// </summary>
        /// <returns></returns>
        public ActionResult SendEmail()
        {
            var post = Request.Form;

            int agent_id = int.Parse(post["agent_id"]);

            string client_msg = post["body"]; // todo escape string en check security

            //int property_id = int.Parse(post["property_id"]);
            int listing_id = int.Parse(post["listing_id"]);

            string client_name = post["client_name"];
            string client_phone = post["client_phone"];
            string client_email = post["client_email"];

            string link = Url.Action("Residence", "Estates") + "?id=" + listing_id;
            string subject = string.Format("Interest in " + listing_id);

            string body = string.Format("<html>Interest in <a href=\"{0}\">listing {1}</a><br><h3>Interested buyer</h3>", link, listing_id);
            body += "<h2>" + client_name + "</h2>";

            body += string.Format("<a href=\"{0}\" mailto>email: {0} </p>", client_email);
            body += "</br><p>phone number: " + client_phone + "</p>";
            body += "</br><h3>Client Message: </h3>";
            body += "</br><p>" + client_msg + "</p></html>";

            // Read agent email
            MySqlConnection connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
            connection.Open();

            MySqlCommand command = connection.CreateCommand();
            command.CommandText = "Select Agent_Name, Agent_Surname, Agent_Phone, Agent_Email from Agent where Agent_Id=@agent_id";
            command.Parameters.AddWithValue("@agent_id", agent_id);

            MySqlDataReader reader = command.ExecuteReader();

            reader.Read();
            if(!reader.HasRows)
            {
                return null;
            }

            string agent_email = reader.GetString("Agent_Email");

            string from = ConfigurationManager.AppSettings["webEmail"];

            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(from, agent_email);
            msg.Subject = subject;
            msg.Body = body;
            msg.IsBodyHtml = true;

            StandardSMTPEmailer emailer = new StandardSMTPEmailer();
            emailer.Send(msg);

            return Redirect(Request.UrlReferrer.ToString());
        }