-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPageViewModel.cs
More file actions
119 lines (111 loc) · 3.03 KB
/
MainPageViewModel.cs
File metadata and controls
119 lines (111 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Net.Http;
using System.Runtime.CompilerServices;
using System.Text;
using Xamarin.Forms;
namespace CRUDWebAPI
{
public class MainPageViewModel : INotifyPropertyChanged
{
public INavigation Navigation { get; set; }
public MainPageViewModel(INavigation _navigation)
{
Navigation = _navigation;
}
public async void GetEmployees()
{
using (var client = new HttpClient())
{
// send a GET request
var uri = "http://192.168.0.5/api/Masters/GetEmployees";
var result = await client.GetStringAsync(uri);
//handling the answer
var EmployeeList = JsonConvert.DeserializeObject<List<Employee>>(result);
Employees = new ObservableCollection<Employee>(EmployeeList);
IsRefreshing = false;
}
}
public Command AddEmployee
{
get
{
return new Command(() =>
{
Navigation.PushAsync(new AddEmployee(null));
});
}
}
public Command EditEmployee
{
get
{
return new Command(() =>
{
Navigation.PushAsync(new AddEmployee(null));
});
}
}
public Command RefreshData
{
get
{
return new Command(() =>
{
GetEmployees();
});
}
}
bool _isRefreshing;
public bool IsRefreshing
{
get
{
return _isRefreshing;
}
set
{
_isRefreshing = value;
OnPropertyChanged();
}
}
Employee _selectedEmployee;
public Employee SelectedEmployee
{
get
{
return _selectedEmployee;
}
set
{
_selectedEmployee = value;
if(value!=null)
{
Navigation.PushAsync(new AddEmployee(SelectedEmployee));
}
OnPropertyChanged();
}
}
ObservableCollection<Employee> _employees;
public ObservableCollection<Employee> Employees
{
get
{
return _employees;
}
set
{
_employees = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}