using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcReCaptcha;

namespace BinBackedUp.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }
        public ActionResult FreeTrial()
        {
            return View();
        }


        [CaptchaValidator]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult FreeTrial(FormCollection callback, bool captchaValid)
        {

                //process the enquiry form
                
            if (callback["YourName"].Trim().Length == 0)
                    ModelState.AddModelError("YourName", "");
            if (callback["Email"].Trim().Length == 0)
                    ModelState.AddModelError("Email", "");
            if (!captchaValid)
	                ModelState.AddModelError("Captcha", "You did not type the verification word correctly. Please try again.");


                if (!ModelState.IsValid)
                {
                    return View();
                }

                else
                {
                    string message = Environment.NewLine + "<BR>ContactName:" + callback["YourName"];
                    message += Environment.NewLine + "<BR>CompanyName:" + callback["CompanyName"];
                    message += Environment.NewLine + "<BR>Business Title:" + callback["business_title"];
                    message += Environment.NewLine + "<BR>Email:" + callback["Email"];
                    message += Environment.NewLine + "<BR>Telephone:" + callback["Telephone"];
                    message += Environment.NewLine + "<BR>Business Sector:" + callback["business_sector"];
                    message += Environment.NewLine + "<BR>Area of Interest:" + callback["area_of_interest"];
                    message += Environment.NewLine + "<BR>Comments:" + callback["Comments"];

                    string clientmessage = "Good News! You have a new free trial request from the website." + message;

                    //email the client
                    System.Net.Mail.MailMessage clientMail = new System.Net.Mail.MailMessage();
                    clientMail.From = new System.Net.Mail.MailAddress("website@binbackedup.co.uk");
                    clientMail.To.Add("admin@binbackedup.co.uk");
                    clientMail.Subject = "Website:  Free Trial Request";
                    clientMail.Body = clientmessage;
                    clientMail.IsBodyHtml = true;
                    System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("localhost");
                    client.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                    client.Send(clientMail);

                    return Redirect("/thankyou");

                }
          
        }

        public ActionResult HowitWorks()
        {
            return View();
        }
        public ActionResult Login()
        {
            return View();
        }
        public ActionResult Products()
        {
            return View();
        }
        public ActionResult ROI()
        {
            return View();
        }
        public ActionResult Support()
        {
            return View();
        }

        public ActionResult Thankyou()
        {
            return View();
        }
    }
}
