Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public void PostInsertDate([FromBody]ExpoRegistration ExpoRegistration)
- {
- string remoteUrl ="http://localhost:64995/Data.html";
- Big5OnlinePortalEntities db = new Big5OnlinePortalEntities();
- var date = db.ExpoRegistrations.FirstOrDefault(e => e.UserName == ExpoRegistration.UserName && e.Password == ExpoRegistration.Password);
- if (date == null)
- {
- Request.CreateErrorResponse(HttpStatusCode.NotFound, "Customer not found");
- }
- else
- {
- date.StartDate = DateTime.Today.Date;
- db.SaveChanges();
- Request.CreateResponse(HttpStatusCode.OK, date);
- if (date.StartDate <= date.EndDate)
- {
- Request.CreateErrorResponse(HttpStatusCode.NotFound, "Customer not found");
- }
- else
- {
- Redirect(remoteUrl);
- }
- }
- }
- $(document).ready(function () {
- $('#linkClose').click(function () {
- $('#divError').hide('fade');
- });
- $('#btnLogin').click(function () {
- localStorage.setItem('username', document.getElementById('txtUsername').value);
- var loginData = {
- grant_type: 'password',
- username: $('#txtUsername').val(),
- password: $('#txtPassword').val(),
- };
- var ExpoRegistration = {};
- ExpoRegistration.UserName = $('#txtUsername').val();
- ExpoRegistration.Password = $('#txtPassword').val();
- $.ajax({
- // Post username, password & the grant type to /token
- url: '/token',
- headers: { "Accept": "application/json" },
- method: 'POST',
- contentType: 'application/json',
- data: {
- username: $('#txtUsername').val(),
- password: $('#txtPassword').val(),
- ClientId12: $('#ddlEventId').val(),
- grant_type: 'password',
- },
- // When the request completes successfully, save the
- // access token in the browser session storage and
- // redirect the user to Data.html page. We do not have
- // this page yet. So please add it to the
- // EmployeeService project before running it
- success: function (response) {
- sessionStorage.setItem("accessToken", response.access_token);
- //window.location.href = "Data.html";
- },
- // Display errors if any in the Bootstrap alert <div>
- error: function (jqXHR) {
- $('#divErrorText').text(jqXHR.responseText);
- $('#divError').show('fade');
- }
- });
- $.ajax({
- url: 'http://localhost:64995/api/StartDate',
- datatype: 'json',
- type: 'POST',
- data: ExpoRegistration,
- headers: {
- 'Authorization': 'Bearer '
- + sessionStorage.getItem("accessToken")
- },
- success: function (response) {
- //window.location.href = "Data.html";
- alert("Start Date Saved");
- },
- error: function (jqXHR) {
- $('#divErrorText').text(jqXHR.responseText);
- $('#divError').show('fade');
- }
- });
- });
- });
Add Comment
Please, Sign In to add comment