public async Task <ActionResult <Reading> > Post(Guid sensorId, [FromBody] ReadingRequest request) { var reading = _converter.ToReadingValue(request); var result = await _services.Create(sensorId, reading); if (result == null) { return(NotFound("Reading does not exist")); } return(Ok(_converter.ToReadingResponse(result))); }
public async Task <ActionResult <Reading> > Put(Guid id, [FromBody] ReadingRequest request) { var reading = _converter.ToReadingValue(request); var response = await _services.Update(id, reading); if (request == null) { return(NotFound()); } return(Ok(_converter.ToReadingResponse(response))); }
public async Task <ActionResult <Guid> > Post([FromBody] ReadingRequest reading, CancellationToken cancellationToken) { var entity = await _context.Readings.AddAsync(new Reading { Value = reading.Value, Scale = reading.Scale, ReadingId = Guid.NewGuid(), Taken = reading.Taken ?? DateTime.UtcNow }, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(entity.Entity.ReadingId); }
protected abstract void Authenticate(); //Authenticate for API Method /// <summary> /// GoogleCalendarからカレンダー内のイベントリストを取得する /// </summary> /// <returns>カレンダー内のイベント</returns> public CalendarEvent[] GetEventList(ReadingRequest reading_request) { CalendarEvent[] eventlist; //Ensure Consistency if (reading_request.enabled_filter) { //Filter Consistency if (reading_request.start_filter >= reading_request.end_filter) { reading_request.enabled_filter = false; } } if (reading_request.number_of_event <= 0 || reading_request.number_of_event > 2500) { //Number Obtained Consistency reading_request.number_of_event = 250; } if (reading_request.calendar_id == null) { //CalendarID Consistency reading_request.calendar_id = "primary"; } //-------------------------- EventsResource.ListRequest request = _service.Events.List(reading_request.calendar_id); request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime; //Fixed request.SingleEvents = true; //Fixed if (reading_request.enabled_filter) { //Filter Settings request.TimeMin = reading_request.start_filter; request.TimeMax = reading_request.end_filter; } request.MaxResults = reading_request.number_of_event; Events list = request.Execute(); //Request EventsList if (list.Items == null && list.Items.Count <= 0) { return(null); } //Check Items eventlist = new CalendarEvent[list.Items.Count]; //Redefinition Array for (int i = 0; i < list.Items.Count; i++) { //Storage ItemData Event item = list.Items[i]; eventlist[i].summary = item.Summary; eventlist[i].id = item.Id; eventlist[i].color = item.ColorId; eventlist[i].description = item.Description; eventlist[i].location = item.Location; //DateTime Consistency if (item.Start.DateTime != null) { eventlist[i].start = DateTime.Parse(item.Start.DateTime.ToString()); eventlist[i].end = DateTime.Parse(item.End.DateTime.ToString()); } else { eventlist[i].start = DateTime.Parse(item.Start.Date.ToString()); eventlist[i].end = DateTime.Parse(item.End.Date.ToString()); eventlist[i].dateonly = true; } } return(eventlist); }
public ReadingValue ToReadingValue(ReadingRequest readingRequest) { return(new ReadingValue(readingRequest.Value, readingRequest.Units, readingRequest.TimeStamp)); }