Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. using AccessorizeForLess.ViewModels;
  2. using Postal;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.ComponentModel.DataAnnotations;
  7. using System.Linq;
  8. using System.Web;
  9. using System.Web.Mvc;
  10.  
  11. namespace AccessorizeForLess.Models
  12. {
  13. public class ContactEmail : Email
  14. {
  15. public string To { get; set; }
  16.  
  17. [DataType(DataType.EmailAddress)]
  18. [DisplayName("Email Address")]
  19. [RegularExpression(@"^([w.-]+)@([w-]+)((.(w){2,3})+)$", ErrorMessage = "The Email field is not valid, Please enter a valid email address!")]
  20. [Required(ErrorMessage="Email address is required.")]
  21. public string From { get; set; }
  22.  
  23. [DisplayName("First Name")]
  24. [Required(ErrorMessage="Please provide your first name")]
  25. public string FirstName { get; set; }
  26.  
  27. [DisplayName("Last Name")]
  28. [Required(ErrorMessage="Please provide your last name")]
  29. public string LastName { get; set; }
  30.  
  31. [DisplayName("Subject")]
  32. [Required(ErrorMessage="Please select a topic")]
  33. public SelectList Subject { get; set; }
  34. public string SelectedSubject { get; set; }
  35.  
  36. [DisplayName("Message")]
  37. [DataType(DataType.MultilineText)]
  38. [Required(ErrorMessage="PLease provide a message for the email")]
  39. public string Message { get; set; }
  40.  
  41. public List<EmailSubjectViewModel> Subjects { get; set; }
  42. }
  43. }
  44.  
  45. namespace AccessorizeForLess.ViewModels
  46. {
  47. public class EmailSubjectViewModel
  48. {
  49. public int Id { get; set; }
  50. public string Subject { get; set; }
  51. }
  52. }
  53.  
  54. public ActionResult Index()
  55. {
  56. List<EmailSubjectViewModel> Subjects = new List<EmailSubjectViewModel>()
  57. {
  58. new EmailSubjectViewModel(){Id=1, Subject="Website Issues"},
  59. new EmailSubjectViewModel(){Id=2, Subject="Order Issue"},
  60. new EmailSubjectViewModel(){Id=3, Subject="Product Question"},
  61. new EmailSubjectViewModel(){Id=4, Subject="Returns Questions"},
  62. new EmailSubjectViewModel(){Id=5, Subject="Other"}
  63. };
  64.  
  65. ContactEmail email = new ContactEmail()
  66. {
  67. Subjects = Subjects
  68. };
  69. return View(email);
  70. }
  71.  
  72.  
  73. public ActionResult Send(ContactEmail email)
  74. {
  75. ContactEmail e = new ContactEmail();
  76. e.From = email.From;
  77. e.FirstName = email.FirstName;
  78. e.LastName = email.LastName;
  79. e.SelectedSubject = email.SelectedSubject;
  80. e.Message = email.Message;
  81.  
  82. e.Send();
  83. return View();
  84. }
  85.  
  86. @model AccessorizeForLess.Models.ContactEmail
  87. @{
  88. ViewBag.Title = "Contact";
  89. Layout = "~/Views/Shared/_Layout.cshtml";
  90. }
  91.  
  92. <h2>Contact</h2>
  93.  
  94. @using (Html.BeginForm("Send", "Contact", FormMethod.Post))
  95. {
  96. @Html.AntiForgeryToken()
  97.  
  98. <div class="form-horizontal">
  99. <h4>AccessorizeForLess.net&nbsp;&nbsp;&nbsp;
  100. <a href="https://www.facebook.com/accessorize5orless" target="_blank" title="Accessorize For Less On Facebook"><img src="~/Content/icon-facebook.png" /></a></h4>
  101. <div style="color:red;font-weight:bold;">@ViewBag.Message</div>
  102.  
  103. <hr />
  104. @Html.ValidationSummary(true)
  105.  
  106. <div class="form-group">
  107. @Html.LabelFor(model => model.FirstName, new { @class = "control-label col-md-2" })
  108. <div class="col-md-10">
  109. @Html.EditorFor(model => model.FirstName)
  110. @Html.ValidationMessageFor(model => model.FirstName)
  111. </div>
  112. </div>
  113. <div class="form-group">
  114. @Html.LabelFor(model => model.LastName, new { @class = "control-label col-md-2" })
  115. <div class="col-md-10">
  116. @Html.EditorFor(model => model.LastName)
  117. @Html.ValidationMessageFor(model => model.LastName)
  118. </div>
  119. </div>
  120.  
  121. <div class="form-group">
  122. @Html.LabelFor(model => model.From, new { @class = "control-label col-md-2" })
  123. <div class="col-md-10">
  124. @Html.EditorFor(model => model.From)
  125. @Html.ValidationMessageFor(model => model.From)
  126. </div>
  127. </div>
  128.  
  129. <div class="form-group">
  130. @Html.LabelFor(model => model.SelectedSubject, "Category", new { @class = "control-label col-md-2" })
  131. <div class="col-md-10">
  132. @Html.DropDownListFor(model => model.SelectedSubject, new SelectList(Model.Subjects, "Id", "Subject"), "- Please Select -")
  133. @Html.ValidationMessageFor(model => model.SelectedSubject)
  134. </div>
  135. </div>
  136.  
  137. <div class="form-group">
  138. @Html.LabelFor(model => model.Message, new { @class = "control-label col-md-2" })
  139. <div class="col-md-10">
  140. @Html.EditorFor(model => model.Message, new { @cols = "25", @rows = "55" })
  141. @Html.ValidationMessageFor(model => model.Message)
  142. </div>
  143. </div>
  144.  
  145. <div class="form-group">
  146. <div class="col-md-offset-2 col-md-10">
  147. <input type="submit" value="Send" class="btn btn-default" />
  148. </div>
  149. </div>
  150. </div>
  151.  
  152.  
  153. }
  154.  
  155. <system.net>
  156. <mailSettings>
  157. <smtp deliveryMethod="Network" from="admin@accessorizeforless.net">
  158. <network host="smtp.gmail.com" port="587" enableSsl="true" defaultCredentials="true" userName="***********@gmail.com" password="**********" />
  159. </smtp>
  160. </mailSettings>
  161. </system.net>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement