public async Task <bool> SendObservation(ObsValue obsValue) { HttpResponseMessage response = new HttpResponseMessage(); string obsValueJson = JsonConvert.SerializeObject(obsValue); using (HttpContent body = new StringContent(obsValueJson, Encoding.UTF8, "application/json")) { try { response = await _client.PostAsync($"{_client.BaseAddress + _pathServiceObs}", body); response.EnsureSuccessStatusCode(); } catch { throw new HttpRequestException($"Erro na requisição ao serviço. Requisição retornou com o status '{response.StatusCode}'"); } finally { response.Dispose(); body.Dispose(); } } return(response.StatusCode == HttpStatusCode.OK); }
private async void InserirComObs(string messageObs, DateTime dtPonto) { string data = dtPonto.ToString("dd/MM"); string obs = messageObs; var dtPontoValue = new DateValue { Data = data, Evento = dtPonto.GetEventForTime().Result, Hora = dtPonto.ToShortTimeString(), Autor = "Leonardo Guilen", }; var obsValue = new ObsValue { Data = data, Observacao = obs }; try { Parallel.Invoke(new ParallelOptions { CancellationToken = CancellationToken.None, MaxDegreeOfParallelism = 2, TaskScheduler = null }, async() => { Task.FromResult(await sendDate.PostDateValuesAsync(dtPontoValue)) .ConfigureAwait(false).GetAwaiter(); }, async() => { Task.FromResult(await sendDate.PostObsValuesAsync(obsValue)) .ConfigureAwait(false).GetAwaiter(); }); } catch (Exception ex) { confirmLoader.IsVisible = false; sendError.IsVisible = true; await DisplayAlert("ERRO", $"Encontramos um problema ao salvar o seu ponto. Mais detalhes {ex.Message}", "OK"); } confirmLoader.IsVisible = false; confirmedImg.IsVisible = true; await Task.Delay(1500); await DisplayAlert("SUCESSO", "Seu novo ponto foi salvo com sucesso!", "OK"); await Navigation.PopAllPopupAsync(); }
public async Task <bool> PostObsValuesAsync(ObsValue obsValue) { bool result; try { result = await _dateService.SendObservation(obsValue); } catch (HttpRequestException) { result = false; } return(result); }
//TODO:Pre Branches Evaluate public Guid?Evaluate(ObsValue other, ObsValue current) { if (ResponseType.Equals("=")) { object responseObject = Response; if (current.Type == typeof(Guid?)) { responseObject = new Guid(Response); } if (current.Type == typeof(decimal?)) { responseObject = Convert.ToDecimal(Response); } if (current.Type == typeof(DateTime?)) { responseObject = Convert.ToDateTime(Response); } return(responseObject.Equals(current.Value) ? GotoQuestionId : null); } return(null); }
public SetResponse Evaluate(ObsValue current) { if (ResponseType.Equals("=")) { object responseObject = Response; if (current.Type == typeof(Guid?)) { responseObject = new Guid(Response); } if (current.Type == typeof(decimal?)) { responseObject = Convert.ToDecimal(Response); } if (current.Type == typeof(DateTime?)) { responseObject = Convert.ToDateTime(Response); } return(responseObject.Equals(current.Value) ? new SetResponse(RefQuestionId, ActionId, Content, Rank, ConditionId, ResponseComplex) : null); } return(null); }