public async Task <IActionResult> Post([FromBody] string time) { if (String.IsNullOrWhiteSpace(time) || !time.Contains(timeSeparator)) { var message = "Input should be in format 00:00"; _logger.LogDebug(message); return(BadRequest(message)); } try { var splittedValues = time.Split(timeSeparator); var timeModel = new ClockModel { Hour = Convert.ToInt32(splittedValues[0]), Min = Convert.ToInt32(splittedValues[1]) }; var angle = await _ClockBusiness.GetAngle(timeModel); return(Ok(new { Message = $"Angle between {timeModel.Hour} h and {timeModel.Min} m is {angle} degree.", Angle = angle })); } catch (Exception ex) { _logger.LogDebug(ex.Message); return(BadRequest(ex.Message)); } }
/// <summary> /// Handler /// </summary> /// <param name="eventdate"></param> /// <returns></returns> public async Task Handler(object eventdate) { if (eventdate != null) { var eventData = JsonConvert.DeserializeObject <EventData>(eventdate.ToString()); var splittedValues = eventData.Data.Split(timeSeparator); var timeModel = new ClockModel { Hour = Convert.ToInt32(splittedValues[0]), Min = Convert.ToInt32(splittedValues[1]) }; try { var angleValue = await _ClockBusiness.GetAngle(timeModel); // TODo Save in to database; // Call to Database repo } catch (Exception ex) { _logger.LogError(ex.Message); } } }