Guest User

Untitled

a guest
Jun 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using System.Web.Routing;
  7.  
  8. namespace Practice
  9. {
  10. public class RouteConfig
  11. {
  12. public static void RegisterRoutes(RouteCollection routes)
  13. {
  14. routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  15.  
  16. routes.MapRoute(
  17. name: "Default",
  18. url: "{controller}/{action}/{id}",
  19. defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
  20. );
  21. }
  22. }
  23. }
  24.  
  25. public ActionResult Index()
  26. {
  27. string firstLocation = "C:\Users\kaleb\source\repos\Practice\Practice\Images\Files";
  28. return RedirectToAction("PracticeView", new { param = firstLocation });
  29. }
  30.  
  31.  
  32. public ActionResult PracticeView(string param)
  33. {
  34. List<FileInfo> fileLst = new List<FileInfo>();
  35. List<DirectoryInfo> dirLst = new List<DirectoryInfo>();
  36.  
  37. if (Directory.Exists(param)) {
  38.  
  39. DirectoryInfo di = new DirectoryInfo(param);
  40. DirectoryInfo[] diArr = di.GetDirectories();
  41.  
  42. foreach (DirectoryInfo i in diArr)
  43. {
  44. dirLst.Add(i);
  45. }
  46.  
  47. DirectoryInfo files = new DirectoryInfo(param);
  48. FileInfo[] f = files.GetFiles().ToArray();
  49.  
  50. foreach (FileInfo i in f)
  51. {
  52. fileLst.Add(i);
  53. }
  54. }
  55.  
  56. var returned = new Tuple<List<DirectoryInfo>, List<FileInfo>>(dirLst, fileLst);
  57. return View(returned);
  58. }
  59.  
  60. public ActionResult imageView(string param1,string[] param2)
  61. {
  62. var returned = new Tuple<string, string[]>(param1, param2);
  63. return View(returned);
  64. }
  65.  
  66. @model Tuple<List<DirectoryInfo>, List<FileInfo>>
  67.  
  68. <h3 style="text-decoration:underline;">Directories</h3>
  69. @foreach (DirectoryInfo i in Model.Item1)
  70. {
  71. System.Diagnostics.Debug.WriteLine(i);
  72. <p>@Html.ActionLink(i.Name, "PracticeView", new { param =
  73. i.FullName })</p>
  74. }
  75.  
  76. <h3 style="text-decoration:underline;">Images</h3>
  77.  
  78. @{
  79. List<string> images = new List<string>();
  80. string[] arr;
  81. }
  82.  
  83. @foreach (FileInfo i in Model.Item2)
  84. {
  85. images.Add(i.FullName);
  86. }
  87.  
  88. @{
  89. arr = images.ToArray();
  90. }
  91.  
  92. @foreach (FileInfo i in Model.Item2)
  93. {
  94. <p>@Html.ActionLink(i.Name, "imageView", new { param1 =
  95. i.FullName , param2 = string.Join(";", arr)})</p>
  96. }
  97.  
  98. @model Tuple<string, string[]>
  99.  
  100. <div style="width:800px;height:400px;border:3px solid
  101. #000;margin:0 auto;margin-top:70px;position:relative;">
  102.  
  103. <img src="" style="width:100%;height:100%;" id="img" />
  104.  
  105. <p style="position:absolute;top:45%;font-
  106. size:22px;color:#fff;left:10px;cursor:pointer;" id="left"><</p>
  107.  
  108. <p style="position:absolute;top:45%;font-
  109. size:22px;color:#fff;right:10px;cursor:pointer;" id="right">></p>
  110. </div>
  111.  
  112. <script type="text/javascript">
  113. var arr = [];
  114. var first = "@Model.Item1";
  115. counter = 0;
  116.  
  117. arr.push(first);
  118.  
  119. @foreach (string i in Model.Item2)
  120. {
  121. <text>arr.push("@i")</text>
  122. }
  123.  
  124. $('#right').click(function () {
  125. if (counter == 0) {
  126.  
  127. }
  128. else {
  129. counter--;
  130. }
  131. });
  132.  
  133. $('#left').click(function () {
  134. if (counter == 0) {
  135.  
  136. }
  137. else {
  138. counter--;
  139. }
  140. });
  141.  
  142. var image = document.getElementById("img");
  143. image.src = "@Url.Content("~/Practice/Images/")" + arr[0];
  144. </script>
Add Comment
Please, Sign In to add comment