Api Sample

user
using System;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using LetsHang.Models;
using Newtonsoft.Json.Linq;
using LetsHang.Helpers;
using System.Collections.ObjectModel;

namespace LetsHang.Services
{
    public class ApiServices
    {

        //public async Task<bool> RegisterAsync(string username, string Password, string confirmPassword, string firstname, string lastname, string email, string phonenumber)
        public async Task<string> RegisterAsync(string Password, string confirmPassword, string firstname, string lastname, string email, string phonenumber)
        {
            string isRegistered = "";
            var client = new HttpClient();
            var model = new RegisterBindingModel
            {
                //UserName = username,
                Password = Password,
                ConfirmPassword = confirmPassword,
                FirstName = firstname,
                LastName = lastname,
                Email = email,
                PhoneNumber = phonenumber,
                //ImageFile = "http://letshang.azurewebsites.net/Images/UserImages/defaultuser.jpg"
                ImageFile = "http://manishkr38-001-site4.itempurl.com/Images/UserImages/defaultuser.jpg"
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                //var response = await client.PostAsync("http://www.edukot.com/user/json/UserRegister.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/account/Register",content);
                isRegistered = await response.Content.ReadAsStringAsync();
                //return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return isRegistered;

        }

        public async Task<bool> UpdateFCMDeviceToken(string userId, string fcmToken)
        {
            var client = new HttpClient();


            var model = new UserBindingModel
            {
                id = userId,
                AccessToken = fcmToken
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/SendHangTimeInvitationSquads.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/account/UpdateFCMDeviceToken", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/UserRegister.php",new  StringContent(myJson, Encoding.UTF8, "application/json") );
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }

        public async Task<string[]> LoginAsync(string email, string password)
        {
            //string isLoginSuccess = "";
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                Email = email,
                Password = password
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/account/Login", content);
                var jwt = await response.Content.ReadAsStringAsync();
                JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                var accessToken = jwtDynamic.Value<string>("accessToken");
                var id = jwtDynamic.Value<string>("id");
                var userNam = jwtDynamic.Value<string>("userName");
                var pass = jwtDynamic.Value<string>("passwordHash");

                var emails = jwtDynamic.Value<string>("email");
                var fName = jwtDynamic.Value<string>("firstName");
                var lName = jwtDynamic.Value<string>("lastName");
                var pNumber = jwtDynamic.Value<string>("phoneNumber");
                var Ifile = jwtDynamic.Value<string>("imageFile");



                Debug.WriteLine(jwt);

                string[] info = new string[9];
                info[0] = accessToken;
                info[1] = id;
                info[2] = userNam;
                info[3] = pass;

                info[4] = emails;
                info[5] = fName;
                info[6] = lName;
                info[7] = pNumber;
                info[8] = Ifile;

                //  return accessToken;
                return info;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            // return "abc";
            return null;

        }

        public async Task<bool> ForgotPassword(string email)
        {
            var client = new HttpClient();


            var model = new UserBindingModel
            {
                Email = email
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Account/ForgotPassword", content);
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }


        /*
        public async Task<string[]> LoginAsync(string email, string password)
        {
            var KeyValues = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>("username",email),
                new KeyValuePair<string, string>("password",password)
            };

            try
            {
                var request = new HttpRequestMessage(HttpMethod.Post, "http://www.edukot.com/user/json/UserLogin.php");
                //var request = new HttpRequestMessage(HttpMethod.Post, "http://letshang.azurewebsites.net/api/account/Login");
                request.Content = new FormUrlEncodedContent(KeyValues);
                var client = new HttpClient();
                var response = await client.SendAsync(request);
                //var content = await response.Content.ReadAsStringAsync();
                var jwt = await response.Content.ReadAsStringAsync();
                JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                var accessToken = jwtDynamic.Value<string>("AccessToken");
                var id = jwtDynamic.Value<string>("id");
                var userNam = jwtDynamic.Value<string>("UserName");
                var pass = jwtDynamic.Value<string>("Password");

                var emails = jwtDynamic.Value<string>("Email");
                var fName = jwtDynamic.Value<string>("FirstName");
                var lName = jwtDynamic.Value<string>("LastName");
                var pNumber = jwtDynamic.Value<string>("PhoneNumber");
                var Ifile = jwtDynamic.Value<string>("ImageFile");
                    


                Debug.WriteLine(jwt);

                string[] info = new string[9];
                info[0] = accessToken;
                info[1] = id;
                info[2] = userNam;
                info[3] = pass;

                info[4] = emails;
                info[5] = fName;
                info[6] = lName;
                info[7] = pNumber;
                info[8] = Ifile;

                //  return accessToken;
                return info;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            // return "abc";
            return null;

        }
        */

        public async Task<string> CreateHangTimes(string title, string description, string location, string eventDate, string timeFrom, string timeTo, string isprivate, string currentUserId, string currentUserName, DateTime eventDataActual)
        {
            var client = new HttpClient();
            var model = new HangTimeBindingModel
            {
                Title = title,
                Description = description,
                Location = location,
                EventDate = eventDate,
                TimeFrom = timeFrom,
                TimeTo = timeTo,
                isPrivate = isprivate,
                CreatedBy = currentUserId,
                EventDateActual = eventDataActual,
                isActive = "True",
                ImageFile = "http://letshang.azurewebsites.net/Images/HangtimeImages/defaulthangtime.jpg"
                    
                //CreatedByUserName = currentUserName

            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyMUBnbWFpbC5jb20iLCJqdGkiOiJhMGVlZTczZi1jODVlLTRhNDMtOGM1Mi05ODUwNjM4YWYxMGMiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6ImExYTRmNWQ3LTgxYzctNDE0Yy1hZTk3LTlhZDQ2OGNlYzQ2MyIsImV4cCI6MTUyNzU5NTE2MCwiaXNzIjoiaHR0cDovL2xldHNoYW5nLmF6dXJld2Vic2l0ZXMubmV0LyIsImF1ZCI6Imh0dHA6Ly9sZXRzaGFuZy5henVyZXdlYnNpdGVzLm5ldC8ifQ.QGTAd5vWC0bdQH5J9iMZfbr9oenQlPI_PpavnPuR5Lw");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/CreateHangTimes.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Hangtime/CreateHangtime", content);
                //var jwt = await response.Content.ReadAsStringAsync();
                //JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                var HangId = await response.Content.ReadAsStringAsync();
                //var HangId = jwtDynamic.Value<string>("HangTimeId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");

                //var response = await client.PostAsync("http://www.edukot.com/user/json/UserRegister.php",new  StringContent(myJson, Encoding.UTF8, "application/json") );
                //return response.IsSuccessStatusCode;
                return HangId.ToString();
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return "no data";
            /*
                        Uri geturi = new Uri("http://www.edukot.com/user/json/UserRegister.php?data=" + myJson); //replace your url  

                        System.Net.Http.HttpResponseMessage responseGet = await client.GetAsync(geturi);
                        string response = await responseGet.Content.ReadAsStringAsync();
                        return true;

                */

        }

        public async Task<List<HangTimeBindingModel>> GetHangTimes()
        {
            try
            {

                var httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/gethangtimes.php");
                var json = await httpClient.GetStringAsync("http://letshang.azurewebsites.net/api/Hangtime/GetAllHangtimes");
                var taskModels = JsonConvert.DeserializeObject<List<HangTimeBindingModel>>(json);
                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<string> CreateSquads(string name, string location, string description, string adminUser)
        {
            var client = new HttpClient();
            var model = new SquadBindingModel
            {
                Name = name,
                //Location = location,
                Description = description,
                AdminUser = adminUser,
                ImageFile = "http://letshang.azurewebsites.net/Images/SquadImages/defaultsquad.jpg"
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/CreateSquad.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/CreateSquad", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/UserRegister.php",new  StringContent(myJson, Encoding.UTF8, "application/json") );

                var SquadId = await response.Content.ReadAsStringAsync();

                //var jwt = await response.Content.ReadAsStringAsync();
                //JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                //var SquadId = jwtDynamic.Value<int>("squadID");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");

                //var response = await client.PostAsync("http://www.edukot.com/user/json/UserRegister.php",new  StringContent(myJson, Encoding.UTF8, "application/json") );
                //return response.IsSuccessStatusCode;
                //return SquadId.ToString();
                return SquadId.ToString();



                //return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return "no data";
            /*
                        Uri geturi = new Uri("http://www.edukot.com/user/json/UserRegister.php?data=" + myJson); //replace your url  

                        System.Net.Http.HttpResponseMessage responseGet = await client.GetAsync(geturi);
                        string response = await responseGet.Content.ReadAsStringAsync();
                        return true;

                */

        }

        /*


public async Task<List<NotificationBindingModel>> GetNotifications(string currentUserId)
        {
            var client = new HttpClient();
            var model = new NotificationBindingModel
            {
                CurrentUserId = currentUserId
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var response = await client.PostAsync("http://www.edukot.com/user/json/getNotifications.php", content);

                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<NotificationBindingModel>>(jwt);
               // JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
               //// var HangId = jwtDynamic.Value<string>("HangTimeId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return null;

        }


         */

        public async Task<List<UserBindingModel>> GetFriendsList(string currentUserId)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                CurrentUserId = currentUserId
            };

            try
            {

                //var httpClient = new HttpClient();
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(json);
                //return taskModels;
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                //var response = await client.PostAsync("http://www.edukot.com/user/json/getfriendslist.php", content);
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Friends/GetFriendsList", content);

                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(jwt);
                // JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                //// var HangId = jwtDynamic.Value<string>("HangTimeId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<List<SelectableData<UserBindingModel>>> GetSelectedFriendsList(string currentUserId)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                CurrentUserId = currentUserId
            };

            try
            {

                //var httpClient = new HttpClient();
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/getselectedfriendslist.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Friends/AddFriendsList", content);
                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<SelectableData<UserBindingModel>>>(jwt);
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getselectedfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<SelectableData<UserBindingModel>>>(jwt);
                //var taskModels = JsonConvert.DeserializeObject<ObservableCollection<SquadBindingModel>>(json);


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<List<SelectableData<UserBindingModel>>> InviteHangtimeUsersList(string currentUserId)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                CurrentUserId = currentUserId
            };

            try
            {

                //var httpClient = new HttpClient();
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/getselectedfriendslist.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Hangtime/InviteHangtimeUsersList", content);
                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<SelectableData<UserBindingModel>>>(jwt);
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getselectedfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<SelectableData<UserBindingModel>>>(jwt);
                //var taskModels = JsonConvert.DeserializeObject<ObservableCollection<SquadBindingModel>>(json);


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<List<SelectableData<UserBindingModel>>> InviteSquadUsersList(string currentUserId)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                CurrentUserId = currentUserId
            };

            try
            {

                //var httpClient = new HttpClient();
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/getselectedfriendslist.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/InviteSquadUsersList", content);
                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<SelectableData<UserBindingModel>>>(jwt);
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getselectedfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<SelectableData<UserBindingModel>>>(jwt);
                //var taskModels = JsonConvert.DeserializeObject<ObservableCollection<SquadBindingModel>>(json);


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }




        /*
        public async Task<List<SelectableData<UserBindingModel>>> GetSelectedFriendsList()
        {
            try
            {

                var httpClient = new HttpClient();
                var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getselectedfriendslist.php");
                var taskModels = JsonConvert.DeserializeObject<List<SelectableData<UserBindingModel>>>(json);
                //var taskModels = JsonConvert.DeserializeObject<ObservableCollection<SquadBindingModel>>(json);


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }


        //public async Task<ObservableCollection<SquadBindingModel>> GetSquadList()
        public async Task<List<SelectableData<SquadBindingModel>>> GetSelectedSquadList()
        {
            try
            {

                var httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getselectedsquadlist.php");
                var json = await httpClient.GetStringAsync("http://letshang.azurewebsites.net/api/Squad/AddSquadList");
                var taskModels = JsonConvert.DeserializeObject<List<SelectableData<SquadBindingModel>>>(json);
                //var taskModels = JsonConvert.DeserializeObject<ObservableCollection<SquadBindingModel>>(json);


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        */

        public async Task<List<SelectableData<SquadBindingModel>>> GetSelectedSquadList()
        {
            var client = new HttpClient();


            var model = new UserBindingModel
            {
                CurrentUserId = Settings.CurrentUserId
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/AddSquadList", content);
                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<SelectableData<SquadBindingModel>>>(jwt);

                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<List<SquadBindingModel>> GetSquadList()
        {
            try
            {

                var httpClient = new HttpClient();
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getsquadlist.php");
                //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyMUBnbWFpbC5jb20iLCJqdGkiOiJhMGVlZTczZi1jODVlLTRhNDMtOGM1Mi05ODUwNjM4YWYxMGMiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6ImExYTRmNWQ3LTgxYzctNDE0Yy1hZTk3LTlhZDQ2OGNlYzQ2MyIsImV4cCI6MTUyNzU5NTE2MCwiaXNzIjoiaHR0cDovL2xldHNoYW5nLmF6dXJld2Vic2l0ZXMubmV0LyIsImF1ZCI6Imh0dHA6Ly9sZXRzaGFuZy5henVyZXdlYnNpdGVzLm5ldC8ifQ.QGTAd5vWC0bdQH5J9iMZfbr9oenQlPI_PpavnPuR5Lw");
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var json = await httpClient.GetStringAsync("http://letshang.azurewebsites.net/api/Squad/GetAllSquads");
                var taskModels = JsonConvert.DeserializeObject<List<SquadBindingModel>>(json);
                //var taskModels = JsonConvert.DeserializeObject<ObservableCollection<SquadBindingModel>>(json);


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<List<SquadBindingModel>> GetSquadListForCurrentUser()
        {
            var client = new HttpClient();


            var model = new UserBindingModel
            {
                CurrentUserId = Settings.CurrentUserId
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/GetAllSquads", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/GetSquadListForCurrentUser", content);
                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<SquadBindingModel>>(jwt);

                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        //Not in use Mk
        public async Task<bool> InviteHangTimeUser(string fromUserId, string hangTimeId, string toUserId, string status)
        {
            var client = new HttpClient();


            var model = new InviteHangTimeUserModel
            {
                FromUserId = fromUserId,
                HangTimeId = hangTimeId,
                ToUserId = toUserId,
                Status = status
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://www.edukot.com/user/json/InviteHangTimeUser.php", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/InviteHangTimeUser.php", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/UserRegister.php",new  StringContent(myJson, Encoding.UTF8, "application/json") );
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;
            /*
                        Uri geturi = new Uri("http://www.edukot.com/user/json/UserRegister.php?data=" + myJson); //replace your url  

                        System.Net.Http.HttpResponseMessage responseGet = await client.GetAsync(geturi);
                        string response = await responseGet.Content.ReadAsStringAsync();
                        return true;

                */

        }//Not in use Mk

      
        public async Task<string[]> GetDisplayHangTime(string hid)
        {

            var client = new HttpClient();
            var model = new HangTimeBindingModel
            {
                HangtimeId = hid
            };


            try
            {
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Hangtime/DisplaySelectedHangtime", content);
                var jwt = await response.Content.ReadAsStringAsync();
                JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);

                string[] info = new string[10];

                info[0] = jwtDynamic.Value<string>("idHangTime");
                info[1] = jwtDynamic.Value<string>("title");
                info[2] = jwtDynamic.Value<string>("description");
                info[3] = jwtDynamic.Value<string>("imageFile");
                info[4] = jwtDynamic.Value<string>("location");
                info[5] = jwtDynamic.Value<string>("eventDate");
                info[6] = jwtDynamic.Value<string>("timeFrom");
                info[7] = jwtDynamic.Value<string>("timeTo");
                info[8] = jwtDynamic.Value<string>("isPrivate");
                info[9] = jwtDynamic.Value<string>("createdBy");

                return info;

            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;

        }

        public async Task<string[]> GetDisplaySquad(string sid)
        {

            var client = new HttpClient();
            var model = new SquadBindingModel
            {
                SquadId = sid
            };

            try
            {
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/DisplaySelectedSquad", content);
                var jwt = await response.Content.ReadAsStringAsync();
                JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);

                string[] info = new string[8];

                info[0] = jwtDynamic.Value<string>("idSquad");
                info[1] = jwtDynamic.Value<string>("name");
                info[2] = jwtDynamic.Value<string>("location");
                info[3] = jwtDynamic.Value<string>("adminUser");
                info[4] = jwtDynamic.Value<string>("imageFile");
                info[5] = jwtDynamic.Value<string>("description");
                info[6] = jwtDynamic.Value<string>("numMembers");
                info[7] = jwtDynamic.Value<string>("numEvents");

                return info;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;

        }

        /*
        public async Task<string[]> GetDisplayHangTime(string hid)
        {

            var KeyValues = new List<KeyValuePair<string, string>>
            {
                //new KeyValuePair<string, string>("hid",hid)    //in php
                new KeyValuePair<string, string>("HangtimeId",hid)
            };


            try
            {
                //var request = new HttpRequestMessage(HttpMethod.Post, "http://www.edukot.com/user/json/DisplaySelectedHangTime.php");
                var request = new HttpRequestMessage(HttpMethod.Post, "http://letshang.azurewebsites.net/api/Hangtime/DisplaySelectedHangtime");
                request.Content = new FormUrlEncodedContent(KeyValues);
                var client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.SendAsync(request);
                //var content = await response.Content.ReadAsStringAsync();
                var jwt = await response.Content.ReadAsStringAsync();
                JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);

                string[] info = new string[9];

                info[0] = jwtDynamic.Value<string>("idHangTime");
                info[1] = jwtDynamic.Value<string>("Title");
                info[2] = jwtDynamic.Value<string>("Description");
                info[3] = jwtDynamic.Value<string>("ImageFile");
                info[4] = jwtDynamic.Value<string>("Location");
                info[5] = jwtDynamic.Value<string>("EventDate");
                info[6] = jwtDynamic.Value<string>("TimeFrom");
                info[7] = jwtDynamic.Value<string>("TimeTo");
                info[8] = jwtDynamic.Value<string>("isPrivate");

                return info;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;

        }

        public async Task<string[]> GetDisplaySquad(string sid)
        {

            var KeyValues = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>("sid",sid)
            };


            try
            {
                var request = new HttpRequestMessage(HttpMethod.Post, "http://www.edukot.com/user/json/DisplaySelectedSquad.php");
                request.Content = new FormUrlEncodedContent(KeyValues);
                var client = new HttpClient();
                var response = await client.SendAsync(request);
                //var content = await response.Content.ReadAsStringAsync();
                var jwt = await response.Content.ReadAsStringAsync();
                JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);

                string[] info = new string[8];

                info[0] = jwtDynamic.Value<string>("idSquad");
                info[1] = jwtDynamic.Value<string>("name");
                info[2] = jwtDynamic.Value<string>("location");
                info[3] = jwtDynamic.Value<string>("adminuser");
                info[4] = jwtDynamic.Value<string>("imagefile");
                info[5] = jwtDynamic.Value<string>("description");
                info[6] = jwtDynamic.Value<string>("numMembers");
                info[7] = jwtDynamic.Value<string>("numEvents");


                return info;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;

        }

        */

        //public async Task<bool> SendHangTimeInvitationSquads(string hangTimeId, string fromUserId, string toUserId, string SquadId, string status)
        public async Task<bool> SendHangTimeInvitationSquads(string hangTimeId, string fromUserId, string SquadId, string status)
        {
            var client = new HttpClient();


            var model = new InviteHangTimeUserModel
            {
                FromUserId = fromUserId,
                HangTimeId = hangTimeId,
                ToSquadId = SquadId,
                Status = status
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/SendHangTimeInvitationSquads.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Hangtime/SendHangtimeInvitationToSquads", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/UserRegister.php",new  StringContent(myJson, Encoding.UTF8, "application/json") );
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }


        public async Task<bool> SendHangTimeInvitationFriends(string hangTimeId, string fromUserId, string toUserId, string status)
        {
            var client = new HttpClient();


            var model = new InviteHangTimeUserModel
            {
                FromUserId = fromUserId,
                HangTimeId = hangTimeId,
                ToUserId = toUserId,
                Status = status
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/SendHangTimeInvitationFriends.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Hangtime/SendHangtimeInvitationToFriends", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/UserRegister.php",new  StringContent(myJson, Encoding.UTF8, "application/json") );
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }


        public async Task<bool> SendFriends(string fromUserId, string toUserId, string invitedBy, string status)
        {
            var client = new HttpClient();


            var model = new InviteHangTimeUserModel
            {
                FromUserId = fromUserId,
                ToUserId = toUserId,
                InvitedBy = invitedBy,
                Status = status
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Friends/SendFriendInvitation", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/SendFriendInvitation.php", content);
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }

        public async Task<bool> SendSquadInvitationFriends(string squadId, string toUserId, string status, string invitedBy, string isFollowing)
        {
            var client = new HttpClient();


            var model = new InviteSquadUserModel
            {
                SquadId = squadId,
                ToUserId = toUserId,
                Status = status,
                InvitedBy = invitedBy,
                IsFollowing = isFollowing


            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/SendSquadInvitationFriends.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/SendSquadInvitationToFriends", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/UserRegister.php",new  StringContent(myJson, Encoding.UTF8, "application/json") );
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }


        public async Task<List<NotificationBindingModel>> GetNotifications(string currentUserId)
        {
            var client = new HttpClient();
            var model = new NotificationBindingModel
            {
                CurrentUserId = currentUserId
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/getNotifications.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Notification/GetNotification", content);

                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<NotificationBindingModel>>(jwt);
                // JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                //// var HangId = jwtDynamic.Value<string>("HangTimeId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return null;

        }


        public async Task<bool> HandleFriendRequest(string currentListId, string invitationResponse)
        {
            var client = new HttpClient();


            var model = new NotificationBindingModel
            {
                CurrentListId = currentListId,
                InvitationResponse = invitationResponse
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/HandleFriendRequest.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Friends/HandleFriendRequest", content);
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }

        public async Task<bool> HandleSquadRequest(string currentListId, string invitationResponse)
        {
            var client = new HttpClient();


            var model = new NotificationBindingModel
            {
                CurrentListId = currentListId,
                InvitationResponse = invitationResponse
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/HandleSquadRequest", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/HandleSquadRequest.php", content);
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }

        public async Task<bool> HandleHangtimeRequest(string currentListId, string invitationResponse)
        {
            var client = new HttpClient();


            var model = new NotificationBindingModel
            {
                CurrentListId = currentListId,
                InvitationResponse = invitationResponse
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/HandleHangtimeRequest.php", content);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Hangtime/HandleHangtimeRequest", content);
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }


        public async Task<bool> HandleSquadHangtimeRequest(string currentListId, string invitationResponse)
        {
            var client = new HttpClient();


            var model = new NotificationBindingModel
            {
                CurrentListId = currentListId,
                InvitationResponse = invitationResponse
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Hangtime/HandleSquadHangtimeRequest", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/HandleSquadHangtimeRequest.php", content);
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }

        public async Task<bool> EditProfile(string username, string firstname, string lastname, string email, string phonenumber, string currentUserId, string company, string about)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                UserName = username,
                FirstName = firstname,
                LastName = lastname,
                Email = email,
                PhoneNumber = phonenumber,
                id = currentUserId,
                Company = company,
                About = about
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Account/EditProfile", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/UserRegister.php",new  StringContent(myJson, Encoding.UTF8, "application/json") );
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;
            /*
                        Uri geturi = new Uri("http://www.edukot.com/user/json/UserRegister.php?data=" + myJson); //replace your url  

                        System.Net.Http.HttpResponseMessage responseGet = await client.GetAsync(geturi);
                        string response = await responseGet.Content.ReadAsStringAsync();
                        return true;

                */

        }
        /*
        public async Task<string[]> GetCurrentUserData(string currentUserId)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                CurrentUserId = currentUserId
            };

            try
            {

                //var httpClient = new HttpClient();
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(json);
                //return taskModels;
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var response = await client.PostAsync("http://www.edukot.com/user/json/GetCurrentUserData.php", content);

                var jwt = await response.Content.ReadAsStringAsync();
                JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);

                var userName = jwtDynamic.Value<string>("UserName");
                var firstName = jwtDynamic.Value<string>("FirstName");
                var lastName = jwtDynamic.Value<string>("LastName");
                var email = jwtDynamic.Value<string>("Email");
                var phoneNumber = jwtDynamic.Value<string>("PhoneNumber");


                Debug.WriteLine(jwt);

                string[] info = new string[5];
                info[0] = userName;
                info[1] = firstName;
                info[2] = lastName;
                info[3] = email;
                info[4] = phoneNumber;

                //  return accessToken;
                return info;



            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        */
      
        public async Task<bool> ChangePassword(string email, string password, string confirmPassword)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                Email = email,
                Password = password,
                ConfirmPassword = confirmPassword
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Account/ResetPassword", content);
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return false;

        }

        public async Task<bool> SendComment(string data, string type, string typeid, string displayname, string displayimage, string userid)
        {
            var client = new HttpClient();
            var model = new CommentBindingModel
            {
                Data = data,
                Type = type,
                TypeId = typeid,
                DisplayName = displayname,
                DisplayImage = displayimage,
                UserId = userid

            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Notification/SendComment", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/SendComment.php", content);
                return response.IsSuccessStatusCode;
                /*
                var jwt = await response.Content.ReadAsStringAsync();
                JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                var HangId = jwtDynamic.Value<string>("HangTimeId");
                var SuccessStatus = jwtDynamic.Value<string>("stats");
                return HangId.ToString();
                */
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;
            /*
                        Uri geturi = new Uri("http://www.edukot.com/user/json/UserRegister.php?data=" + myJson); //replace your url  

                        System.Net.Http.HttpResponseMessage responseGet = await client.GetAsync(geturi);
                        string response = await responseGet.Content.ReadAsStringAsync();
                        return true;

                */

        }

        public async Task<List<CommentBindingModel>> GetComments(string currentHangtimeId)
        {
            var client = new HttpClient();
            var model = new CommentBindingModel
            {
                CurrentHangTimeId = currentHangtimeId
            };

            try
            {

                //var httpClient = new HttpClient();
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(json);
                //return taskModels;
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Hangtime/GetHangtimeComment", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/GetHangtimeComment.php", content);

                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<CommentBindingModel>>(jwt);
                // JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                //// var HangId = jwtDynamic.Value<string>("HangTimeId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<List<CommentBindingModel>> GetSquadComment(string currentHangtimeId)
        {
            var client = new HttpClient();
            var model = new CommentBindingModel
            {
                CurrentHangTimeId = currentHangtimeId
            };

            try
            {

                //var httpClient = new HttpClient();
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(json);
                //return taskModels;
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/GetSquadComment", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/GetSquadComment.php", content);

                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<CommentBindingModel>>(jwt);
                // JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                //// var HangId = jwtDynamic.Value<string>("HangTimeId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<List<UserBindingModel>> GetHangtimeUserList(string hangtimeId)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                CurrentUserId = hangtimeId
                 
            };

            try
            {

                //var httpClient = new HttpClient();
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(json);
                //return taskModels;
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Hangtime/GetHangtimeUserList", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/GetHangtimeUserList.php", content);

                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(jwt);
                // JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                //// var HangId = jwtDynamic.Value<string>("HangTimeId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<List<UserBindingModel>> GetSquadMembersList(string hangtimeId)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                CurrentUserId = hangtimeId

            };

            try
            {

                //var httpClient = new HttpClient();
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(json);
                //return taskModels;
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/GetSquadMembersList", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/GetSquadMembersList.php", content);

                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(jwt);
                // JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                //// var HangId = jwtDynamic.Value<string>("HangTimeId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<List<HangTimeBindingModel>> GetSquadHangtimesList(string hangtimeId)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                CurrentUserId = hangtimeId

            };

            try
            {

                //var httpClient = new HttpClient();
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(json);
                //return taskModels;
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/GetSquadHangtimesList", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/GetSquadHangtimesList.php", content);

                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<HangTimeBindingModel>>(jwt);
                // JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                //// var HangId = jwtDynamic.Value<string>("HangTimeId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<List<SquadBindingModel>> GetCreatedSquadList(string currentUserId)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                CurrentUserId = currentUserId

            };

            try
            {

                //var httpClient = new HttpClient();
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(json);
                //return taskModels;
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/GetCreatedSquadList", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/GetCreatedSquadList.php", content);

                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<SquadBindingModel>>(jwt);
                // JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                //// var HangId = jwtDynamic.Value<string>("HangTimeId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<bool> DeleteSquad(string squadId)
        {
            var client = new HttpClient();


            var model = new SquadBindingModel
            {
                idSquad = Convert.ToInt32(squadId)
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/DeleteSquad", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/DeleteSquad.php", content);
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }

        public async Task<List<SquadBindingModel>> GetJoinedSquadList(string currentUserId)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                CurrentUserId = currentUserId

            };

            try
            {

                //var httpClient = new HttpClient();
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(json);
                //return taskModels;
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/GetJoinedSquadList", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/GetJoinedSquadList.php", content);

                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<SquadBindingModel>>(jwt);
                // JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                //// var HangId = jwtDynamic.Value<string>("HangTimeId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<bool> LeaveSquad(string squadId, string currentUserId)
        {
            var client = new HttpClient();


            var model = new SquadBindingModel
            {
                idSquad = Convert.ToInt32(squadId),
                AdminUser = currentUserId
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/LeaveSquad", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/LeaveSquad.php", content);
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }

        public async Task<List<HangTimeBindingModel>> GetCreatedHangtimeList(string currentUserId)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                CurrentUserId = currentUserId

            };

            try
            {

                //var httpClient = new HttpClient();
                //var json = await httpClient.GetStringAsync("http://www.edukot.com/user/json/getfriendslist.php");
                //var taskModels = JsonConvert.DeserializeObject<List<UserBindingModel>>(json);
                //return taskModels;
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Hangtime/GetCreatedHangtimeList", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/GetCreatedHangtimeList.php", content);

                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<HangTimeBindingModel>>(jwt);
                // JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                //// var HangId = jwtDynamic.Value<string>("HangTimeId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<bool> DeleteHangtime(string hangtimeId)
        {
            var client = new HttpClient();


            var model = new HangTimeBindingModel
            {
                idHangTime = Convert.ToInt32(hangtimeId)
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Hangtime/DeleteHangtime", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/DeleteHangtime.php", content);
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }

        public async Task<string> EditSquads(string name, string location, string description, string adminUser, string idsquad)
        {
            var client = new HttpClient();
            var model = new SquadBindingModel
            {
                Name = name,
                Location = location,
                Description = description,
                AdminUser = adminUser,
                idSquad = Convert.ToInt32(idsquad)
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                //string myJson = json.ToString();
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/EditSquads", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/EditSquad.php", content);
                //var response = await client.PostAsync("http://www.edukot.com/user/json/UserRegister.php",new  StringContent(myJson, Encoding.UTF8, "application/json") );

                //var jwt = await response.Content.ReadAsStringAsync();
                //JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);
                //var SquadId = jwtDynamic.Value<string>("SquadId");
                //var SuccessStatus = jwtDynamic.Value<string>("stats");
                var SquadId = await response.Content.ReadAsStringAsync();

                return SquadId.ToString();



            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return "no data";
            /*
                        Uri geturi = new Uri("http://www.edukot.com/user/json/UserRegister.php?data=" + myJson); //replace your url  

                        System.Net.Http.HttpResponseMessage responseGet = await client.GetAsync(geturi);
                        string response = await responseGet.Content.ReadAsStringAsync();
                        return true;

                */

        }



        public async Task<string[]> DisplaySelectedUserList(string hid)
        {

            var client = new HttpClient();
            var model = new UserBindingModel
            {
                id = hid
            };


            try
            {
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);

                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/account/DisplaySelectedUserList", content);
                var jwt = await response.Content.ReadAsStringAsync();
                JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);

                var accessToken = jwtDynamic.Value<string>("accessToken");
                var id = jwtDynamic.Value<string>("id");
                var userNam = jwtDynamic.Value<string>("userName");
                var pass = jwtDynamic.Value<string>("passwordHash");

                var emails = jwtDynamic.Value<string>("email");
                var fName = jwtDynamic.Value<string>("firstName");
                var lName = jwtDynamic.Value<string>("lastName");
                var pNumber = jwtDynamic.Value<string>("phoneNumber");
                var Ifile = jwtDynamic.Value<string>("imageFile");
                var company = jwtDynamic.Value<string>("company");
                var about = jwtDynamic.Value<string>("about");

                string[] info = new string[11];

                info[0] = id;
                info[1] = emails;
                info[2] = pass;
                info[3] = userNam;
                info[4] = fName;
                info[5] = lName;
                info[6] = pNumber;
                info[7] = accessToken;
                info[8] = Ifile;
                info[9] = company;
                info[10] = about;

                return info;
                /*
                var request = new HttpRequestMessage(HttpMethod.Post, "http://www.edukot.com/user/json/DisplaySelectedUserList.php");
                request.Content = new FormUrlEncodedContent(KeyValues);
                var client = new HttpClient();
                var response = await client.SendAsync(request);
                //var content = await response.Content.ReadAsStringAsync();
                var jwt = await response.Content.ReadAsStringAsync();
                JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);

                string[] info = new string[11];

                info[0] = jwtDynamic.Value<string>("id");
                info[1] = jwtDynamic.Value<string>("Email");
                info[2] = jwtDynamic.Value<string>("Password");
                info[3] = jwtDynamic.Value<string>("UserName");
                info[4] = jwtDynamic.Value<string>("FirstName");
                info[5] = jwtDynamic.Value<string>("LastName");
                info[6] = jwtDynamic.Value<string>("PhoneNumber");
                info[7] = jwtDynamic.Value<string>("AccessToken");
                info[8] = jwtDynamic.Value<string>("ImageFile");
                info[9] = jwtDynamic.Value<string>("Company");
                info[10] = jwtDynamic.Value<string>("About");

                return info;
                */
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }

        public async Task<List<SelectableData<UserBindingModel>>> GetSquadMembersListToRemove(string currentSquadId)
        {
            var client = new HttpClient();
            var model = new UserBindingModel
            {
                CurrentUserId = currentSquadId
            };

            try
            {
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/GetSquadMembersListToRemove", content);
                var jwt = await response.Content.ReadAsStringAsync();
                var taskModels = JsonConvert.DeserializeObject<List<SelectableData<UserBindingModel>>>(jwt);


                return taskModels;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }


        public async Task<bool> RemoveSquadMember(string squadId, string toUserId)
        {
            var client = new HttpClient();


            var model = new InviteSquadUserModel
            {
                SquadId = squadId,
                ToUserId = toUserId
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Squad/RemoveSquadMember", content);
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }

        public async Task<bool> RemoveFriend(string friendId)
        {
            var client = new HttpClient();


            var model = new InviteHangTimeUserModel
            {
                FromUserId = Settings.CurrentUserId,
                ToUserId = friendId
            };
            try
            {
                var json = JsonConvert.SerializeObject(model);
                HttpContent content = new StringContent(json);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Settings.AccessToken);
                var response = await client.PostAsync("http://letshang.azurewebsites.net/api/Friends/RemoveFriend", content);
                return response.IsSuccessStatusCode;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }
            return true;

        }



        /*
        public async Task<string[]> DisplaySelectedUserList(string hid)
        {

            var KeyValues = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>("hid",hid)
            };


            try
            {
                var request = new HttpRequestMessage(HttpMethod.Post, "http://www.edukot.com/user/json/DisplaySelectedUserList.php");
                request.Content = new FormUrlEncodedContent(KeyValues);
                var client = new HttpClient();
                var response = await client.SendAsync(request);
                //var content = await response.Content.ReadAsStringAsync();
                var jwt = await response.Content.ReadAsStringAsync();
                JObject jwtDynamic = JsonConvert.DeserializeObject<dynamic>(jwt);

                string[] info = new string[11];

                info[0] = jwtDynamic.Value<string>("id");
                info[1] = jwtDynamic.Value<string>("Email");
                info[2] = jwtDynamic.Value<string>("Password");
                info[3] = jwtDynamic.Value<string>("UserName");
                info[4] = jwtDynamic.Value<string>("FirstName");
                info[5] = jwtDynamic.Value<string>("LastName");
                info[6] = jwtDynamic.Value<string>("PhoneNumber");
                info[7] = jwtDynamic.Value<string>("AccessToken");
                info[8] = jwtDynamic.Value<string>("ImageFile");
                info[9] = jwtDynamic.Value<string>("Company");
                info[10] = jwtDynamic.Value<string>("About");

                return info;
            }
            catch (Exception e)
            {
                string a = e.ToString();
            }

            return null;
        }
        */

    }
}
  • 0
  • 0
  • 0