|
| 1 | +using RandomLib; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using System.Web; |
| 6 | +using System.Web.Mvc; |
| 7 | + |
| 8 | +namespace RandomWebApp.Controllers |
| 9 | +{ |
| 10 | + // Attribute Routing in ASP.NET MVC 5 |
| 11 | + // http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx |
| 12 | + [RoutePrefix("json")] |
| 13 | + [Route("{action=Index}")] |
| 14 | + public class RandomController : JsonApiController |
| 15 | + { |
| 16 | + public ActionResult Index() |
| 17 | + { |
| 18 | + return RedirectToAction("", ""); |
| 19 | + } |
| 20 | + |
| 21 | + // GET: /json/NewAlphabets/8 |
| 22 | + [Route("NewAlphabets/{length:int:range(0,4096)}")] |
| 23 | + public ActionResult NewAlphabets(int length) |
| 24 | + { |
| 25 | + return Json(RandomUtility.GenerateAlphabets(length)); |
| 26 | + } |
| 27 | + |
| 28 | + // GET: /json/NewAlphanumerics/8 |
| 29 | + [Route("NewAlphanumerics/{length:int:range(0,4096)}")] |
| 30 | + public ActionResult NewAlphanumerics(int length) |
| 31 | + { |
| 32 | + return Json(RandomUtility.GenerateAlphanumerics(length)); |
| 33 | + } |
| 34 | + |
| 35 | + // GET: /json/NewBytes/hexlower/16 |
| 36 | + [Route("NewBytes/hexlower/{length:int:range(0,4096)}")] |
| 37 | + public ActionResult NewBytes_HexLower(int length) |
| 38 | + { |
| 39 | + var data = RandomUtility.GenerateBytes(length); |
| 40 | + return Json(data.ToHexString(false)); |
| 41 | + } |
| 42 | + |
| 43 | + // GET: /json/NewBytes/hexupper/16 |
| 44 | + [Route("NewBytes/hexupper/{length:int:range(0,4096)}")] |
| 45 | + public ActionResult NewBytes_HexUpper(int length) |
| 46 | + { |
| 47 | + var data = RandomUtility.GenerateBytes(length); |
| 48 | + return Json(data.ToHexString(true)); |
| 49 | + } |
| 50 | + |
| 51 | + // GET: /json/NewBytes/base64/16 |
| 52 | + [Route("NewBytes/base64/{length:int:range(0,4096)}")] |
| 53 | + public ActionResult NewBytes_Base64(int length) |
| 54 | + { |
| 55 | + var data = RandomUtility.GenerateBytes(length); |
| 56 | + return Json(Convert.ToBase64String(data)); |
| 57 | + } |
| 58 | + |
| 59 | + // GET: /json/NewUuid |
| 60 | + public ActionResult NewUuid() |
| 61 | + { |
| 62 | + return Json(Guid.NewGuid()); |
| 63 | + } |
| 64 | + |
| 65 | + // GET: /json/NewOrderedId |
| 66 | + public ActionResult NewOrderedId() |
| 67 | + { |
| 68 | + var id = RandomUtility.GenerateOrderedGuid(); |
| 69 | + return Json(new { id = id.Guid, date = id.DateTime.ToIso8601String() }); |
| 70 | + } |
| 71 | + |
| 72 | + // GET: /json/NewOrderedId/sqlserver |
| 73 | + [Route("NewOrderedId/sqlserver")] |
| 74 | + public ActionResult NewOrderedId_SqlServer() |
| 75 | + { |
| 76 | + var id = RandomUtility.GenerateOrderedSqlGuid(); |
| 77 | + return Json(new { id = id.Guid, date = id.DateTime.ToIso8601String() }); |
| 78 | + } |
| 79 | + |
| 80 | + // GET: /json/NewOrderedId2 |
| 81 | + public ActionResult NewOrderedId2() |
| 82 | + { |
| 83 | + var id = RandomUtility.GenerateOrderedGuid2(); |
| 84 | + return Json(new { id = id.Guid, date = id.DateTime.ToIso8601String() }); |
| 85 | + } |
| 86 | + |
| 87 | + // GET: /json/NewOrderedId2/sqlserver |
| 88 | + [Route("NewOrderedId2/sqlserver")] |
| 89 | + public ActionResult NewOrderedId2_SqlServer() |
| 90 | + { |
| 91 | + var id = RandomUtility.GenerateOrderedSqlGuid2(); |
| 92 | + return Json(new { id = id.Guid, date = id.DateTime.ToIso8601String() }); |
| 93 | + } |
| 94 | + } |
| 95 | +} |
0 commit comments