-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatabaseClass.vb
73 lines (63 loc) · 3.09 KB
/
DatabaseClass.vb
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
Imports MongoDB.Bson
Imports MongoDB.Driver
Public Class DatabaseClass
Private ReadOnly DbClient As MongoClient
Private ReadOnly Db As IMongoDatabase
Private ReadOnly userCollection As IMongoCollection(Of BsonDocument)
Private hospitalCollection As IMongoCollection(Of BsonDocument)
Private doctorCollection As IMongoCollection(Of BsonDocument)
Public Sub New()
DbClient = New MongoClient("mongodb+srv://anand:[email protected]/?retryWrites=true&w=majority")
Db = DbClient.GetDatabase("AyushmaanBhavahDB")
userCollection = Db.GetCollection(Of BsonDocument)("Users")
hospitalCollection = Db.GetCollection(Of BsonDocument)("Hospitals")
doctorCollection = Db.GetCollection(Of BsonDocument)("Doctors")
End Sub
Public Async Sub InsertUser(fullname As String, email As String, password As String, phone As String)
Dim userDocument = New BsonDocument From {
{"fullname", fullname},
{"phone", phone},
{"email", email},
{"password", password},
{"remember", False},
{"systemId", ""},
{"joindate", DateTime.Today.ToString("dd-MM-yyyy")}
}
Await userCollection.InsertOneAsync(userDocument)
End Sub
Public Async Sub UpdateUser(key As String, value As Object, phone As String)
Dim filter = Builders(Of BsonDocument).Filter.Eq(Of String)("phone", phone)
Dim update = Builders(Of BsonDocument).Update.Set(Of String)(key, value)
Await userCollection.UpdateOneAsync(filter, update)
End Sub
Public Async Sub RememberUser(remember As Boolean, phone As String)
Try
Dim filter = Builders(Of BsonDocument).Filter.Eq(Of String)("phone", phone)
Dim update = Builders(Of BsonDocument).Update.Set(Of Boolean)("remember", remember)
Await userCollection.UpdateOneAsync(filter, update)
Catch ex As Exception
MsgBox("Error in Database: " + ex.ToString, MsgBoxStyle.Information, "Error")
End Try
End Sub
Public Async Sub DeleteUser(phone As String)
Dim filter = Builders(Of BsonDocument).Filter.Eq(Of String)("phone", phone)
Await userCollection.DeleteOneAsync(filter)
End Sub
Public Async Function GetUser(key As String, value As String) As Task(Of BsonDocument)
Return Await userCollection.Find(New BsonDocument(key, value)).FirstOrDefaultAsync()
End Function
Public Async Sub InsertDoctor(fullname As String, basicInfo As String, Clinics As List(Of String))
Dim doctorDocument = New BsonDocument From {
{"fullname", fullname},
{"basicInfo", basicInfo},
{"clinics", ""}
}
Await doctorCollection.InsertOneAsync(doctorDocument)
End Sub
Public Async Function GetDoctors_ByName(name As String) As Task(Of BsonDocument)
Return Await doctorCollection.FindAsync(New BsonDocument("fullname", name))
End Function
Public Async Function GetDoctors_ByClinic(clinic As String) As Task(Of BsonDocument)
Return ""
End Function
End Class