public static string CreateLog(PrivateLogDTO dto) { Task <string> str = FirebaseHelper.PostData(dto); str.Wait(); return(str.Result); }
public static bool UpdateLog(PrivateLogDTO dto) { Task <bool> str = FirebaseHelper.UpdateData(dto); str.Wait(); return(str.Result); }
static void MenuOptions_CreateLog() { PrivateLogDTO log = new PrivateLogDTO(); Console.Write("Please enter message to add:"); log.Message = Console.ReadLine(); log.UserID = FirebaseHelper.GetUserID(); log.ID = Guid.NewGuid().ToString(); JMS_Commands.CreateLog(log); log = null; GC.Collect(); }
public static async Task <bool> UpdateData(PrivateLogDTO dto) { dto.Message = Encrypt(dto.Message, Keys.PublicKey); string data = JsonConvert.SerializeObject(dto); var content = new StringContent(data, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PatchAsync(CreateQueryString(Properties.Resources.ProjectID, QueryType.Update, "logs", dto.ID), content); if (response.IsSuccessStatusCode) { Debug.WriteLine("Successful"); return(true); } else { Debug.WriteLine("Unsuccessful"); return(false); } }
public static async Task <PrivateLog> GetLogData(string id) { HttpResponseMessage response = await client.GetAsync(CreateQueryString(Properties.Resources.ProjectID, QueryType.Get, "logs", id)); if (response.IsSuccessStatusCode) { Debug.WriteLine("Successful"); string json = response.Content.ReadAsStringAsync().Result; PrivateLogDTO data = JsonConvert.DeserializeObject <PrivateLogDTO>(json); PrivateLog log = new PrivateLog(data); log.Message = Decrypt(log.Message, Keys.PrivateKey); return(log); } else { Debug.WriteLine("Unsuccessful"); return(null); } }
public static async Task <string> PostData(PrivateLogDTO dto) { dto.Message = Encrypt(dto.Message, Keys.PublicKey); string data = JsonConvert.SerializeObject(dto); var content = new StringContent(data, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PatchAsync(CreateQueryString(Properties.Resources.ProjectID, QueryType.Update, "logs", dto.ID), content); if (response.IsSuccessStatusCode) { Debug.WriteLine("Successful"); string json = response.Content.ReadAsStringAsync().Result; Dictionary <string, string> dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(json); return(dict.Values.FirstOrDefault()); } else { Debug.WriteLine("Unsuccessful"); return(""); } }