Guest User

Untitled

a guest
Oct 24th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. [HttpPost]
  2. public void PostInsertDate([FromBody]ExpoRegistration ExpoRegistration)
  3. {
  4. string remoteUrl ="http://localhost:64995/Data.html";
  5. Big5OnlinePortalEntities db = new Big5OnlinePortalEntities();
  6. var date = db.ExpoRegistrations.FirstOrDefault(e => e.UserName == ExpoRegistration.UserName && e.Password == ExpoRegistration.Password);
  7. if (date == null)
  8. {
  9. Request.CreateErrorResponse(HttpStatusCode.NotFound, "Customer not found");
  10. }
  11. else
  12. {
  13. date.StartDate = DateTime.Today.Date;
  14. db.SaveChanges();
  15. Request.CreateResponse(HttpStatusCode.OK, date);
  16. if (date.StartDate <= date.EndDate)
  17. {
  18. Request.CreateErrorResponse(HttpStatusCode.NotFound, "Customer not found");
  19. }
  20. else
  21. {
  22. Redirect(remoteUrl);
  23.  
  24. }
  25. }
  26. }
  27.  
  28. $(document).ready(function () {
  29.  
  30. $('#linkClose').click(function () {
  31. $('#divError').hide('fade');
  32. });
  33.  
  34. $('#btnLogin').click(function () {
  35. localStorage.setItem('username', document.getElementById('txtUsername').value);
  36. var loginData = {
  37. grant_type: 'password',
  38. username: $('#txtUsername').val(),
  39. password: $('#txtPassword').val(),
  40. };
  41. var ExpoRegistration = {};
  42. ExpoRegistration.UserName = $('#txtUsername').val();
  43. ExpoRegistration.Password = $('#txtPassword').val();
  44.  
  45. $.ajax({
  46. // Post username, password & the grant type to /token
  47. url: '/token',
  48. headers: { "Accept": "application/json" },
  49. method: 'POST',
  50. contentType: 'application/json',
  51. data: {
  52. username: $('#txtUsername').val(),
  53. password: $('#txtPassword').val(),
  54. ClientId12: $('#ddlEventId').val(),
  55. grant_type: 'password',
  56.  
  57. },
  58. // When the request completes successfully, save the
  59. // access token in the browser session storage and
  60. // redirect the user to Data.html page. We do not have
  61. // this page yet. So please add it to the
  62. // EmployeeService project before running it
  63. success: function (response) {
  64. sessionStorage.setItem("accessToken", response.access_token);
  65. //window.location.href = "Data.html";
  66. },
  67. // Display errors if any in the Bootstrap alert <div>
  68. error: function (jqXHR) {
  69. $('#divErrorText').text(jqXHR.responseText);
  70. $('#divError').show('fade');
  71. }
  72. });
  73.  
  74. $.ajax({
  75.  
  76. url: 'http://localhost:64995/api/StartDate',
  77. datatype: 'json',
  78. type: 'POST',
  79. data: ExpoRegistration,
  80. headers: {
  81. 'Authorization': 'Bearer '
  82. + sessionStorage.getItem("accessToken")
  83. },
  84. success: function (response) {
  85. //window.location.href = "Data.html";
  86. alert("Start Date Saved");
  87. },
  88. error: function (jqXHR) {
  89. $('#divErrorText').text(jqXHR.responseText);
  90. $('#divError').show('fade');
  91. }
  92. });
  93.  
  94. });
  95. });
Add Comment
Please, Sign In to add comment