public bool AddScoreCard(ScoreCardEnveloppe enveloppe) { // connection bdd using (var context = new LQDMEntities()) { // on trouve le centre de rattachement Centre centre = context.Centre.Where(_ => _.CleExterne == enveloppe.CentreCle).FirstOrDefault(); if (centre == null) { // on essaye d'enregistrer une feuille sans identifier le centre return(false); } // on prends l'évenement (par défaut l'évenement Standard) Evenement e = context.Evenement.Where(_ => _.CentreCentreId == centre.CentreId && _.TypeEvenement == typeEvenement.Standard).FirstOrDefault(); LQModel.ScoreCard sc = new LQModel.ScoreCard(enveloppe.scoreCard, e); context.ScoreCard.Add(sc); context.SaveChanges(); } return(true); }
private async Task <bool> PostScoreCard(ScoreCard sc) { Properties.Settings p = new Properties.Settings(); try { ScoreCardEnveloppe enveloppe = new ScoreCardEnveloppe(); enveloppe.scoreCard = sc; enveloppe.CentreCle = p.CentreCle; JsonSerializerSettings jSettings = new JsonSerializerSettings(); jSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects; jSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; var stringPayload = JsonConvert.SerializeObject(enveloppe, jSettings); // Wrap our JSON inside a StringContent which then can be used by the HttpClient class var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json"); using (var httpClient = new HttpClient()) { // Do the actual request and await the response var httpResponse = await httpClient.PostAsync(p.APIUrl + "/apilq/AddScoreCard", httpContent); // If the response contains content we want to read it! if (httpResponse.Content != null) { var responseContent = await httpResponse.Content.ReadAsStringAsync(); bool result = false; if (bool.TryParse(responseContent, out result) && result) { return(true); } } } } catch (Exception ex) { logMessage(string.Format("Erreur sur l'envoi de la fiche de score {0} : {1} ", sc.ToString(), ex.Message), alerte.ERREUR); return(false); } return(false); }