Ejemplo n.º 1
0
 /* Takes the input of userId and searches in the database table [users] This function will retrieve the userName from the database table [users] */
 public static string GetUserName(string userId, string agentLocationCode)
 {
     using (tsc_tools db = new tsc_tools())
     {
         user user       = new user();
         var  userRecord = db.users.Where(u => u.userId == userId.ToLower()).SingleOrDefault();
         if (userRecord != null)
         {
             if (agentLocationCode != "" && (userRecord.locationCode == "" || userRecord.locationCode == null))
             {
                 userRecord.locationCode = agentLocationCode.ToUpper();
                 db.Entry(userRecord).CurrentValues.SetValues(userRecord);
                 db.SaveChanges();
                 locationLookup locationLookup       = new locationLookup();
                 var            locationLookupRecord = db.locationLookups.Where(l => l.locationCode == agentLocationCode.ToUpper()).SingleOrDefault();
                 if (locationLookupRecord == null)
                 {
                     locationLookup.locationCode = agentLocationCode.ToUpper();
                     string locationName = "Building: " + agentLocationCode;
                     locationLookup.locationName = locationName;
                     db.locationLookups.Add(locationLookup);
                     db.SaveChanges();
                     var context = GlobalHost.ConnectionManager.GetHubContext <MyHub>();
                     context.Clients.Group(groupNames.Monitor).addLocationName(agentLocationCode, locationName);
                 }
             }
             return(userRecord.userName.ToUpper());
         }
         else
         {
             return(null);
         }
     }
 }
Ejemplo n.º 2
0
 /* Retrieves Location Codes and Location Names */
 public static string GetLocationCodes()
 {
     using (tsc_tools db = new tsc_tools())
     {
         locationLookup locationCode          = new locationLookup();
         var            locationLookupRecords =
             from l in db.locationLookups
             orderby l.locationName
             select l;
         return(JsonConvert.SerializeObject(locationLookupRecords));
     }
 }