Guest User

Untitled

a guest
May 25th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. [WebGet(UriTemplate = "{deviceId}/{username=null}/{password=null}")]
  2.         public IEnumerable<Session> Get(string username, string password, string deviceId)
  3.         {
  4.            
  5.             if (String.IsNullOrEmpty(username))
  6.                 throw new HttpResponseException(HttpStatusCode.BadRequest);
  7.             if (String.IsNullOrEmpty(password))
  8.                 throw new HttpResponseException(HttpStatusCode.BadRequest);
  9.                        
  10.             var session = new List<Session>();
  11.  
  12.             var employee = db.EEEs
  13.                             .Where(e => e.MBL_WORKER_ID == username && e.MBL_WORKER_PIN == password)
  14.                             .SingleOrDefault();
  15.             var device = db.PMS_MBL_DVCs
  16.                             .Where(d => d.AUID == deviceId)
  17.                             .SingleOrDefault();
  18.            
  19.             if (employee == null || device == null)
  20.                 throw new HttpResponseException(HttpStatusCode.NoContent);
  21.  
  22.             try
  23.             {
  24.                 device = db.mbl_update_device_suid(device.DVC_ID).AsQueryable<PMS_MBL_DVC>().FirstOrDefault();
  25.             }
  26.             catch (Exception ex)
  27.             {
  28.                 throw new HttpResponseException(HttpStatusCode.InternalServerError);
  29.             }
  30.  
  31.             session.Add(new Session { SessionID = 1, result = "success", employeeId = employee.EE_ID, uniqueId = device.SUID.ToString() });
  32.  
  33.             return session;
  34.            
  35.         }
Add Comment
Please, Sign In to add comment