public async Task <bool> AddChannelAsync(Channel c) { bool result = false; if ((c.Name.Replace(" ", "")).Count() == 0) { return(false); } if ((c.AccessCode.Replace(" ", "")).Count() == 0) { return(false); } try { JObject payload = JObject.FromObject(c); payload.Remove("Id"); string response = await CallAPI(@"api/Channels", HTTPMETHOD.POST, payload); result = true; }catch (Exception e) { await HelpersClass.ShowDialogAsync("Something went wrong:" + e.Message); } return(result); } //done
internal async Task ReportSpamForFeedback(string fbID, string userID) { try { var result = await App.MobileService .InvokeApiAsync <bool>("Admin", HttpMethod.Post, new Dictionary <string, string>() { { "SpamfeedbackID", fbID }, { "userReportID", userID } }); }catch (Exception e) { await HelpersClass.ShowDialogAsync("Internet và app don't talk anymore: " + e.Message); } }
public async Task <bool> CheckAccessCodeValid(string accessCode) { try { return(await App.MobileService .InvokeApiAsync <bool>("Admin", HttpMethod.Post, new Dictionary <string, string>() { { "accessCode", accessCode } })); } catch (Exception e) { await HelpersClass.ShowDialogAsync("Check Access code valid failed: " + e.Message); } return(true); }
public async Task <List <Channel> > GetChannelFilter(string userID) { try { var l = await App.MobileService.InvokeApiAsync <List <Channel> >("Admin", HttpMethod.Get, new Dictionary <string, string>() { { "FeedbackUserID", userID } }); return(l); }catch (Exception e) { await HelpersClass.ShowDialogAsync("Có chiện gì xảy ra rồi: " + e.Message); return(null); } }
internal async Task <bool> ReportSpamForComment(string cmtID, string userID) { try { var result = await App.MobileService .InvokeApiAsync <bool>("Admin", HttpMethod.Post, new Dictionary <string, string>() { { "SpamCommentID", cmtID }, { "userReportID", userID } }); return(result); } catch (Exception e) { await HelpersClass.ShowDialogAsync("Internet và app don't talk anymore: " + e.Message); } return(false); }
public async Task <Channel> SearchChannelByCode(string AccessCode) { var list = await ChannelTable.Where(c => c.AccessCode == AccessCode).ToListAsync(); if (list.Count == 1) { return(list[0]); } else { await HelpersClass.ShowDialogAsync("Something might went wrong with channel duplication"); return(new Channel()); } }
public async Task <List <Feedback> > GetFeedbackByUserAsync(string userId) { List <Feedback> result = new List <Feedback>(); try { string response = await CallAPI($@"api/Feedbacks/User/{userId}", HTTPMETHOD.GET, null); result = JsonConvert.DeserializeObject <List <Feedback> >(response); } catch (Exception e) { await HelpersClass.ShowDialogAsync("Something went wrong:" + e.Message); } return(result); }
} //done public async Task <IEnumerable <Channel> > GetChannelAsync(string userId) { IEnumerable <Channel> results = null; try { string response = await CallAPI($@"api/Channels/user/{userId}", HTTPMETHOD.GET, null); results = JsonConvert.DeserializeObject <IEnumerable <Channel> >(response); } catch (Exception e) { await HelpersClass.ShowDialogAsync("Something went wrong:" + e.Message); } return(results); } //done
public async Task <IEnumerable <Feedback> > GetFeedbacksByChannelAsync(int id) { IEnumerable <Feedback> results = null; try { string response = await CallAPI($@"api/Feedbacks/Channel/{id}/{MainPage.instance.user.UserId}", HTTPMETHOD.GET, null); results = JsonConvert.DeserializeObject <IEnumerable <Feedback> >(response); } catch (Exception e) { await HelpersClass.ShowDialogAsync("Something went wrong:" + e.Message); } return(results); }
public async Task <Comment> AddComment(Comment c) { try { JObject payload = JObject.FromObject(c); payload.Remove("id"); payload.Remove("createdAt"); var response = await CallAPI($@"api/Comments", HTTPMETHOD.POST, payload); var comment = JsonConvert.DeserializeObject <Comment>(response); return(comment); } catch (Exception e) { await HelpersClass.ShowDialogAsync(e.Message); } return(null); }
public async Task <Feedback> AddFeedbackAsync(Feedback feedback) { Feedback result = null; try { JObject payload = JObject.FromObject(feedback); payload.Remove("Id"); payload.Remove("createdAt"); string response = await CallAPI(@"api/Feedbacks", HTTPMETHOD.POST, payload); result = JsonConvert.DeserializeObject <Feedback>(response); } catch (Exception e) { await HelpersClass.ShowDialogAsync("Something went wrong:" + e.Message); } return(result); }
public async Task <Channel> GetChannelById(int id) { try { var response = await CallAPI($@"api/Channels/{id}", HTTPMETHOD.GET, null); var channel = JsonConvert.DeserializeObject <Channel>(response); if (channel == null) { throw new ArgumentNullException(); } return(channel); }catch { await HelpersClass.ShowDialogAsync("Something might went wrong with channel duplication"); return(new Channel()); } }
public async Task <bool> DeleteChannel(Channel c) { //Get the feedback from channel c try { var response = await CallAPI($@"api/Channels/{c.Id}", HTTPMETHOD.DELETE, null); if (response == null) { throw new ArgumentNullException(); } return(true); } catch (Exception e) { await HelpersClass.ShowDialogAsync("Something went wrong: " + e.Message); return(false); } }
//public async Task<MobileServiceUser> CustomLogin(string username, string password) //{ // string message; // MobileServiceUser user = null; // // Use the PasswordVault to securely store and access credentials. // PasswordVault vault = new PasswordVault(); // PasswordCredential credential = null; // try // { // // get the token // //var token = await GetAuthenticationToken(username, password); // //// authenticate: create and use a mobile service user // //user = new MobileServiceUser(token.Guid); // //user.MobileServiceAuthenticationToken = token.Access_Token; // //// Create and store the user credentials. // //credential = new PasswordCredential("custom", // // user.UserId, user.MobileServiceAuthenticationToken); // //vault.Add(credential); // //App.MobileService.CurrentUser = user; // } // catch (MobileServiceInvalidOperationException) // { // message = "You must log in. Login Required"; // await HelpersClass.ShowDialogAsync(message); // } // return user; //} //public async Task<AuthenticationToken> //GetAuthenticationToken(string username, string email, string password) //{ // try // { // //using (var pc = new PrincipalContext(ContextType.Domain)) // //{ // // using (var up = new UserPrincipal(pc)) // // { // // up.SamAccountName = username; // // up.EmailAddress = email; // // up.SetPassword(password); // // up.Enabled = true; // // up.ExpirePasswordNow(); // // up.Save(); // // } // //} // } // catch (MobileServiceInvalidOperationException exception) // { // //if (string.Equals(exception.Message, "invalid_grant")) // // throw new InvalidGrantException("Wrong credentails", // // exception); // //else // // throw; // } // return null; //} public async Task <MobileServiceUser> Login(MobileServiceAuthenticationProvider provider) { string message; MobileServiceUser user = null; // This sample uses the Facebook provider. // Use the PasswordVault to securely store and access credentials. PasswordVault vault = new PasswordVault(); PasswordCredential credential = null; try { // Login with the identity provider. user = await App.MobileService .LoginAsync(provider); // Create and store the user credentials. credential = new PasswordCredential(provider.ToString(), user.UserId, user.MobileServiceAuthenticationToken); JObject obj = new JObject(); obj.Add("Id", user.UserId); obj.Add("Name", credential.UserName); vault.Add(credential); string response = await CallAPI(@"/api/Users", HTTPMETHOD.POST, obj); message = string.Format("You are now logged in - {0}", user.UserId); } catch (MobileServiceInvalidOperationException) { message = "You must log in. Login Required"; await HelpersClass.ShowDialogAsync(message); } catch { } return(user); }