-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuctionDb.cs
254 lines (226 loc) · 7.93 KB
/
AuctionDb.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Auction
{
public class AuctionDb : DbContext
{
public DbSet<Users> Users { get; set; }
}
public class AuctionTable
{
public bool blank(string str)
{
return str == null || str.Trim().Equals("");
}
}
public class Users : AuctionTable
{
/**
* User Item POCO
* TableName: users
*/
public Users() { }
public Users(DataRow row)
{
userId = row.Field<int>("userId");
userName = row.Field<string>("userName");
pwd = row.Field<string>("pwd");
fullname = row.Field<string>("fullname");
//deleteFlag = row.Field<bool>("deleteFlag");
userType = row.Field<int>("userType");
}
public int userId { get; set; }
public string userName { get; set; }
public string pwd { get; set; }
public string fullname { get; set; }
public int userType { get; set; }
public bool deleteFlag { get; set; }
public string toString()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this).ToString();
}
}
public class UserType : AuctionTable
{
public static int Admin = 1;
public static int Publisher = 2;
public static int Viewer = 3;
}
/**
* Auction Item POCO
* TableName: auction_item
*/
public class AuctionItem : AuctionTable
{
public AuctionItem()
{
auctioned = "";
quantity = 1;
sold = false;
}
public AuctionItem(AuctionItem ai) {
setAuctionItem(ai);
}
public AuctionItem(DataRow row)
{
itemId = row.Field<int>("itemId");
itemName = row.Field<string>("itemName");
itemType = row.Field<string>("itemType");
additionalInfo = row.Field<string>("additionalInfo");
owner = row.Field<string>("owner");
quantity = row.Field<int>("quantity");
initialPrice = row.Field<int>("initialPrice");
sold = row.Field<bool>("sold");
//deleteFlag = row.Field<bool>("deleteFlag");
auctioned = sold ? "Yes" : "";
}
public int itemId { get; set; }
public string itemName { get; set; }
public string itemType { get; set; }
public string additionalInfo { get; set; }
public string owner { get; set; }
public int quantity { get; set; }
public int initialPrice { get; set; }
public bool sold { get; set; }
public bool deleteFlag { get; set; }
public string auctioned { get; set; }
public AuctionItem setAuctionItem(AuctionItem ai)
{
itemId = ai.itemId;
itemName = ai.itemName;
itemType = ai.itemType;
additionalInfo = ai.additionalInfo;
owner = ai.owner;
quantity = ai.quantity;
initialPrice = ai.initialPrice;
sold = ai.sold;
//deleteFlag = ai.deleteFlag;
auctioned = ai.sold ? "Yes" : "";
return this;
}
public bool mandatoryCheck()
{
if (blank(itemName) || blank(itemType) || blank(additionalInfo) || blank(owner))
return false;
if (quantity < 1 || initialPrice < 0)
return false;
return true;
}
public string toString()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this).ToString();
}
}
/**
* Auction Item POCO
* TableName: auction_item
*/
public class AuctionLocation : AuctionTable
{
public AuctionLocation() {
capacity = 1;
contact = "";
addressComplete = "";
}
public AuctionLocation(AuctionLocation al) {
setAuctionLocation(al);
}
public AuctionLocation(DataRow row) {
locationId = row.Field<int>("locationId");
locationName = row.Field<string>("locationName");
address = row.Field<string>("address");
availability = row.Field<string>("availability");
place = row.Field<string>("place");
zipcode = row.Field<string>("zipcode");
capacity = row.Field<int>("capacity");
contactPerson = row.Field<string>("contactPerson");
phone = row.Field<string>("phone");
email = row.Field<string>("email");
//deleteFlag = row.Field<bool>("deleteFlag");
contact = (blank(phone)? "" : phone + ", ") + (blank(email) ? "" : email);
addressComplete = address + "\n" + zipcode;
}
public int locationId { get; set; }
public string locationName { get; set; }
public string address { get; set; }
public string availability { get; set; }
public string place { get; set; }
public string zipcode { get; set; }
public int capacity { get; set; }
public string contactPerson { get; set; }
public string phone { get; set; }
public string email { get; set; }
public bool deleteFlag { get; set; }
public string contact { get; set; }
public string addressComplete { get; set; }
public AuctionLocation setAuctionLocation(AuctionLocation al)
{
locationId = al.locationId;
locationName = al.locationName;
address = al.address;
availability = al.availability;
place = al.place;
zipcode = al.zipcode;
capacity = al.capacity;
contactPerson = al.contactPerson;
phone = al.phone;
email = al.email;
//deleteFlag = al.deleteFlag;
contact = (blank(phone) ? "" : phone + ", ") + (blank(email) ? "" : email);
addressComplete = address + "\n" + zipcode;
return this;
}
public bool mandatoryCheck()
{
if (blank(locationName) || blank(address) || blank(place) || blank(zipcode) || blank(availability))
return false;
if (capacity < 1)
return false;
return true;
}
public string toString()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this).ToString();
}
}
public class AuctionEvent : AuctionTable
{
public AuctionEvent() { conducted = false; }
public AuctionEvent(DataRow row) {
eventId = row.Field<int>("eventId");
eventName = row.Field<string>("eventName");
eventTime = row.Field<string>("eventTime");
registrationFee = row.Field<int>("registrationFee");
buyer = row.Field<string>("buyer");
conducted = row.Field<bool>("conducted");
auctionItem = new AuctionItem(row);
auctionLocation = new AuctionLocation(row);
}
public int eventId { get; set; }
public string eventName { get; set; }
public string eventTime { get; set; }
public int registrationFee { get; set; }
public string buyer { get; set; }
public bool conducted { get; set; }
public AuctionItem auctionItem { get; set; }
public AuctionLocation auctionLocation { get; set; }
public AuctionEvent setAuctionEvent(AuctionEvent ae)
{
eventId = ae.eventId;
eventName = ae.eventName;
eventTime = ae.eventTime;
registrationFee = ae.registrationFee;
buyer = ae.buyer;
conducted = ae.conducted;
auctionItem = new AuctionItem(ae.auctionItem);
auctionLocation = new AuctionLocation(ae.auctionLocation);
return this;
}
}
}