public List<datalog> getAllLogs()
 {
     var myEnt = new tinajaEntities2();
     var logset = from datalog in myEnt.datalog
                  orderby datalog.logtime
                  select datalog;
     return logset.ToList<datalog>();
 }
 public List<datalog> getLogsByApikey(string apikey)
 {
     var myEnt = new tinajaEntities2();
     var logset = from datalog in myEnt.datalog
                  where datalog.apikey == apikey
                  orderby datalog.logtime
                  select datalog;
     return logset.ToList<datalog>();
 }
 public List<datalog> getLogsByApikeyHours(string apikey, int hours)
 {
     // get the negative value of the hours supplied
     int negHours = hours * -1;
     DateTime hoursBackTime = DateTime.UtcNow.AddHours(negHours);
     var myEnt = new tinajaEntities2();
     var logset = from datalog in myEnt.datalog
                  where (datalog.apikey == apikey) && (datalog.logtime >= hoursBackTime)
                  orderby datalog.logtime
                  select datalog;
     return logset.ToList<datalog>();
 }
        public string insertLog(string apikey, string logval)
        {
            tinajaEntities2 myEnt = new tinajaEntities2();
            // datalog dl = new datalog { apikey = theKey, logvalue = theValue };

            decimal logResult = 0;

            try
            {
                if (string.IsNullOrEmpty(apikey))
                    throw new Exception("Error: apikey cannot be blank.");

                if (!decimal.TryParse(logval, out logResult))
                    throw new Exception("Error: logvalue must be a decimal type with up to 4 decimal places.  (e.g., -999999.9999 to 999999.9999)");
            }
            catch (FormatException exFormat)
            {
                LogIt("Fail, validation FormatException - insertLog: " + exFormat.Message);
                return "Fail, validation FormatException - insertLog: " + exFormat.Message;
            }
            catch (Exception ex)
            {
                LogIt("Fail, validation Exception - insertLog: " + ex.Message);
                return "Fail, validation Exception - insertLog: " + ex.Message;
            }

            decimal logvalue = logResult;

            datalog myDL = new datalog();
            myDL.apikey = apikey;
            myDL.logvalue = logvalue;
            myDL.logtime = DateTime.UtcNow;
            myDL.id = Guid.NewGuid();

            try
            {
                myEnt.AddTodatalog(myDL);
                myEnt.SaveChanges();
            }
            catch (FormatException exFormat)
            {
                LogIt("Fail, SaveChanges FormatException - insertLog: " + exFormat.Message);
                return "Fail, SaveChanges FormatException - insertLog: " + exFormat.Message;
            }
            catch (Exception ex)
            {
                LogIt("Fail, SaveChanges Exception - insertLog: " + ex.Message);
                return "Fail, SaveChanges Exception - insertLog: " + ex.Message;
            }

            return "Inserted";
        }