public IActionResult GetTime([FromQuery] string timezoneId) { var timezone = TimeZoneInfo.FindSystemTimeZoneById(timezoneId); if (timezone == null) { timezone = TimeZoneInfo.Utc; } var utcTime = DateTime.UtcNow; var timezoneTime = TimeZoneInfo.ConvertTime(utcTime, TimeZoneInfo.Utc, timezone); var remoteIp = HttpContext.Connection.RemoteIpAddress.ToString(); var currentTimeDetail = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = remoteIp, Time = timezoneTime, TimezoneId = timezone.Id, Timezone = timezone.DisplayName }; _context.CurrentTimeQueries.Add(currentTimeDetail); _context.SaveChanges(); return(Ok(currentTimeDetail)); }
public IActionResult Get(string zoneId = null) { var utcTime = DateTime.UtcNow; var serverTime = DateTime.Now; TimeZoneInfo timeZoneInfo = string.IsNullOrEmpty(zoneId) ? null : TimeZoneInfo.FindSystemTimeZoneById(zoneId); var requestedTimeZone = timeZoneInfo; var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var returnVal = GetReturnVal(zoneId, utcTime, serverTime, requestedTimeZone, ip); //List<string> TimeQuery = new List<string>(); using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine($" - {CurrentTimeQuery.UTCTime}"); TimeQuery.Add(CurrentTimeQuery.UTCTime.ToString()); } } return(Ok(returnVal)); }
public IActionResult Get() { try { var utcTime = DateTime.UtcNow; var serverTime = TimeLordService.ConvertTime(DateTime.UtcNow, TimeLordService.CurrentTimeZone); var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(Ok(returnVal)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <CurrentTimeQuery> GetTimeByTimezone(string ip, string timezone) { var utcTime = DateTime.UtcNow; var serverTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, timezone); var timezoneDisplayName = TimeZoneInfo.FindSystemTimeZoneById(timezone).DisplayName; var timeLog = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime, Timezone = timezoneDisplayName }; using (var db = new ClockworkContext()) { await db.CurrentTimeQueries.AddAsync(timeLog); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(timeLog); }
public IActionResult Get() { var utcTime = DateTime.UtcNow; var serverTime = DateTime.Now; var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime, SelectedTimeZone = TimeZoneInfo.Local.Id }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } //return Ok(returnVal); return(Ok(TimeZoneService.GetTime(TimeZoneInfo.Local.Id).ToString())); }
public IActionResult Get([FromBody] string body) { var localDate = JsonConvert.DeserializeObject <List <LocalTime> >(body); var utcTime = DateTime.UtcNow; var serverTime = DateTime.Now; var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); DateTime local = new DateTime(localDate[0].year, localDate[0].month, localDate[0].day, localDate[0].hours, localDate[0].minutes, localDate[0].seconds); TimeSpan offset = utcTime - local; var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, ServerTime = serverTime, LocalTime = local, UTCOffset = offset.TotalHours }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(Ok(returnVal)); }
public IActionResult Get(string timeZoneId) { timeZoneId = HttpUtility.UrlDecode(timeZoneId); var utcTime = DateTime.UtcNow; var userTime = ConvertDateToTimeZone(utcTime, timeZoneId); var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = userTime, TimeZone = timeZoneId }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(Ok(returnVal)); }
public IActionResult Get() { var utcTime = DateTime.UtcNow; var serverTime = DateTime.Now; var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime }; //Save to Database using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); //List the saved timestamps Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(Ok(returnVal)); }
public IActionResult Get(string timezone) { var utcTime = DateTime.UtcNow; var serverTime = DateTime.Now; var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var tzTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(timezone)); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime, TZTime = tzTime, TimeZone = timezone }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(Ok(returnVal)); }
public IActionResult Post([FromBody] string timeZone) { var utcTime = DateTime.UtcNow; var serverTime = DateTime.Now; var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var tzi = TimeZoneInfo.GetSystemTimeZones().SingleOrDefault(t => t.DisplayName.Equals(timeZone)); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime, Timezone = timeZone, TimezoneTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, tzi) }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(Ok(returnVal)); }
public IActionResult Get(string timezone) { DateTime utcTime = DateTime.UtcNow; var serverTime = DateTime.Now; var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var additionalHrs = timezone.Replace(":", "."); additionalHrs = additionalHrs.Replace("p", "+").Replace("m", "-"); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = Convert.ToDateTime(utcTime.AddHours(Convert.ToDouble(additionalHrs))), TimeZone = timezone }; using (var db = new ClockworkContext()) { db.Database.Migrate(); db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(Ok(returnVal)); }
public IActionResult GetZone(string zone) { var zoneTime = new DateTime(); var utcTime = DateTime.UtcNow; foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones()) { if (z.Id == zone) { zoneTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(utcTime, z.Id); } } var returnVal = new CurrentTimeQuery { UTCTime = DateTime.UtcNow, ClientIp = this.HttpContext.Connection.RemoteIpAddress.ToString(), Time = zoneTime, TimeZone = zone }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); db.SaveChanges(); } return(Ok(returnVal)); }
public IActionResult Post(string id) { if (string.IsNullOrEmpty(id)) { return(Json(new { errorMessage = "Select a Time Zone" })); } var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(id); if (timeZoneInfo == null) { return(Json(new { errorMessage = "No TimeZone Found" })); } var utcNow = DateTime.UtcNow; var timeZoneTime = TimeZoneInfo.ConvertTimeFromUtc(utcNow, timeZoneInfo); var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var returnVal = new CurrentTimeQuery { UTCTime = utcNow, ClientIp = ip, Time = timeZoneTime }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); } return(Ok(returnVal)); }
public IActionResult GetCurrentTime(string timeZoneId) { var utcTime = DateTime.UtcNow; var serverTime = DateTime.Now; var requestedTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(serverTime, timeZoneId); var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = requestedTime, TimeZoneId = timeZoneId }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } //Leverage the ID field to hold user-friendly display name returnVal.SetTimeZoneIdToDisplayName(); return(Ok(returnVal)); }
public IActionResult Get(string timeZoneId) { var utcTime = DateTime.UtcNow; var timeZone = !string.IsNullOrWhiteSpace(timeZoneId) ? TimeZoneInfo.FindSystemTimeZoneById(timeZoneId) : TimeZoneInfo.Local; var serverTime = TimeZoneInfo.ConvertTime(utcTime, timeZone); var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime, TimeZone = timeZone.DisplayName }; _context.CurrentTimeQueries.Add(returnVal); var count = _context.SaveChanges(); Console.WriteLine($"{count} records saved to database"); Console.WriteLine(); foreach (var currentTimeQuery in _context.CurrentTimeQueries) { Console.WriteLine($" - {currentTimeQuery.UTCTime}"); } return(Ok(returnVal)); }
public async Task <CurrentTimeQuery> GetTime(string ip) { var utcTime = DateTime.UtcNow; var serverTime = DateTime.Now; var timeLog = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime }; using (var db = new ClockworkContext()) { await db.CurrentTimeQueries.AddAsync(timeLog); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(timeLog); }
public IActionResult Get(string timezone) { var utcTime = DateTime.UtcNow; var serverTime = DateTime.Now; var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); int offset = OffsetFromTimezone(timezone); if (offset == 0) { timezone = string.Empty; } else { serverTime = DateTime.UtcNow.AddHours(offset); } var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime, RequestedTimezone = timezone }; _clockworkContext.CurrentTimeQueries.Add(returnVal); if (_clockworkContext.SaveChanges() > 0) { return(Ok(returnVal)); } else { return(Json(new { status = "error", message = "Error saving to the DB!" })); } }
public IActionResult Get() { var utcTime = DateTime.UtcNow; var serverTime = DateTime.Now; var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime }; using (var db = new ClockworkContext()) { /*TODO: to make this works properly, use tools > NuGet Package Manager > Package Manager Counsole, open "20171207214527_InitialCreate" * in Migration folder and type in "Update-Database" to initialize the database, also check index.cshtml in clockwork.web, get url there need to be updated as well*/ db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(Ok(returnVal)); }
public OkResult Post([FromBody] string timeZoneId) { var utcTime = DateTime.UtcNow; var requestedTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, TZConvert.GetTimeZoneInfo(timeZoneId)); var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var queriedTime = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = requestedTime, TimeZoneId = timeZoneId }; _clockworkContext.CurrentTimeQueries.Add(queriedTime); var count = _clockworkContext.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in _clockworkContext.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } return(Ok()); }
public static void InsertNewEntry(CurrentTimeQuery newEntry) { var db = new ClockworkContext(); // insert new entry to database db.CurrentTimeQueries.Add(newEntry); Console.WriteLine("{0} records(s) saved to database", db.SaveChanges()); }
public async Task <IActionResult> Get(string timezoneId, bool didUserRequest = false, int page = 1, int pageSize = 10, string sort = "desc") { PaginatedList <CurrentTimeQuery> currentTimeQueriesData; var currentTimeQueries = new List <CurrentTimeQuery>(); TimeZoneInfo targetTimezone = TimeZoneInfo.FindSystemTimeZoneById(timezoneId ?? TimeZoneInfo.Local.Id); var utcTime = DateTime.UtcNow; var serverTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, targetTimezone); var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime }; using (var db = new ClockworkContext()) { if (didUserRequest) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); } var tempData = db.CurrentTimeQueries.AsNoTracking(); switch (sort) { case "desc": tempData = tempData.OrderByDescending(r => r.CurrentTimeQueryId); break; case "asc": tempData = tempData.OrderBy(r => r.CurrentTimeQueryId); break; default: break; } currentTimeQueriesData = await PaginatedList <CurrentTimeQuery> .CreateAsync(tempData, page, pageSize); } return(Ok(new { timeRequested = returnVal, currentTimeQueries = currentTimeQueriesData, pageIndex = currentTimeQueriesData.PageIndex, totalPages = currentTimeQueriesData.TotalPages, hasNext = currentTimeQueriesData.HasNextPage, hasPrevious = currentTimeQueriesData.HasPreviousPage })); }
public ActionResult Delete() { using (var db = new ClockworkContext()) { db.CurrentTimeQueries.RemoveRange(db.CurrentTimeQueries); Console.WriteLine("Data Table Truncated"); db.SaveChanges(); } return(Ok()); }
public async Task <IActionResult> Get(string userTimezoneId) { TimeZoneInfo getTimeZoneId = TimeZoneInfo.FindSystemTimeZoneById(userTimezoneId); var utcTime = DateTime.UtcNow; var serverTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, getTimeZoneId); var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); int pageNo = 1; int pageSize = 10; //adding page to my data. Pagination <CurrentTimeQuery> paginationData; var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } //default to desc so new entry can be easily see var data = db.CurrentTimeQueries.AsNoTracking().OrderByDescending(x => x.CurrentTimeQueryId); paginationData = await Pagination <CurrentTimeQuery> .CreateAsync(data, pageNo, pageSize); } return(Ok(new { currentData = returnVal , displayedData = paginationData , pageNumber = 1 , pageNext = paginationData.HasNextPage , pagePrev = paginationData.HasPreviousPage , totalPage = paginationData.TotalPages })); }
public IActionResult Get(string timeZone) { //gets the current utc time DateTime utcTime = DateTime.UtcNow; //get current server time DateTime serverTime = DateTime.Now; //get the ip address of the user string ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); //set default timeZoneSelection to an empty string if they didn't select anything //aka selected '--' string timeZoneSelection = ""; //timeZoneSelectionTime for displaying and adding to database string timeZoneSelectionTime = ""; //if a timeZone has been selected, then the server time is used to calculate the //zoned date time of the selection if (timeZone != null && timeZone != "--") { //get the requested timeZone //DateTimeZone tzTime = DateTimeZoneProviders.Tzdb[timeZone]; timeZoneSelection = timeZone; timeZoneSelectionTime = CurrentTimeQuery .ConvertToDifferentTimeZoneFromUtc(CurrentTimeQuery.GetZoneId(timeZone)).ToShortTimeString(); } var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime, TimeZoneSelectionTime = timeZoneSelectionTime, TimeZoneSelection = timeZoneSelection }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(Ok(returnVal)); }
public IActionResult GetWithTimezone(string timezone) { // Get the correct time to add to the database and send back to client var utcTime = DateTime.UtcNow; var timeZoneTime = DateTime.Now; if (timezone != null) { TimeZoneInfo tzInfo; try { tzInfo = TimeZoneInfo.FindSystemTimeZoneById(timezone); } catch (TimeZoneNotFoundException) { // COuld not find the specified timezone in the system. Return bad request return(BadRequest("Cannot find timezone " + timezone)); } timeZoneTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, tzInfo); } // Get the ip address var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); // Create the object to store in the Database and to send to client var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = timeZoneTime, TimeZoneRequested = timezone }; // Store the object in the database using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } // Send back the object to the client return(Ok(returnVal)); }
public IActionResult Post([FromBody] TimeModel timeOffset)//int timeID TimeModel timeOffset { if (timeOffset.Hours < 0) { timeOffset.Minutes = -timeOffset.Minutes; timeOffset.Seconds = -timeOffset.Seconds; } if (timeOffset.IsDaylightSavings) { timeOffset.Hours += 1; } var utcTime = DateTime.UtcNow; //Get server time in the requested time zone var serverTime = utcTime.AddHours(timeOffset.Hours).AddMinutes(timeOffset.Minutes).AddSeconds(timeOffset.Seconds); var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var timeZoneStamp = serverTime.Subtract(utcTime).ToString(); //Stores requested timeszone's metadata //var timeZone = TimeZoneInfo.GetSystemTimeZones()[timeID]; //var utcTime = DateTime.UtcNow; //var serverTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(timeZone.Id)); //var ip = this.HttpContext.Connection.RemoteIpAddress.ToString() //var timeZoneStamp = serverTime.GetUtcOffset(serverTime).ToString(); //var timeZoneStamp = timeZone.GetUtcOffset(serverTime).ToString(); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime, TimeZoneStamp = timeZoneStamp }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(Ok(returnVal)); }
public CurrentTimeQuery Read(CurrentTimeQuery currentTimeQuery) { using (var context = new ClockworkContext()) { context.CurrentTimeQueries.Add(currentTimeQuery); var count = context.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in context.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } } return(currentTimeQuery); }
public CurrentTimeQuery Create(CurrentTimeQuery query) { using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(query); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime); } return(query); } }
/// <summary> /// Save Current Time Query data to database /// </summary> /// <param name="utcTime"></param> /// <param name="ip"></param> /// <param name="serverTime"></param> /// <param name="timeZoneId"></param> /// <returns></returns> public CurrentTimeQuery AddCurrentTimeQuery(DateTime utcTime, string ip, DateTime serverTime, string timeZoneId) { var currentTimeQuery = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = serverTime, Timezone = !string.IsNullOrEmpty(timeZoneId) && timeZoneId.ToUpper().Contains("SELECT TIMEZONE") ? string.Empty : timeZoneId }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(currentTimeQuery); db.SaveChanges(); } return(currentTimeQuery); }
public IActionResult Get([FromQuery] string timezone) { Console.WriteLine("our timezone was: " + timezone); var utcTime = DateTime.UtcNow; var localTime = DateTime.Now; if (timezone != null) { try { TimeZoneInfo localZone = TimeZoneInfo.FindSystemTimeZoneById(timezone); localTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, localZone); } catch (Exception e) { return(StatusCode(400)); } } var ip = this.HttpContext.Connection.RemoteIpAddress.ToString(); var returnVal = new CurrentTimeQuery { UTCTime = utcTime, ClientIp = ip, Time = localTime, }; using (var db = new ClockworkContext()) { db.CurrentTimeQueries.Add(returnVal); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); foreach (var CurrentTimeQuery in db.CurrentTimeQueries) { Console.WriteLine(" - {0}", CurrentTimeQuery); } } return(Ok(returnVal)); }