public async Task <ActionResult> Book( TimeJson req) { if (!req.Valid) { _log.LogWarning("Rejected input {input}", req); return(BadRequest()); } var getTime = new GetTime( sub: GetUserId(), host: req.Host, start: req.Start ); var getTimeResult = (await _db.Submit(_creds, getTime)) .SingleOrDefault(); if (getTimeResult == null) { return(NotFound()); } var conflictsQuery = new GetBookingConflict( sub: GetUserId(), host: getTimeResult.Host, start: getTimeResult.Start, end: getTimeResult.End ); var conflictsResult = (await _db.Submit(_creds, conflictsQuery)) .SingleOrDefault(); if (conflictsResult == null) { var book = new BookCommand( sub: GetUserId(), host: getTimeResult.Host, start: getTimeResult.Start ); var r = await _db.Submit(_creds, book); return(Created( $"bookings/{getTimeResult.Start}", r.Select(x => new TimeJson { Host = x.Host, Name = x.Name, Start = x.Start, Dur = (int)((x.End - x.Start) / 60) }).Single())); } else { return(Conflict(conflictsResult)); } }
//=================================================================================================================== private IEnumerator Start() { //Try to GET the current time. WWW www = new WWW(URL); yield return(www); //If get fails, try again every 3 seconds. while (!string.IsNullOrEmpty(www.error)) { yield return(new WaitForSeconds(3)); www = new WWW(URL); yield return(www); } //Get some components. GameObject g = GameObject.FindWithTag("Player"); move = g.GetComponent <MoveCtrl>(); blur = g.GetComponentInChildren <UnityStandardAssets.ImageEffects.BlurOptimized>(); // Prepare received data. TimeJson timeJson = new TimeJson(); JsonUtility.FromJsonOverwrite(www.text, timeJson); //Unix timestamp is seconds past epoch System.DateTime dtDateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); string currentDate = dtDateTime.AddSeconds(timeJson.timestamp - timeJson.gmtOffset).ToLocalTime().ToString(); //Set up current time and end time. System.DateTime currentTime = System.DateTime.Parse(currentDate); System.DateTime startTime = new System.DateTime(1991, 5, 8, 15, 15, 0); //Build the first room. GameObject r = Instantiate(roomPrefab, Vector3.zero, Quaternion.identity) as GameObject; RoomCtrl rCtrl = r.GetComponent <RoomCtrl>(); rCtrl.setEndTime(startTime.AddYears(1), currentTime); rCtrl.setName(0); //Pass the current time to the time controller, it'll take it from here. GetComponent <TimeCtrl>().setCurrentTime(currentTime); //Tell the UI that we are ready, we can start the game. GameObject.FindWithTag("UI").GetComponent <UICtrl>().Ready = true; }
private void buttonGetBirthdayFact_Click(object sender, EventArgs e) { string date = birthdayLabel2.Text; if (!string.IsNullOrEmpty(date)) { TimeJson timeJson = parseTime(date); var factJson = m_WebController.DownloadWebData <FactJson>( new Uri(k_UrlGetFactByDatePath + timeJson.Month + "/" + timeJson.Day + k_GetFactByDateParams)); textBoxFact.Clear(); textBoxFact.AppendText(factJson.text); textBoxFact.AppendText(Environment.NewLine); textBoxFact.AppendText("Fact Date : " + timeJson.Month + "/" + timeJson.Day + " Event Year : " + factJson.year); } }
//=================================================================================================================== private IEnumerator updateTime() { WWW www = new WWW(URL); yield return(www); //If the string is valid. if (string.IsNullOrEmpty(www.error)) { //Prepare received data. TimeJson timeJson = new TimeJson(); JsonUtility.FromJsonOverwrite(www.text, timeJson); //Unix timestamp is seconds past epoch System.DateTime dtDateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); string currentDate = dtDateTime.AddSeconds(timeJson.timestamp - timeJson.gmtOffset).ToLocalTime().ToString(); System.DateTime currentTime = System.DateTime.Parse(currentDate); GetComponent <TimeCtrl>().setCurrentTime(currentTime); } }