From b72de557c85eaca5256fd1919c6a952f87e986a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Windmuller?= Date: Thu, 1 Mar 2018 11:46:24 -0700 Subject: [PATCH] Adding example code --- Contact.xml | 134 ++++++++++++++++++++++++++ Web2Rpm/Controllers/HomeController.cs | 79 +++++++++++++++ Web2Rpm/Models/Lead.cs | 24 +++++ Web2Rpm/Models/RpmProcess.cs | 22 +++++ Web2Rpm/Views/Home/Error.cshtml | 4 + Web2Rpm/Views/Home/Index.cshtml | 71 ++++++++++++++ Web2Rpm/Views/Home/Sent.cshtml | 12 +++ 7 files changed, 346 insertions(+) create mode 100644 Contact.xml create mode 100644 Web2Rpm/Controllers/HomeController.cs create mode 100644 Web2Rpm/Models/Lead.cs create mode 100644 Web2Rpm/Models/RpmProcess.cs create mode 100644 Web2Rpm/Views/Home/Error.cshtml create mode 100644 Web2Rpm/Views/Home/Index.cshtml create mode 100644 Web2Rpm/Views/Home/Sent.cshtml diff --git a/Contact.xml b/Contact.xml new file mode 100644 index 0000000..c8310b7 --- /dev/null +++ b/Contact.xml @@ -0,0 +1,134 @@ + + + Contact + Mar 1,2018 + true + + 4 + True + + + false + Add repeating fields + + false + false + true + true + true + + Edit + Edit + Start + {"AgentUserEmailAccess":false,"CustomerUserEmailAccess":false,"AgentUserPermission":1,"AgentUserChangeStatus":false,"AgentUserAddAction":false,"CustomerUserPermission":1,"CustomerUserChangeStatus":false,"CustomerUserAddAction":false} + + [] + {"IsEnabled":false,"Name":"Signatures","IsHandDrawn":false,"ShowCompany":false,"Instruction":""} + + + Text + {"PatternEnabled":false,"Pattern":"","Instruction":""} + 1 + {"Width":"2","Order":1} + false + 40639 + + + Text + {"PatternEnabled":false,"Pattern":"","Instruction":""} + 3 + {"Width":"1","Order":-1} + false + 40640 + + + Text + {"PatternEnabled":false,"Pattern":"","Instruction":""} + 4 + {"Width":"1","Order":-1} + false + 40641 + + + Text + {"PatternEnabled":false,"Pattern":"","Instruction":""} + 5 + {"Width":"1","Order":-1} + false + 40642 + + + Text + {"PatternEnabled":false,"Pattern":"","Instruction":""} + 6 + {"Width":"1","Order":-1} + false + 40643 + + + Text + {"PatternEnabled":false,"Pattern":"","Instruction":""} + 7 + {"Width":"2","Order":-1} + false + 40644 + + + + + New + false + true + true + true + true + {"ShowLink":false} + + + + + + Number + Owner + Action due for me + Started + Started by + Modified + Modified by + Files + + + Number + Owner + Action due for me + Started + Started by + Modified + Modified by + + + Number + Owner + Action due for me + Started + Started by + Modified + Modified by + + + Form title + Done + Due + Assignee + Description + Result + + + + + + + + + + \ No newline at end of file diff --git a/Web2Rpm/Controllers/HomeController.cs b/Web2Rpm/Controllers/HomeController.cs new file mode 100644 index 0000000..b2cc8ec --- /dev/null +++ b/Web2Rpm/Controllers/HomeController.cs @@ -0,0 +1,79 @@ +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; +using Web2Rpm.Models; +using Newtonsoft.Json; +using System.Net.Http; +using System.Text; +using System; + +namespace Web2Rpm.Controllers +{ + public class HomeController : Controller + { + // CONFIGURATION + private const string API_KEY = "fffff-fffff-fffff-fffff-fffff"; + private const string API_URL = "http://api.cubedms.com/rpm/api2.svc/ProcFormAdd"; + private const int API_PROCESSID = -1; + + // GET: // + public IActionResult Index() + { + return View(); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Index(Lead leadForm) + { + if (!ModelState.IsValid) + { + return View(leadForm); + } + + // Make the RPM form object + RpmProcess rpmLead = new RpmProcess(); + rpmLead.ProcessID = API_PROCESSID; + + // Add the fields + rpmLead.Form.Fields.Add(new RpmField() { Field = "Contact Name (First & Last)", Value = leadForm.Name }); + rpmLead.Form.Fields.Add(new RpmField() { Field = "Primary Contact Number", Value = leadForm.Phone }); + rpmLead.Form.Fields.Add(new RpmField() { Field = "Email", Value = leadForm.Email }); + rpmLead.Form.Fields.Add(new RpmField() { Field = "Company", Value = leadForm.Company }); + rpmLead.Form.Fields.Add(new RpmField() { Field = "Website", Value = leadForm.Website }); + rpmLead.Form.Fields.Add(new RpmField() { Field = "Web Lead Comment", Value = leadForm.Comment }); + + // Turn into JSON + string body = JsonConvert.SerializeObject(rpmLead); + + // Send + HttpClient client = new HttpClient(); + try + { + var content = new StringContent(body, Encoding.UTF8, "application/json"); + content.Headers.Add("RpmApiKey", API_KEY); + var response = await client.PostAsync(API_URL, content); + } + catch (HttpRequestException hre) + { + return RedirectToAction("Error"); + } + catch (Exception ex) + { + return RedirectToAction("Error"); + } + + // Change the page + return RedirectToAction("Sent"); + } + + public ActionResult Sent() + { + return View(); + } + + public ActionResult Error() + { + return View(); + } + } +} diff --git a/Web2Rpm/Models/Lead.cs b/Web2Rpm/Models/Lead.cs new file mode 100644 index 0000000..254f1ef --- /dev/null +++ b/Web2Rpm/Models/Lead.cs @@ -0,0 +1,24 @@ +using System.ComponentModel.DataAnnotations; + +namespace Web2Rpm.Models +{ + public class Lead + { + [Required] + public string Company { get; set; } + + [Required] + public string Name { get; set; } + + [Required, EmailAddress] + public string Email { get; set; } + + public string Phone { get; set; } + + public string Website { get; set; } + + [Display(Name = "Questions / Comments")] + public string Comment { get; set; } + + } +} diff --git a/Web2Rpm/Models/RpmProcess.cs b/Web2Rpm/Models/RpmProcess.cs new file mode 100644 index 0000000..bf54442 --- /dev/null +++ b/Web2Rpm/Models/RpmProcess.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Web2Rpm.Models +{ + public class RpmProcess + { + public int ProcessID; + public RpmForm Form = new RpmForm(); + } + public class RpmField + { + public string Field { get; set; } + public string Value { get; set; } + } + public class RpmForm + { + public List Fields = new List(); + } +} diff --git a/Web2Rpm/Views/Home/Error.cshtml b/Web2Rpm/Views/Home/Error.cshtml new file mode 100644 index 0000000..ac5231a --- /dev/null +++ b/Web2Rpm/Views/Home/Error.cshtml @@ -0,0 +1,4 @@ +@{ + ViewData["Title"] = "Error"; +} +

Error

diff --git a/Web2Rpm/Views/Home/Index.cshtml b/Web2Rpm/Views/Home/Index.cshtml new file mode 100644 index 0000000..aab412c --- /dev/null +++ b/Web2Rpm/Views/Home/Index.cshtml @@ -0,0 +1,71 @@ +@{ + ViewData["Title"] = "Contact"; + var countries = new SelectList(new List { + new SelectListItem { Text = "United States", Value = "United States" }, new SelectListItem { Text = "Canada", Value = "Canada" }, new SelectListItem { Text = "Mexico", Value = "Mexico" }, new SelectListItem { Text = "Afghanistan", Value = "Afghanistan" }, new SelectListItem { Text = "Albania", Value = "Albania" }, new SelectListItem { Text = "Algeria", Value = "Algeria" }, new SelectListItem { Text = "Andorra", Value = "Andorra" }, new SelectListItem { Text = "Angola", Value = "Angola" }, new SelectListItem { Text = "Antigua and Barbuda", Value = "Antigua and Barbuda" }, new SelectListItem { Text = "Argentina", Value = "Argentina" }, new SelectListItem { Text = "Armenia", Value = "Armenia" }, new SelectListItem { Text = "Australia", Value = "Australia" }, new SelectListItem { Text = "Austria", Value = "Austria" }, new SelectListItem { Text = "Azerbaijan", Value = "Azerbaijan" }, new SelectListItem { Text = "Bahamas", Value = "Bahamas" }, new SelectListItem { Text = "Bahrain", Value = "Bahrain" }, new SelectListItem { Text = "Bangladesh", Value = "Bangladesh" }, new SelectListItem { Text = "Barbados", Value = "Barbados" }, new SelectListItem { Text = "Belarus", Value = "Belarus" }, new SelectListItem { Text = "Belgium", Value = "Belgium" }, new SelectListItem { Text = "Belize", Value = "Belize" }, new SelectListItem { Text = "Benin", Value = "Benin" }, new SelectListItem { Text = "Bhutan", Value = "Bhutan" }, new SelectListItem { Text = "Bolivia, Plurinational State of", Value = "Bolivia, Plurinational State of" }, new SelectListItem { Text = "Bosnia and Herzegovina", Value = "Bosnia and Herzegovina" }, new SelectListItem { Text = "Botswana", Value = "Botswana" }, new SelectListItem { Text = "Brazil", Value = "Brazil" }, new SelectListItem { Text = "Brunei Darussalam", Value = "Brunei Darussalam" }, new SelectListItem { Text = "Bulgaria", Value = "Bulgaria" }, new SelectListItem { Text = "Burkina Faso", Value = "Burkina Faso" }, new SelectListItem { Text = "Burundi", Value = "Burundi" }, new SelectListItem { Text = "Cambodia", Value = "Cambodia" }, new SelectListItem { Text = "Cameroon", Value = "Cameroon" }, new SelectListItem { Text = "Cape Verde", Value = "Cape Verde" }, new SelectListItem { Text = "Central African Republic", Value = "Central African Republic" }, new SelectListItem { Text = "Chad", Value = "Chad" }, new SelectListItem { Text = "Chile", Value = "Chile" }, new SelectListItem { Text = "China", Value = "China" }, new SelectListItem { Text = "Colombia", Value = "Colombia" }, new SelectListItem { Text = "Comoros", Value = "Comoros" }, new SelectListItem { Text = "Congo", Value = "Congo" }, new SelectListItem { Text = "Congo, the Democratic Republic of the", Value = "Congo, the Democratic Republic of the" }, new SelectListItem { Text = "Costa Rica", Value = "Costa Rica" }, new SelectListItem { Text = "Côte d'Ivoire", Value = "Côte d'Ivoire" }, new SelectListItem { Text = "Croatia", Value = "Croatia" }, new SelectListItem { Text = "Cuba", Value = "Cuba" }, new SelectListItem { Text = "Cyprus", Value = "Cyprus" }, new SelectListItem { Text = "Czech Republic", Value = "Czech Republic" }, new SelectListItem { Text = "Denmark", Value = "Denmark" }, new SelectListItem { Text = "Djibouti", Value = "Djibouti" }, new SelectListItem { Text = "Dominica", Value = "Dominica" }, new SelectListItem { Text = "Dominican Republic", Value = "Dominican Republic" }, new SelectListItem { Text = "Timor-Leste", Value = "Timor-Leste" }, new SelectListItem { Text = "Ecuador", Value = "Ecuador" }, new SelectListItem { Text = "Egypt", Value = "Egypt" }, new SelectListItem { Text = "El Salvador", Value = "El Salvador" }, new SelectListItem { Text = "Equatorial Guinea", Value = "Equatorial Guinea" }, new SelectListItem { Text = "Eritrea", Value = "Eritrea" }, new SelectListItem { Text = "Estonia", Value = "Estonia" }, new SelectListItem { Text = "Ethiopia", Value = "Ethiopia" }, new SelectListItem { Text = "Fiji", Value = "Fiji" }, new SelectListItem { Text = "Finland", Value = "Finland" }, new SelectListItem { Text = "France", Value = "France" }, new SelectListItem { Text = "Gabon", Value = "Gabon" }, new SelectListItem { Text = "Gambia", Value = "Gambia" }, new SelectListItem { Text = "Georgia", Value = "Georgia" }, new SelectListItem { Text = "Germany", Value = "Germany" }, new SelectListItem { Text = "Ghana", Value = "Ghana" }, new SelectListItem { Text = "Greece", Value = "Greece" }, new SelectListItem { Text = "Grenada", Value = "Grenada" }, new SelectListItem { Text = "Guatemala", Value = "Guatemala" }, new SelectListItem { Text = "Guinea", Value = "Guinea" }, new SelectListItem { Text = "Guinea-Bissau", Value = "Guinea-Bissau" }, new SelectListItem { Text = "Guyana", Value = "Guyana" }, new SelectListItem { Text = "Haiti", Value = "Haiti" }, new SelectListItem { Text = "Honduras", Value = "Honduras" }, new SelectListItem { Text = "Hungary", Value = "Hungary" }, new SelectListItem { Text = "Iceland", Value = "Iceland" }, new SelectListItem { Text = "India", Value = "India" }, new SelectListItem { Text = "Indonesia", Value = "Indonesia" }, new SelectListItem { Text = "Iran, Islamic Republic of", Value = "Iran, Islamic Republic of" }, new SelectListItem { Text = "Iraq", Value = "Iraq" }, new SelectListItem { Text = "Ireland", Value = "Ireland" }, new SelectListItem { Text = "Israel", Value = "Israel" }, new SelectListItem { Text = "Italy", Value = "Italy" }, new SelectListItem { Text = "Jamaica", Value = "Jamaica" }, new SelectListItem { Text = "Japan", Value = "Japan" }, new SelectListItem { Text = "Jordan", Value = "Jordan" }, new SelectListItem { Text = "Kazakhstan", Value = "Kazakhstan" }, new SelectListItem { Text = "Kenya", Value = "Kenya" }, new SelectListItem { Text = "Kiribati", Value = "Kiribati" }, new SelectListItem { Text = "Korea, Democratic People's Republic of", Value = "Korea, Democratic People's Republic of" }, new SelectListItem { Text = "Korea, Republic of", Value = "Korea, Republic of" }, new SelectListItem { Text = "Kuwait", Value = "Kuwait" }, new SelectListItem { Text = "Kyrgyzstan", Value = "Kyrgyzstan" }, new SelectListItem { Text = "Lao People's Democratic Republic", Value = "Lao People's Democratic Republic" }, new SelectListItem { Text = "Latvia", Value = "Latvia" }, new SelectListItem { Text = "Lebanon", Value = "Lebanon" }, new SelectListItem { Text = "Lesotho", Value = "Lesotho" }, new SelectListItem { Text = "Liberia", Value = "Liberia" }, new SelectListItem { Text = "Libyan Arab Jamahiriya", Value = "Libyan Arab Jamahiriya" }, new SelectListItem { Text = "Liechtenstein", Value = "Liechtenstein" }, new SelectListItem { Text = "Lithuania", Value = "Lithuania" }, new SelectListItem { Text = "Luxembourg", Value = "Luxembourg" }, new SelectListItem { Text = "Macedonia, the former Yugoslav Republic of", Value = "Macedonia, the former Yugoslav Republic of" }, new SelectListItem { Text = "Madagascar", Value = "Madagascar" }, new SelectListItem { Text = "Malawi", Value = "Malawi" }, new SelectListItem { Text = "Malaysia", Value = "Malaysia" }, new SelectListItem { Text = "Maldives", Value = "Maldives" }, new SelectListItem { Text = "Mali", Value = "Mali" }, new SelectListItem { Text = "Malta", Value = "Malta" }, new SelectListItem { Text = "Marshall Islands", Value = "Marshall Islands" }, new SelectListItem { Text = "Mauritania", Value = "Mauritania" }, new SelectListItem { Text = "Mauritius", Value = "Mauritius" }, new SelectListItem { Text = "Micronesia, Federated States of", Value = "Micronesia, Federated States of" }, new SelectListItem { Text = "Moldova, Republic of", Value = "Moldova, Republic of" }, new SelectListItem { Text = "Monaco", Value = "Monaco" }, new SelectListItem { Text = "Mongolia", Value = "Mongolia" }, new SelectListItem { Text = "Montenegro", Value = "Montenegro" }, new SelectListItem { Text = "Morocco", Value = "Morocco" }, new SelectListItem { Text = "Mozambique", Value = "Mozambique" }, new SelectListItem { Text = "Myanmar", Value = "Myanmar" }, new SelectListItem { Text = "Namibia", Value = "Namibia" }, new SelectListItem { Text = "Nauru", Value = "Nauru" }, new SelectListItem { Text = "Nepal", Value = "Nepal" }, new SelectListItem { Text = "Netherlands", Value = "Netherlands" }, new SelectListItem { Text = "New Zealand", Value = "New Zealand" }, new SelectListItem { Text = "Nicaragua", Value = "Nicaragua" }, new SelectListItem { Text = "Niger", Value = "Niger" }, new SelectListItem { Text = "Nigeria", Value = "Nigeria" }, new SelectListItem { Text = "Norway", Value = "Norway" }, new SelectListItem { Text = "Oman", Value = "Oman" }, new SelectListItem { Text = "Pakistan", Value = "Pakistan" }, new SelectListItem { Text = "Palau", Value = "Palau" }, new SelectListItem { Text = "Panama", Value = "Panama" }, new SelectListItem { Text = "Papua New Guinea", Value = "Papua New Guinea" }, new SelectListItem { Text = "Paraguay", Value = "Paraguay" }, new SelectListItem { Text = "Peru", Value = "Peru" }, new SelectListItem { Text = "Philippines", Value = "Philippines" }, new SelectListItem { Text = "Poland", Value = "Poland" }, new SelectListItem { Text = "Portugal", Value = "Portugal" }, new SelectListItem { Text = "Qatar", Value = "Qatar" }, new SelectListItem { Text = "Romania", Value = "Romania" }, new SelectListItem { Text = "Russian Federation", Value = "Russian Federation" }, new SelectListItem { Text = "Rwanda", Value = "Rwanda" }, new SelectListItem { Text = "Saint Kitts and Nevis", Value = "Saint Kitts and Nevis" }, new SelectListItem { Text = "Saint Lucia", Value = "Saint Lucia" }, new SelectListItem { Text = "Saint Vincent and The Grenadines", Value = "Saint Vincent and The Grenadines" }, new SelectListItem { Text = "Samoa", Value = "Samoa" }, new SelectListItem { Text = "San Marino", Value = "San Marino" }, new SelectListItem { Text = "Sao Tome and Principe", Value = "Sao Tome and Principe" }, new SelectListItem { Text = "Saudi Arabia", Value = "Saudi Arabia" }, new SelectListItem { Text = "Senegal", Value = "Senegal" }, new SelectListItem { Text = "Serbia", Value = "Serbia" }, new SelectListItem { Text = "Seychelles", Value = "Seychelles" }, new SelectListItem { Text = "Sierra Leone", Value = "Sierra Leone" }, new SelectListItem { Text = "Singapore", Value = "Singapore" }, new SelectListItem { Text = "Slovakia", Value = "Slovakia" }, new SelectListItem { Text = "Slovenia", Value = "Slovenia" }, new SelectListItem { Text = "Solomon Islands", Value = "Solomon Islands" }, new SelectListItem { Text = "Somalia", Value = "Somalia" }, new SelectListItem { Text = "South Africa", Value = "South Africa" }, new SelectListItem { Text = "Spain", Value = "Spain" }, new SelectListItem { Text = "Sri Lanka", Value = "Sri Lanka" }, new SelectListItem { Text = "Sudan", Value = "Sudan" }, new SelectListItem { Text = "Suriname", Value = "Suriname" }, new SelectListItem { Text = "Swaziland", Value = "Swaziland" }, new SelectListItem { Text = "Sweden", Value = "Sweden" }, new SelectListItem { Text = "Switzerland", Value = "Switzerland" }, new SelectListItem { Text = "Syrian Arab Republic", Value = "Syrian Arab Republic" }, new SelectListItem { Text = "Taiwan, Province of China", Value = "Taiwan, Province of China" }, new SelectListItem { Text = "Tajikistan", Value = "Tajikistan" }, new SelectListItem { Text = "Tanzania, United Republic of", Value = "Tanzania, United Republic of" }, new SelectListItem { Text = "Thailand", Value = "Thailand" }, new SelectListItem { Text = "Togo", Value = "Togo" }, new SelectListItem { Text = "Tonga", Value = "Tonga" }, new SelectListItem { Text = "Trinidad and Tobago", Value = "Trinidad and Tobago" }, new SelectListItem { Text = "Tunisia", Value = "Tunisia" }, new SelectListItem { Text = "Turkey", Value = "Turkey" }, new SelectListItem { Text = "Turkmenistan", Value = "Turkmenistan" }, new SelectListItem { Text = "Tuvalu", Value = "Tuvalu" }, new SelectListItem { Text = "Uganda", Value = "Uganda" }, new SelectListItem { Text = "Ukraine", Value = "Ukraine" }, new SelectListItem { Text = "United Arab Emirates", Value = "United Arab Emirates" }, new SelectListItem { Text = "United Kingdom", Value = "United Kingdom" }, new SelectListItem { Text = "Uruguay", Value = "Uruguay" }, new SelectListItem { Text = "Uzbekistan", Value = "Uzbekistan" }, new SelectListItem { Text = "Vanuatu", Value = "Vanuatu" }, new SelectListItem { Text = "Vatican City", Value = "Vatican City" }, new SelectListItem { Text = "Venezuela, Bolivarian Republic of", Value = "Venezuela, Bolivarian Republic of" }, new SelectListItem { Text = "Viet Nam", Value = "Viet Nam" }, new SelectListItem { Text = "Western Sahara", Value = "Western Sahara" }, new SelectListItem { Text = "Yemen", Value = "Yemen" }, new SelectListItem { Text = "Zambia", Value = "Zambia" }, new SelectListItem { Text = "Zimbabwe", Value = "Zimbabwe" } + }, "Value", "Text"); +} +
+ @model Web2Rpm.Models.Lead +
+
+
+

@ViewData["Title"]

+
+
+
+ @using (Html.BeginForm()) + { + @Html.AntiForgeryToken() +
+
+ @Html.LabelFor(m => m.Name, new { @class = "control-label" }) + @Html.TextBoxFor(m => m.Name, new { @class = "form-control" }) + @Html.ValidationMessageFor(m => m.Name) +
+
+
+
+ @Html.LabelFor(m => m.Phone, new { @class = "control-label" }) + @Html.TextBoxFor(m => m.Phone, new { @class = "form-control" }) + @Html.ValidationMessageFor(m => m.Phone) +
+
+ @Html.LabelFor(m => m.Email, new { @class = "control-label" }) + @Html.TextBoxFor(m => m.Email, new { @class = "form-control" }) + @Html.ValidationMessageFor(m => m.Email) +
+
+
+
+
+ @Html.LabelFor(m => m.Company, new { @class = "control-label" }) + @Html.TextBoxFor(m => m.Company, new { @class = "form-control" }) + @Html.ValidationMessageFor(m => m.Company) +
+
+ @Html.LabelFor(m => m.Website, new { @class = "control-label" }) + @Html.TextBoxFor(m => m.Website, new { @class = "form-control" }) + @Html.ValidationMessageFor(m => m.Website) +
+
+
+ +
+
+ @Html.LabelFor(m => m.Comment, new { @class = "control-label" }) + @Html.TextAreaFor(m => m.Comment, new { @class = "form-control", @rows = "4" }) + @Html.ValidationMessageFor(m => m.Comment) +
+
+ + +
+
+ +
+
+ } +
+
+
+
\ No newline at end of file diff --git a/Web2Rpm/Views/Home/Sent.cshtml b/Web2Rpm/Views/Home/Sent.cshtml new file mode 100644 index 0000000..5bd966c --- /dev/null +++ b/Web2Rpm/Views/Home/Sent.cshtml @@ -0,0 +1,12 @@ +@{ + ViewData["Title"] = "Sent"; +} +
+
+

Thank you

+ +

+ Your contact request has been received, we will be in touch shortly. +

+
+