// use: tylko po przycisku zaloguj public static async Task Login(String username, String password) { try { ClientBackend.StroreCredentials(username, password); String json = await ClientBackend.GetResponse("/user"); ServerAnswerRecievedUser userData = JsonConvert.DeserializeObject <ServerAnswerRecievedUser>(await ClientBackend.GetResponse("/user")); if (userData.Status.Equals("success", StringComparison.OrdinalIgnoreCase)) { //ClientBackend.StroreCredentials(username, password); //zapisz dane do pliku jesli sie udalo zalogowac //jesli nie exception throw new LoginException() } else { throw new LoginException(); } } catch (LoginException) { throw new LoginException(); } catch (System.Exception) { throw new UnknownException(); } }
// use: sieganie po posty w konkretnym eventcie public static async Task <ObservableCollection <Post> > GetPosts(int eventID) { try { ServerAnswerRecievedPosts sarp = JsonConvert.DeserializeObject <ServerAnswerRecievedPosts>(await ClientBackend.GetResponse("/posts/" + eventID)); if (sarp.Status.Equals("success", StringComparison.OrdinalIgnoreCase)) { eventMap[eventID].Posts = sarp.PostList; if (eventMap[eventID].Posts == null) { throw new System.Exception(); } return(eventMap[eventID].Posts); } else { throw new DataFormatException(); } } catch (DataFormatException) { throw; } catch (System.Exception) { throw new UnknownException(); } }
public static async Task <ServerAnswerRecievedUser> GetUser(int userID) { try { String json = await ClientBackend.GetResponse("/user"); ServerAnswerRecievedUser data = JsonConvert.DeserializeObject <ServerAnswerRecievedUser>(await ClientBackend.GetResponse("/user/" + userID)); return(data); } catch (System.Exception) { throw new UnknownException(); } }
// use: sieganie po eventy usera public static async Task <ObservableCollection <Event> > GetEvents(int userID) { try { ServerAnswerRecievedEvents recievedEvent = JsonConvert.DeserializeObject <ServerAnswerRecievedEvents> (await ClientBackend.GetResponse("/events/" + userID)); if (recievedEvent.Status.Equals("success", StringComparison.OrdinalIgnoreCase)) { eventMap.Clear(); events = recievedEvent.EventList; if (events == null) { throw new UnknownException(); } foreach (Event element in events) { eventMap.Add(element.ID, element); } return(events); } else { throw new DataFormatException(); } } catch (DataFormatException) { throw; } catch (System.Exception) { throw new UnknownException(); } }