Exemplo n.º 1
0
        public static async Task GetUserRoles(ObservableCollection<UserRole> UserRoleList)
        {
            var response = await http.GetAsync("http://uwproject.feifei.ca/api/ApplicationRoles");
            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                JsonValue value = JsonValue.Parse(result);
                JsonArray root = value.GetArray();
                for (uint i = 0; i < root.Count; i++)
                {
                    string id = root.GetObjectAt(i).GetNamedString("Id");
                    string name = root.GetObjectAt(i).GetNamedString("Name");
                    var userRole = new UserRole
                    {
                        Id = id,
                        Name = name
                    };
                    UserRoleList.Add(userRole);
                }
            }
            else
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Cannot retrieve any record");
                await dialog.ShowAsync();
            }
        }
 private async void EditUserRole_Click(object sender, RoutedEventArgs e)
 {
     if (UserRoleIdWillBeEdited.Text != "" && UserRoleNameWillBeEdited.Text != "")
     {
         string id = UserRoleIdWillBeEdited.Text;
         string name = UserRoleNameWillBeEdited.Text;
         var userRole = new UserRole() { Id = id.ToString(), Name = name};
         await UserRoleManager.EditUserRole(new StringContent(JsonConvert.SerializeObject(userRole), Encoding.UTF8, "application/json"), userRole, UserRoles);
     }
 }
Exemplo n.º 3
0
        public static async Task EditUserRole(StringContent optionJsonToBeEdited, UserRole updatedUserRole, ObservableCollection<UserRole> UserRoleList)
        {
            string requestUri = "http://uwproject.feifei.ca/api/ApplicationRoles/" + updatedUserRole.Id;
            var response = await http.PutAsync(requestUri, optionJsonToBeEdited);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();
                UserRole currentUserRole = UserRoleList.FirstOrDefault(o => o.Id == updatedUserRole.Id);
                currentUserRole = updatedUserRole;
            }
            else
            {
                var dialog = new Windows.UI.Popups.MessageDialog("Cannot edit record");
                await dialog.ShowAsync();
            }
        }
Exemplo n.º 4
0
        public static async Task GetUserRoles(ObservableCollection<UserRole> UserRoleList)
        {
            var http = new HttpClient();
            var response = await http.GetAsync("http://uwproject.feifei.ca/api/ApplicationRoles");
            var result = await response.Content.ReadAsStringAsync();

            JsonValue value = JsonValue.Parse(result);
            JsonArray root = value.GetArray();
            for (uint i = 0; i < root.Count; i++)
            {
                string id = root.GetObjectAt(i).GetNamedString("Id");
                string name = root.GetObjectAt(i).GetNamedString("Name");
                var userRole = new UserRole
                {
                    Id = id,
                    Name = name
                };
                UserRoleList.Add(userRole);
            }
        }