public ActionResult Submit(RegisterTreeFormViewModel model)
        {
            if (ModelState.IsValid)
            {
                WebImage photo       = null;
                var      newFileName = "";
                var      imagePath   = "";

                if (model.Files != null)
                {
                    photo = WebImage.GetImageFromRequest();
                    if (photo != null)
                    {
                        newFileName = Path.GetFileName(photo.FileName);
                        imagePath   = @"\UploadedFiles\" + DateTime.UtcNow.ToString("yyyyMMddHHmmss") + "-" + newFileName;
                        photo.Save(@"~\" + imagePath);
                        TempData["imgLoc"] = imagePath.Replace("\\", "/");
                    }
                }
                SendEmail(model);
                CreateNode(model);
                TempData["ContactSuccess"] = true;
                return(RedirectToCurrentUmbracoPage());
            }
            else
            {
                if (!ReCaptchaPassed(Request.Form["foo"]))
                {
                    ModelState.AddModelError(string.Empty, "You failed the CAPTCHA.");
                    return(CurrentUmbracoPage());
                }
                return(CurrentUmbracoPage());
            }
        }
        private void SendEmail(RegisterTreeFormViewModel model)
        {
            MailAddress from    = new MailAddress("*****@*****.**", "West Midlands Combined Authority");
            MailAddress to      = new MailAddress("*****@*****.**", "West Midlands Combined Authority");
            MailMessage message = new MailMessage(from, to);

            message.Subject = string.Format("Someone has planted a tree");
            var imgLoc = "https://beta.wmca.org.uk" + TempData["imgLoc"];

            message.Body       = "<p><b>Name: </b>" + model.FirstName + "&nbsp;" + model.LastName + "</p><p><b>Email: </b>" + model.Email + "</p><p><b>Location: </b>" + model.Location + "</p><p><b>Latitude: </b>" + model.Latitude + "</p><p><b>Longitude: </b>" + model.Longitude + "</p><p><b>Image: </b>" + "<a href=\"" + imgLoc + "\" />" + imgLoc + "</a>" + "</p><p><b>Join Mailing List: </b>" + model.MailingList + "</p>";
            message.IsBodyHtml = true;
            SmtpClient client = new SmtpClient();

            client.Host        = "in-v3.mailjet.com";
            client.Credentials = new System.Net.NetworkCredential("66b3bdc8b4d8c8607a56e3a66ffc0c46", "22a429a0d57ececf742ac017898e8bf7");
            //SmtpClient client = new SmtpClient("127.0.0.1", 25);
            client.Send(message);
        }
        private void CreateNode(RegisterTreeFormViewModel model)
        {
            var parent = _contentService.GetById(1694);
            var udiId  = parent.GetUdi();

            var request = _contentService.CreateContent($"Tree - {model.DatePlanted}", udiId, "tree");

            request.SetValue("who", model.WhoType);
            request.SetValue("firstName", model.FirstName);
            request.SetValue("lastName", model.LastName);
            request.SetValue("organisationName", model.OrgName);
            request.SetValue("datePlanted", model.DatePlanted);
            request.SetValue("howManyTreesDidYouPlant", model.TreesPlanted);
            request.SetValue("location", model.Location);
            request.SetValue("latitude", model.Latitude);
            request.SetValue("longitude", model.Longitude);
            request.SetValue("treeType", model.TreeType);
            request.SetValue("image", TempData["imgLoc"]);

            _contentService.Save(request);
        }