-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPmViewManager.cs
71 lines (58 loc) · 1.95 KB
/
PmViewManager.cs
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
using PasswodManager.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace PasswodManager
{
public class PmViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private ObservableCollection<PasswordItem> _passwords;
private ApiService api;
public PmViewModel()
{
_passwords = new ObservableCollection<PasswordItem>();
api = new ApiService();
load();
}
public async Task load()
{
var res = await api.get();
_passwords = new ObservableCollection<PasswordItem>();
res.ForEach(_passwords.Add);
OnPropertyChanged("passwords");
OnPropertyChanged();
}
public ObservableCollection<PasswordItem> passwords
{
get => _passwords;
}
public async
Task
addNewPassword(string app,string password)
{
var uid = await SecureStorage.GetAsync("uid");
PasswordPostModel ppm = new PasswordPostModel();
ppm.app = app;
ppm.userId = uid;
ppm.password = password;
await api.SaveTodoItemAsync(ppm);
await load();
OnPropertyChanged("passwords");
OnPropertyChanged();
}
//public async Task deletePassword(String todoId)
//{
// await api.delete(todoId);
// await initData();
// OnPropertyChanged("passwords");
// OnPropertyChanged();
//}
public void OnPropertyChanged([CallerMemberName] string name = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}