Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. ********************FontPickerController***********************
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. using MIS324Assignments.Models;
  9.  
  10. namespace MIS324Assignments.Controllers
  11. {
  12. public class FontPickerController : Controller
  13. {
  14. // GET: FontPicker
  15. [HttpGet]
  16. public ActionResult Index()
  17. {
  18. FontPickerModel fp = new FontPickerModel();
  19. ViewBag.imageTags = GenerateImageTags(fp.Message);
  20. return View(fp);
  21. }
  22. [HttpGet]
  23. public ActionResult Fonts()
  24. {
  25. FontPickerModel fp = new FontPickerModel();
  26. ViewBag.imageTags = GenerateImageTags(fp.Message, fp.FontId);
  27. return View(fp);
  28. }
  29.  
  30.  
  31. [HttpPost]
  32. public ActionResult Index(FontPickerModel fp)
  33. {
  34. Response.Write("Method Post");
  35. if (ModelState.IsValid)
  36. {
  37. ViewBag.imageTags = GenerateImageTags(fp.Message);
  38. }
  39. return View(fp);
  40. }
  41.  
  42. [HttpPost]
  43. public ActionResult Fonts(FontPickerModel fp)
  44. {
  45. Response.Write("Method Post");
  46. if (ModelState.IsValid)
  47. {
  48. ViewBag.imageTags = GenerateImageTags(fp.Message, fp.FontId);
  49. }
  50. return View(fp);
  51. }
  52.  
  53.  
  54. string GenerateImageTags(string Message, string FontId = "")
  55. {
  56. //build a string of image tags
  57. string imageTags = "";
  58. for (int i = 0; i < Message.Length; i++)
  59. {
  60. string character = Message.Substring(i, 1);
  61. if (character != " ")
  62. imageTags += GetTag(character, FontId);
  63. else
  64. imageTags += "<br />";
  65. }
  66. return imageTags;
  67. }
  68. private string GetTag(string character, string FontId)
  69. {
  70. string url = "<img src='http://yorktown.cbe.wwu.edu/sandvig/images/alphabet/";
  71.  
  72. if (FontId == "ChunkRed")
  73. {
  74. return url + "chunk/red/" + character + "9.jpg' />";
  75. }
  76. else if (FontId == "DecoBlue")
  77. {
  78. return url + "deco/blue/" + character + "1.gif' />";
  79. }
  80. else if (FontId == "Animals")
  81. {
  82. return url + "animals/" + character + "4.gif' />";
  83. }
  84. else if (FontId == "ElegantRed")
  85. {
  86. return url + "elegant/red/4" + character + ".gif' />";
  87. }
  88. else if (FontId == "Funky")
  89. {
  90. return url + "funky/" + character + "3.jpg' />";
  91. }
  92. else
  93. {
  94. return url + "punch/black/" + character + "7.gif' />";
  95. }
  96. }
  97. }
  98. }
  99. ********************************fonts.cshtml*************************************************(this one was a work in progress, namely with the dropdownlistfor HTML helper near the bottom)****************************************************
  100.  
  101. @model MIS324Assignments.Models.FontPickerModel
  102.  
  103.  
  104. <!DOCTYPE html>
  105.  
  106. <html>
  107. <head>
  108. <meta name="viewport" content="width=device-width" />
  109. <title>Fonts</title>
  110. </head>
  111. <body>
  112. @Scripts.Render("~/bundles/jquery")
  113. @Scripts.Render("~/bundles/jqueryval")
  114.  
  115.  
  116. @using (Html.BeginForm())
  117. {
  118. @Html.AntiForgeryToken()
  119.  
  120. <div class="form-horizontal">
  121. <h4>FontPickerModel</h4>
  122. <hr />
  123. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  124. <div class="form-group">
  125. @Html.LabelFor(model => model.Message, htmlAttributes: new { @class = "control-label col-md-2" })
  126. <div class="col-md-10">
  127. @Html.EditorFor(model => model.Message, new { htmlAttributes = new { @class = "form-control" } })
  128. @Html.ValidationMessageFor(model => model.Message, "", new { @class = "text-danger" })
  129. </div>
  130. </div>
  131.  
  132. <div class="form-group">
  133. @Html.LabelFor(model => model.FontId, htmlAttributes: new { @class = "control-label col-md-2" })
  134. <div class="col-md-10">
  135. @Html.DropDownListFor(
  136. model => model.FontId,
  137. new SelectList(MIS324Assignments.ViewModels.FontPickerViewModel.FontPickerViewModel.FontList, "FontID",
  138. "FontName",
  139. new { htmlAttributes = new { @class = "form-control" } }))
  140. @Html.ValidationMessageFor(model => model.FontId, "", new { @class = "text-danger" })
  141. </div>
  142. </div>
  143.  
  144. <div class="form-group">
  145. <div class="col-md-offset-2 col-md-10">
  146. <input type="submit" value="Create" class="btn btn-default" />
  147. </div>
  148. </div>
  149. </div>
  150. }
  151.  
  152. <div>
  153. @Html.ActionLink("Back to List", "Index")
  154. </div>
  155. </body>
  156. </html>
  157. ****************************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement