Sfoglia il codice sorgente

Check in of API

master
Kobus 5 anni fa
commit
33a914aed2
100 ha cambiato i file con 8280 aggiunte e 0 eliminazioni
  1. 63
    0
      .gitattributes
  2. 340
    0
      .gitignore
  3. 25
    0
      UnivateProperties_API.sln
  4. 12
    0
      UnivateProperties_API/Containers/Property/Group.cs
  5. 11
    0
      UnivateProperties_API/Containers/Property/GroupFields.cs
  6. 11
    0
      UnivateProperties_API/Containers/Property/PropertyDetail.cs
  7. 12
    0
      UnivateProperties_API/Containers/Property/PropertyDetailGroup.cs
  8. 43
    0
      UnivateProperties_API/Containers/Property/PropertyDisplay.cs
  9. 14
    0
      UnivateProperties_API/Containers/Timeshare/UnitConfigurationDto.cs
  10. 11
    0
      UnivateProperties_API/Containers/Users/AgencyDto.cs
  11. 17
    0
      UnivateProperties_API/Containers/Users/Role.cs
  12. 15
    0
      UnivateProperties_API/Containers/Users/UserDto.cs
  13. 37
    0
      UnivateProperties_API/Containers/ValidateEntity.cs
  14. 79
    0
      UnivateProperties_API/Context/DataContext.cs
  15. 66
    0
      UnivateProperties_API/Controllers/Communication/AccountController.cs
  16. 66
    0
      UnivateProperties_API/Controllers/Communication/EmailController.cs
  17. 66
    0
      UnivateProperties_API/Controllers/Communication/HostController.cs
  18. 79
    0
      UnivateProperties_API/Controllers/Properties/PropertyController.cs
  19. 38
    0
      UnivateProperties_API/Controllers/Properties/PropertyFieldsController.cs
  20. 71
    0
      UnivateProperties_API/Controllers/Properties/PropertyImageController.cs
  21. 83
    0
      UnivateProperties_API/Controllers/Properties/PropertyTypeController.cs
  22. 65
    0
      UnivateProperties_API/Controllers/Properties/PropertyUserFieldController.cs
  23. 71
    0
      UnivateProperties_API/Controllers/Properties/UserDefinedFieldController.cs
  24. 65
    0
      UnivateProperties_API/Controllers/Properties/UserDefinedGroupController.cs
  25. 71
    0
      UnivateProperties_API/Controllers/Region/CityController.cs
  26. 64
    0
      UnivateProperties_API/Controllers/Region/ProvinceController.cs
  27. 70
    0
      UnivateProperties_API/Controllers/Region/SuburbController.cs
  28. 66
    0
      UnivateProperties_API/Controllers/Timeshare/SeasonController.cs
  29. 66
    0
      UnivateProperties_API/Controllers/Timeshare/StatusController.cs
  30. 66
    0
      UnivateProperties_API/Controllers/Timeshare/TimeshareWeekController.cs
  31. 67
    0
      UnivateProperties_API/Controllers/Timeshare/UnitConfigurationController.cs
  32. 65
    0
      UnivateProperties_API/Controllers/Users/AgencyController.cs
  33. 65
    0
      UnivateProperties_API/Controllers/Users/AgentController.cs
  34. 65
    0
      UnivateProperties_API/Controllers/Users/IndividualController.cs
  35. 208
    0
      UnivateProperties_API/Controllers/Users/RegisterController.cs
  36. 67
    0
      UnivateProperties_API/Controllers/Users/UserController.cs
  37. 21
    0
      UnivateProperties_API/Enums.cs
  38. 24
    0
      UnivateProperties_API/Helpers/AppException.cs
  39. 17
    0
      UnivateProperties_API/Helpers/AutoMapperProfile.cs
  40. 18
    0
      UnivateProperties_API/Helpers/MyCommon.cs
  41. 767
    0
      UnivateProperties_API/Migrations/20190828083244_1124.Designer.cs
  42. 740
    0
      UnivateProperties_API/Migrations/20190828083244_1124.cs
  43. 765
    0
      UnivateProperties_API/Migrations/DataContextModelSnapshot.cs
  44. 43
    0
      UnivateProperties_API/Model/BaseEntity.cs
  45. 142
    0
      UnivateProperties_API/Model/Communication/Email.cs
  46. 43
    0
      UnivateProperties_API/Model/Communication/SMTPAccount.cs
  47. 44
    0
      UnivateProperties_API/Model/Communication/SMTPHost.cs
  48. 40
    0
      UnivateProperties_API/Model/Property/Property.cs
  49. 15
    0
      UnivateProperties_API/Model/Property/PropertyImage.cs
  50. 10
    0
      UnivateProperties_API/Model/Property/PropertyType.cs
  51. 19
    0
      UnivateProperties_API/Model/Property/PropertyUserField.cs
  52. 17
    0
      UnivateProperties_API/Model/Property/UserDefinedField.cs
  53. 15
    0
      UnivateProperties_API/Model/Property/UserDefinedGroup.cs
  54. 16
    0
      UnivateProperties_API/Model/Region/City.cs
  55. 10
    0
      UnivateProperties_API/Model/Region/Province.cs
  56. 16
    0
      UnivateProperties_API/Model/Region/Suburb.cs
  57. 7
    0
      UnivateProperties_API/Model/Timeshare/Season.cs
  58. 8
    0
      UnivateProperties_API/Model/Timeshare/Status.cs
  59. 51
    0
      UnivateProperties_API/Model/Timeshare/TimeshareWeek.cs
  60. 17
    0
      UnivateProperties_API/Model/Timeshare/UnitConfiguration.cs
  61. 28
    0
      UnivateProperties_API/Model/Timeshare/UnitConfigurationType.cs
  62. 22
    0
      UnivateProperties_API/Model/Users/Agency.cs
  63. 21
    0
      UnivateProperties_API/Model/Users/Agent.cs
  64. 12
    0
      UnivateProperties_API/Model/Users/AppSettings.cs
  65. 20
    0
      UnivateProperties_API/Model/Users/Individual.cs
  66. 28
    0
      UnivateProperties_API/Model/Users/Person.cs
  67. 23
    0
      UnivateProperties_API/Model/Users/User.cs
  68. 24
    0
      UnivateProperties_API/Program.cs
  69. 30
    0
      UnivateProperties_API/Properties/launchSettings.json
  70. 108
    0
      UnivateProperties_API/Repository/Communication/EmailRepository.cs
  71. 98
    0
      UnivateProperties_API/Repository/Communication/SMTPAccountRepository.cs
  72. 89
    0
      UnivateProperties_API/Repository/Communication/SMTPHostRepository.cs
  73. 21
    0
      UnivateProperties_API/Repository/IRepository.cs
  74. 10
    0
      UnivateProperties_API/Repository/Properties/IPropertyImageRepository.cs
  75. 15
    0
      UnivateProperties_API/Repository/Properties/IPropertyRepository.cs
  76. 13
    0
      UnivateProperties_API/Repository/Properties/IUserDefinedGroupRepository.cs
  77. 98
    0
      UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs
  78. 340
    0
      UnivateProperties_API/Repository/Properties/PropertyRepository.cs
  79. 90
    0
      UnivateProperties_API/Repository/Properties/PropertyTypeRepository.cs
  80. 90
    0
      UnivateProperties_API/Repository/Properties/PropertyUserFieldRepository.cs
  81. 90
    0
      UnivateProperties_API/Repository/Properties/UserDefinedFieldRepository.cs
  82. 174
    0
      UnivateProperties_API/Repository/Properties/UserDefinedGroupRepository.cs
  83. 99
    0
      UnivateProperties_API/Repository/Region/CityRepository.cs
  84. 10
    0
      UnivateProperties_API/Repository/Region/ICityRepository.cs
  85. 10
    0
      UnivateProperties_API/Repository/Region/ISuburbRepository.cs
  86. 90
    0
      UnivateProperties_API/Repository/Region/ProvinceRepository.cs
  87. 100
    0
      UnivateProperties_API/Repository/Region/SuburbRepository.cs
  88. 90
    0
      UnivateProperties_API/Repository/Timeshare/SeasonRepository.cs
  89. 90
    0
      UnivateProperties_API/Repository/Timeshare/StatusRepository.cs
  90. 141
    0
      UnivateProperties_API/Repository/Timeshare/UnitConfigurationRepository.cs
  91. 129
    0
      UnivateProperties_API/Repository/Timeshare/WeekRepository.cs
  92. 97
    0
      UnivateProperties_API/Repository/Users/AgencyRepository.cs
  93. 96
    0
      UnivateProperties_API/Repository/Users/AgentRepository.cs
  94. 26
    0
      UnivateProperties_API/Repository/Users/IRegisterRepository.cs
  95. 96
    0
      UnivateProperties_API/Repository/Users/IndividualRepository.cs
  96. 325
    0
      UnivateProperties_API/Repository/Users/RegisterRepository.cs
  97. 100
    0
      UnivateProperties_API/Repository/Users/UserRepository.cs
  98. 147
    0
      UnivateProperties_API/Startup.cs
  99. 25
    0
      UnivateProperties_API/UnivateProperties_API.csproj
  100. 0
    0
      UnivateProperties_API/appsettings.Development.json

+ 63
- 0
.gitattributes Vedi File

@@ -0,0 +1,63 @@
1
+###############################################################################
2
+# Set default behavior to automatically normalize line endings.
3
+###############################################################################
4
+* text=auto
5
+
6
+###############################################################################
7
+# Set default behavior for command prompt diff.
8
+#
9
+# This is need for earlier builds of msysgit that does not have it on by
10
+# default for csharp files.
11
+# Note: This is only used by command line
12
+###############################################################################
13
+#*.cs     diff=csharp
14
+
15
+###############################################################################
16
+# Set the merge driver for project and solution files
17
+#
18
+# Merging from the command prompt will add diff markers to the files if there
19
+# are conflicts (Merging from VS is not affected by the settings below, in VS
20
+# the diff markers are never inserted). Diff markers may cause the following 
21
+# file extensions to fail to load in VS. An alternative would be to treat
22
+# these files as binary and thus will always conflict and require user
23
+# intervention with every merge. To do so, just uncomment the entries below
24
+###############################################################################
25
+#*.sln       merge=binary
26
+#*.csproj    merge=binary
27
+#*.vbproj    merge=binary
28
+#*.vcxproj   merge=binary
29
+#*.vcproj    merge=binary
30
+#*.dbproj    merge=binary
31
+#*.fsproj    merge=binary
32
+#*.lsproj    merge=binary
33
+#*.wixproj   merge=binary
34
+#*.modelproj merge=binary
35
+#*.sqlproj   merge=binary
36
+#*.wwaproj   merge=binary
37
+
38
+###############################################################################
39
+# behavior for image files
40
+#
41
+# image files are treated as binary by default.
42
+###############################################################################
43
+#*.jpg   binary
44
+#*.png   binary
45
+#*.gif   binary
46
+
47
+###############################################################################
48
+# diff behavior for common document formats
49
+# 
50
+# Convert binary document formats to text before diffing them. This feature
51
+# is only available from the command line. Turn it on by uncommenting the 
52
+# entries below.
53
+###############################################################################
54
+#*.doc   diff=astextplain
55
+#*.DOC   diff=astextplain
56
+#*.docx  diff=astextplain
57
+#*.DOCX  diff=astextplain
58
+#*.dot   diff=astextplain
59
+#*.DOT   diff=astextplain
60
+#*.pdf   diff=astextplain
61
+#*.PDF   diff=astextplain
62
+#*.rtf   diff=astextplain
63
+#*.RTF   diff=astextplain

+ 340
- 0
.gitignore Vedi File

@@ -0,0 +1,340 @@
1
+## Ignore Visual Studio temporary files, build results, and
2
+## files generated by popular Visual Studio add-ons.
3
+##
4
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5
+
6
+# User-specific files
7
+*.rsuser
8
+*.suo
9
+*.user
10
+*.userosscache
11
+*.sln.docstates
12
+
13
+# User-specific files (MonoDevelop/Xamarin Studio)
14
+*.userprefs
15
+
16
+# Build results
17
+[Dd]ebug/
18
+[Dd]ebugPublic/
19
+[Rr]elease/
20
+[Rr]eleases/
21
+x64/
22
+x86/
23
+[Aa][Rr][Mm]/
24
+[Aa][Rr][Mm]64/
25
+bld/
26
+[Bb]in/
27
+[Oo]bj/
28
+[Ll]og/
29
+
30
+# Visual Studio 2015/2017 cache/options directory
31
+.vs/
32
+# Uncomment if you have tasks that create the project's static files in wwwroot
33
+#wwwroot/
34
+
35
+# Visual Studio 2017 auto generated files
36
+Generated\ Files/
37
+
38
+# MSTest test Results
39
+[Tt]est[Rr]esult*/
40
+[Bb]uild[Ll]og.*
41
+
42
+# NUNIT
43
+*.VisualState.xml
44
+TestResult.xml
45
+
46
+# Build Results of an ATL Project
47
+[Dd]ebugPS/
48
+[Rr]eleasePS/
49
+dlldata.c
50
+
51
+# Benchmark Results
52
+BenchmarkDotNet.Artifacts/
53
+
54
+# .NET Core
55
+project.lock.json
56
+project.fragment.lock.json
57
+artifacts/
58
+
59
+# StyleCop
60
+StyleCopReport.xml
61
+
62
+# Files built by Visual Studio
63
+*_i.c
64
+*_p.c
65
+*_h.h
66
+*.ilk
67
+*.meta
68
+*.obj
69
+*.iobj
70
+*.pch
71
+*.pdb
72
+*.ipdb
73
+*.pgc
74
+*.pgd
75
+*.rsp
76
+*.sbr
77
+*.tlb
78
+*.tli
79
+*.tlh
80
+*.tmp
81
+*.tmp_proj
82
+*_wpftmp.csproj
83
+*.log
84
+*.vspscc
85
+*.vssscc
86
+.builds
87
+*.pidb
88
+*.svclog
89
+*.scc
90
+
91
+# Chutzpah Test files
92
+_Chutzpah*
93
+
94
+# Visual C++ cache files
95
+ipch/
96
+*.aps
97
+*.ncb
98
+*.opendb
99
+*.opensdf
100
+*.sdf
101
+*.cachefile
102
+*.VC.db
103
+*.VC.VC.opendb
104
+
105
+# Visual Studio profiler
106
+*.psess
107
+*.vsp
108
+*.vspx
109
+*.sap
110
+
111
+# Visual Studio Trace Files
112
+*.e2e
113
+
114
+# TFS 2012 Local Workspace
115
+$tf/
116
+
117
+# Guidance Automation Toolkit
118
+*.gpState
119
+
120
+# ReSharper is a .NET coding add-in
121
+_ReSharper*/
122
+*.[Rr]e[Ss]harper
123
+*.DotSettings.user
124
+
125
+# JustCode is a .NET coding add-in
126
+.JustCode
127
+
128
+# TeamCity is a build add-in
129
+_TeamCity*
130
+
131
+# DotCover is a Code Coverage Tool
132
+*.dotCover
133
+
134
+# AxoCover is a Code Coverage Tool
135
+.axoCover/*
136
+!.axoCover/settings.json
137
+
138
+# Visual Studio code coverage results
139
+*.coverage
140
+*.coveragexml
141
+
142
+# NCrunch
143
+_NCrunch_*
144
+.*crunch*.local.xml
145
+nCrunchTemp_*
146
+
147
+# MightyMoose
148
+*.mm.*
149
+AutoTest.Net/
150
+
151
+# Web workbench (sass)
152
+.sass-cache/
153
+
154
+# Installshield output folder
155
+[Ee]xpress/
156
+
157
+# DocProject is a documentation generator add-in
158
+DocProject/buildhelp/
159
+DocProject/Help/*.HxT
160
+DocProject/Help/*.HxC
161
+DocProject/Help/*.hhc
162
+DocProject/Help/*.hhk
163
+DocProject/Help/*.hhp
164
+DocProject/Help/Html2
165
+DocProject/Help/html
166
+
167
+# Click-Once directory
168
+publish/
169
+
170
+# Publish Web Output
171
+*.[Pp]ublish.xml
172
+*.azurePubxml
173
+# Note: Comment the next line if you want to checkin your web deploy settings,
174
+# but database connection strings (with potential passwords) will be unencrypted
175
+*.pubxml
176
+*.publishproj
177
+
178
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
179
+# checkin your Azure Web App publish settings, but sensitive information contained
180
+# in these scripts will be unencrypted
181
+PublishScripts/
182
+
183
+# NuGet Packages
184
+*.nupkg
185
+# The packages folder can be ignored because of Package Restore
186
+**/[Pp]ackages/*
187
+# except build/, which is used as an MSBuild target.
188
+!**/[Pp]ackages/build/
189
+# Uncomment if necessary however generally it will be regenerated when needed
190
+#!**/[Pp]ackages/repositories.config
191
+# NuGet v3's project.json files produces more ignorable files
192
+*.nuget.props
193
+*.nuget.targets
194
+
195
+# Microsoft Azure Build Output
196
+csx/
197
+*.build.csdef
198
+
199
+# Microsoft Azure Emulator
200
+ecf/
201
+rcf/
202
+
203
+# Windows Store app package directories and files
204
+AppPackages/
205
+BundleArtifacts/
206
+Package.StoreAssociation.xml
207
+_pkginfo.txt
208
+*.appx
209
+
210
+# Visual Studio cache files
211
+# files ending in .cache can be ignored
212
+*.[Cc]ache
213
+# but keep track of directories ending in .cache
214
+!?*.[Cc]ache/
215
+
216
+# Others
217
+ClientBin/
218
+~$*
219
+*~
220
+*.dbmdl
221
+*.dbproj.schemaview
222
+*.jfm
223
+*.pfx
224
+*.publishsettings
225
+orleans.codegen.cs
226
+
227
+# Including strong name files can present a security risk
228
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
229
+#*.snk
230
+
231
+# Since there are multiple workflows, uncomment next line to ignore bower_components
232
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
233
+#bower_components/
234
+
235
+# RIA/Silverlight projects
236
+Generated_Code/
237
+
238
+# Backup & report files from converting an old project file
239
+# to a newer Visual Studio version. Backup files are not needed,
240
+# because we have git ;-)
241
+_UpgradeReport_Files/
242
+Backup*/
243
+UpgradeLog*.XML
244
+UpgradeLog*.htm
245
+ServiceFabricBackup/
246
+*.rptproj.bak
247
+
248
+# SQL Server files
249
+*.mdf
250
+*.ldf
251
+*.ndf
252
+
253
+# Business Intelligence projects
254
+*.rdl.data
255
+*.bim.layout
256
+*.bim_*.settings
257
+*.rptproj.rsuser
258
+*- Backup*.rdl
259
+
260
+# Microsoft Fakes
261
+FakesAssemblies/
262
+
263
+# GhostDoc plugin setting file
264
+*.GhostDoc.xml
265
+
266
+# Node.js Tools for Visual Studio
267
+.ntvs_analysis.dat
268
+node_modules/
269
+
270
+# Visual Studio 6 build log
271
+*.plg
272
+
273
+# Visual Studio 6 workspace options file
274
+*.opt
275
+
276
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
277
+*.vbw
278
+
279
+# Visual Studio LightSwitch build output
280
+**/*.HTMLClient/GeneratedArtifacts
281
+**/*.DesktopClient/GeneratedArtifacts
282
+**/*.DesktopClient/ModelManifest.xml
283
+**/*.Server/GeneratedArtifacts
284
+**/*.Server/ModelManifest.xml
285
+_Pvt_Extensions
286
+
287
+# Paket dependency manager
288
+.paket/paket.exe
289
+paket-files/
290
+
291
+# FAKE - F# Make
292
+.fake/
293
+
294
+# JetBrains Rider
295
+.idea/
296
+*.sln.iml
297
+
298
+# CodeRush personal settings
299
+.cr/personal
300
+
301
+# Python Tools for Visual Studio (PTVS)
302
+__pycache__/
303
+*.pyc
304
+
305
+# Cake - Uncomment if you are using it
306
+# tools/**
307
+# !tools/packages.config
308
+
309
+# Tabs Studio
310
+*.tss
311
+
312
+# Telerik's JustMock configuration file
313
+*.jmconfig
314
+
315
+# BizTalk build output
316
+*.btp.cs
317
+*.btm.cs
318
+*.odx.cs
319
+*.xsd.cs
320
+
321
+# OpenCover UI analysis results
322
+OpenCover/
323
+
324
+# Azure Stream Analytics local run output
325
+ASALocalRun/
326
+
327
+# MSBuild Binary and Structured Log
328
+*.binlog
329
+
330
+# NVidia Nsight GPU debugger configuration file
331
+*.nvuser
332
+
333
+# MFractors (Xamarin productivity tool) working folder
334
+.mfractor/
335
+
336
+# Local History for Visual Studio
337
+.localhistory/
338
+
339
+# BeatPulse healthcheck temp database
340
+healthchecksdb

+ 25
- 0
UnivateProperties_API.sln Vedi File

@@ -0,0 +1,25 @@
1
+
2
+Microsoft Visual Studio Solution File, Format Version 12.00
3
+# Visual Studio Version 16
4
+VisualStudioVersion = 16.0.29009.5
5
+MinimumVisualStudioVersion = 10.0.40219.1
6
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnivateProperties_API", "UnivateProperties_API\UnivateProperties_API.csproj", "{EF248AE7-5D65-4894-AAD9-C6296270F03B}"
7
+EndProject
8
+Global
9
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
10
+		Debug|Any CPU = Debug|Any CPU
11
+		Release|Any CPU = Release|Any CPU
12
+	EndGlobalSection
13
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
14
+		{EF248AE7-5D65-4894-AAD9-C6296270F03B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15
+		{EF248AE7-5D65-4894-AAD9-C6296270F03B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16
+		{EF248AE7-5D65-4894-AAD9-C6296270F03B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17
+		{EF248AE7-5D65-4894-AAD9-C6296270F03B}.Release|Any CPU.Build.0 = Release|Any CPU
18
+	EndGlobalSection
19
+	GlobalSection(SolutionProperties) = preSolution
20
+		HideSolutionNode = FALSE
21
+	EndGlobalSection
22
+	GlobalSection(ExtensibilityGlobals) = postSolution
23
+		SolutionGuid = {925AD3C6-1FC6-40AC-92DD-ED0B244B9177}
24
+	EndGlobalSection
25
+EndGlobal

+ 12
- 0
UnivateProperties_API/Containers/Property/Group.cs Vedi File

@@ -0,0 +1,12 @@
1
+using System.Collections.Generic;
2
+
3
+namespace UnivateProperties_API.Containers.Property
4
+{
5
+    public class Group
6
+    {
7
+        #region Properties
8
+        public string Name { get; set; }
9
+        public List<GroupFields> Fields { get; set; }
10
+        #endregion
11
+    }
12
+}

+ 11
- 0
UnivateProperties_API/Containers/Property/GroupFields.cs Vedi File

@@ -0,0 +1,11 @@
1
+namespace UnivateProperties_API.Containers.Property
2
+{
3
+    public class GroupFields
4
+    {
5
+        #region Properties
6
+        public int ID { get; set; }
7
+        public string Name { get; set; }
8
+        public string Type { get; set; }
9
+        #endregion
10
+    }
11
+}

+ 11
- 0
UnivateProperties_API/Containers/Property/PropertyDetail.cs Vedi File

@@ -0,0 +1,11 @@
1
+namespace UnivateProperties_API.Containers.Property
2
+{
3
+    public class PropertyDetail
4
+    {
5
+        #region Properties
6
+        public string Name { get; set; }
7
+        public string Value { get; set; }
8
+        public string Description { get; set; }
9
+        #endregion 
10
+    }
11
+}

+ 12
- 0
UnivateProperties_API/Containers/Property/PropertyDetailGroup.cs Vedi File

@@ -0,0 +1,12 @@
1
+using System.Collections.Generic;
2
+
3
+namespace UnivateProperties_API.Containers.Property
4
+{
5
+    public class PropertyDetailGroup
6
+    {
7
+        #region Properties
8
+        public string GroupName { get; set; }
9
+        public List<PropertyDetail> Values { get; set; }
10
+        #endregion 
11
+    }
12
+}

+ 43
- 0
UnivateProperties_API/Containers/Property/PropertyDisplay.cs Vedi File

@@ -0,0 +1,43 @@
1
+namespace UnivateProperties_API.Containers.Property
2
+{
3
+    public class PropertyDisplay
4
+    {
5
+        #region Properties
6
+        public int Id { get; set; }
7
+        public string ShortDescription { get; set; }
8
+        public bool IsSale { get; set; }
9
+        public string DisplayPrice { get; set; }
10
+        public string Area { get; set; }
11
+        public string Beds { get; set; }
12
+        public string Baths { get; set; }
13
+        public string Garages { get; set; }
14
+        public bool ShowFooter
15
+        {
16
+            get
17
+            {
18
+                bool showFooter = true;
19
+
20
+                if (string.IsNullOrEmpty(Area) && string.IsNullOrEmpty(Beds) && string.IsNullOrEmpty(Baths) && string.IsNullOrEmpty(Garages))
21
+                    showFooter = false;
22
+
23
+                return showFooter;
24
+            }
25
+        }
26
+        public string Province { get; set; }
27
+        public string City { get; set; }
28
+        public string Suburb { get; set; }
29
+        public string DisplayImage { get; set; }
30
+        #endregion 
31
+    }
32
+
33
+    public class PropertySearch
34
+    {
35
+        #region Properties
36
+        public string Type { get; set; }
37
+        public string PropertyType { get; set; }
38
+        public string Province { get; set; }
39
+        public string City { get; set; }
40
+        public string Suburb { get; set; }
41
+        #endregion
42
+    }
43
+}

+ 14
- 0
UnivateProperties_API/Containers/Timeshare/UnitConfigurationDto.cs Vedi File

@@ -0,0 +1,14 @@
1
+using System.Collections.Generic;
2
+
3
+namespace UnivateProperties_API.Containers.Timeshare
4
+{
5
+    public class UnitConfigurationDto
6
+    {
7
+        public int Id { get; set; }
8
+        public string Code { get; set; }
9
+        public int Bedrooms { get; set; }
10
+        public int Adults { get; set; }
11
+        public int Children { get; set; }
12
+        public List<string> Types { get; set; }
13
+    }
14
+}

+ 11
- 0
UnivateProperties_API/Containers/Users/AgencyDto.cs Vedi File

@@ -0,0 +1,11 @@
1
+namespace UnivateProperties_API.Containers.Users
2
+{
3
+    public class AgencyDto
4
+    {
5
+        public int Id { get; set; }
6
+        public string Name { get; set; }
7
+        public string EaabeffcNumber { get; set; }
8
+        public string RegNo { get; set; }
9
+        public UserDto User { get; set; }
10
+    }
11
+}

+ 17
- 0
UnivateProperties_API/Containers/Users/Role.cs Vedi File

@@ -0,0 +1,17 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+
6
+namespace UnivateProperties_API.Containers.Users
7
+{
8
+    public class Role
9
+    {
10
+        public const string SuperAdmin = "Super Admin";
11
+        public const string PrivateUser = "Private User";
12
+        public const string Agency = "Agency";
13
+        public const string Agent = "Agent";
14
+        public const string ManagingAgent = "Managing Agent";
15
+        public const string Developer = "Developer";
16
+    }
17
+}

+ 15
- 0
UnivateProperties_API/Containers/Users/UserDto.cs Vedi File

@@ -0,0 +1,15 @@
1
+namespace UnivateProperties_API.Containers.Users
2
+{
3
+    public class UserDto
4
+    {
5
+        public int Id { get; set; }
6
+        public string Name { get; set; }
7
+        public string Surname { get; set; }
8
+        public int AgencyId { get; set; }
9
+        public string Username { get; set; }
10
+        public string Password { get; set; }
11
+        public string Email { get; set; }
12
+        public string Telephone { get; set; }
13
+        public string CellNumber { get; set; }
14
+    }
15
+}

+ 37
- 0
UnivateProperties_API/Containers/ValidateEntity.cs Vedi File

@@ -0,0 +1,37 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+
5
+namespace UnivateProperties_API.Containers
6
+{
7
+    public class ValidateEntity
8
+    {
9
+        public ValidateEntity()
10
+        {
11
+            Errors = new List<string>();
12
+        }
13
+
14
+        public ValidationResult Result
15
+        {
16
+            get
17
+            {
18
+                return (Errors == null || Errors.Count() == 0) ? ValidationResult.Success : ValidationResult.Failed;
19
+            }
20
+        }
21
+
22
+        public string ResultString
23
+        {
24
+            get
25
+            {
26
+                string message = string.Empty;
27
+                foreach(var item in Errors)
28
+                {
29
+                    message += $"{item} {Environment.NewLine}";
30
+                }
31
+                return message;
32
+            }
33
+        }
34
+
35
+        public List<string> Errors { get; set; }
36
+    }
37
+}

+ 79
- 0
UnivateProperties_API/Context/DataContext.cs Vedi File

@@ -0,0 +1,79 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using UnivateProperties_API.Model.Communication;
3
+using UnivateProperties_API.Model.Users;
4
+using UnivateProperties_API.Model.Property;
5
+using UnivateProperties_API.Model.Region;
6
+using UnivateProperties_API.Model.Timeshare;
7
+using System.Linq;
8
+using UnivateProperties_API.Model;
9
+
10
+namespace UnivateProperties_API.Context
11
+{
12
+    public class DataContext : DbContext
13
+    {
14
+        public DataContext(DbContextOptions<DataContext> options) : base(options)
15
+        {
16
+
17
+        }
18
+
19
+        #region User
20
+        public virtual DbSet<Agency> Agencies { get; set; }
21
+        public virtual DbSet<Agent> Agents { get; set; }
22
+        public virtual DbSet<User> Users { get; set; }
23
+        public virtual DbSet<Individual> Individuals { get; set; }
24
+        #endregion User
25
+
26
+        #region Communication
27
+        public virtual DbSet<Email> Emails { get; set; }
28
+        public virtual DbSet<SMTPAccount> Accounts { get; set; }
29
+        public virtual DbSet<SMTPHost> Hosts { get; set; }
30
+        #endregion Communication
31
+
32
+        #region Property
33
+        public DbSet<Property> Properties { get; set; }
34
+        public DbSet<PropertyImage> PropertyImages { get; set; }
35
+        public DbSet<PropertyType> PropertyTypes { get; set; }
36
+        public DbSet<PropertyUserField> PropertyUserFields { get; set; }
37
+        public DbSet<UserDefinedField> UserDefinedFields { get; set; }
38
+        public DbSet<UserDefinedGroup> UserDefinedGroups { get; set; }
39
+        #endregion
40
+
41
+        #region Region 
42
+        public DbSet<Province> Provinces { get; set; }
43
+        public DbSet<City> Cities { get; set; }
44
+        public DbSet<Suburb> Suburbs { get; set; }
45
+        #endregion
46
+
47
+        #region Timeshare
48
+        public DbSet<TimeshareWeek> Weeks { get; set; }
49
+        public DbSet<Status> Status { get; set; }
50
+        public DbSet<UnitConfiguration> UnitConfigurations { get; set; }
51
+        public DbSet<UnitConfigurationType> UnitConfigurationTypes { get; set; }
52
+        public DbSet<Season> Seasons { get; set; }
53
+        #endregion Timeshare
54
+
55
+        public override int SaveChanges()
56
+        {
57
+            foreach(var item in ChangeTracker
58
+                                    .Entries()
59
+                                    .Where(x => x.State == EntityState.Modified || x.State == EntityState.Added)
60
+                                    .Select(x => x.Entity)
61
+                                    .ToList())
62
+            {
63
+                if(item is BaseEntity)
64
+                {
65
+                    (item as BaseEntity).UpdateModified(string.Empty);
66
+                }
67
+            }
68
+            return base.SaveChanges();
69
+        }
70
+
71
+        protected override void OnModelCreating(ModelBuilder modelBuilder)
72
+        {
73
+            modelBuilder.Entity<SMTPHost>().ToTable("Hosts");
74
+            modelBuilder.Entity<UnitConfiguration>()
75
+                .HasIndex(u => u.Code)
76
+                .IsUnique();
77
+        }
78
+    }
79
+}

+ 66
- 0
UnivateProperties_API/Controllers/Communication/AccountController.cs Vedi File

@@ -0,0 +1,66 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Transactions;
3
+using UnivateProperties_API.Model.Communication;
4
+using UnivateProperties_API.Repository;
5
+
6
+namespace UnivateProperties_API.Controllers.Communication
7
+{
8
+    [Route("api/[controller]")]
9
+    [ApiController]
10
+    public class AccountController : ControllerBase
11
+    {
12
+        private readonly IRepository<SMTPAccount> _Repo;
13
+
14
+        public AccountController(IRepository<SMTPAccount> repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            var items = _Repo.GetAll();
23
+            return new OkObjectResult(items);
24
+        }
25
+
26
+        [HttpGet("{id}")]
27
+        public IActionResult Get(int id)
28
+        {
29
+            var item = _Repo.Get(x => x.Id == id);
30
+            return new OkObjectResult(item);
31
+        }
32
+
33
+        [HttpPost]
34
+        public IActionResult Post([FromBody] SMTPAccount item)
35
+        {
36
+            using (var scope = new TransactionScope())
37
+            {
38
+                _Repo.Insert(item);
39
+                scope.Complete();
40
+                return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
41
+            }
42
+        }
43
+
44
+        [HttpPut("{id}")]
45
+        public IActionResult Put([FromBody] SMTPAccount item)
46
+        {
47
+            if (item != null)
48
+            {
49
+                using (var scope = new TransactionScope())
50
+                {
51
+                    _Repo.Update(item);
52
+                    scope.Complete();
53
+                    return new OkResult();
54
+                }
55
+            }
56
+            return new NoContentResult();
57
+        }
58
+
59
+        [HttpDelete("{id}")]
60
+        public IActionResult Delete(int id)
61
+        {
62
+            _Repo.RemoveAtId(id);
63
+            return new OkResult();
64
+        }
65
+    }
66
+}

+ 66
- 0
UnivateProperties_API/Controllers/Communication/EmailController.cs Vedi File

@@ -0,0 +1,66 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Transactions;
3
+using UnivateProperties_API.Model.Communication;
4
+using UnivateProperties_API.Repository;
5
+
6
+namespace UnivateProperties_API.Controllers.Communication
7
+{
8
+    [Route("api/[controller]")]
9
+    [ApiController]
10
+    public class EmailController : ControllerBase
11
+    {
12
+        private readonly IRepository<Email> _Repo;
13
+
14
+        public EmailController(IRepository<Email> repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            var items = _Repo.GetAll();
23
+            return new OkObjectResult(items);
24
+        }
25
+
26
+        [HttpGet("{id}", Name = "Get")]
27
+        public IActionResult Get(int id)
28
+        {
29
+            var item = _Repo.Get(x => x.Id == id);
30
+            return new OkObjectResult(item);
31
+        }
32
+
33
+        [HttpPost]
34
+        public IActionResult Post([FromBody] Email item)
35
+        {
36
+            using (var scope = new TransactionScope())
37
+            {
38
+                _Repo.Insert(item);
39
+                scope.Complete();
40
+                return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
41
+            }
42
+        }
43
+
44
+        [HttpPut("{id}")]
45
+        public IActionResult Put([FromBody] Email item)
46
+        {
47
+            if (item != null)
48
+            {
49
+                using (var scope = new TransactionScope())
50
+                {
51
+                    _Repo.Update(item);
52
+                    scope.Complete();
53
+                    return new OkResult();
54
+                }
55
+            }
56
+            return new NoContentResult();
57
+        }
58
+
59
+        [HttpDelete("{id}")]
60
+        public IActionResult Delete(int id)
61
+        {
62
+            _Repo.RemoveAtId(id);
63
+            return new OkResult();
64
+        }
65
+    }
66
+}

+ 66
- 0
UnivateProperties_API/Controllers/Communication/HostController.cs Vedi File

@@ -0,0 +1,66 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Transactions;
3
+using UnivateProperties_API.Model.Communication;
4
+using UnivateProperties_API.Repository;
5
+
6
+namespace UnivateProperties_API.Controllers.Communication
7
+{
8
+    [Route("api/[controller]")]
9
+    [ApiController]
10
+    public class HostController : ControllerBase
11
+    {
12
+        private readonly IRepository<SMTPHost> _Repo;
13
+
14
+        public HostController(IRepository<SMTPHost> repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            var items = _Repo.GetAll();
23
+            return new OkObjectResult(items);
24
+        }
25
+
26
+        [HttpGet("{id}")]
27
+        public IActionResult Get(int id)
28
+        {
29
+            var item = _Repo.Get(x => x.Id == id);
30
+            return new OkObjectResult(item);
31
+        }
32
+
33
+        [HttpPost]
34
+        public IActionResult Post([FromBody] SMTPHost item)
35
+        {
36
+            using (var scope = new TransactionScope())
37
+            {
38
+                _Repo.Insert(item);
39
+                scope.Complete();
40
+                return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
41
+            }
42
+        }
43
+
44
+        [HttpPut("{id}")]
45
+        public IActionResult Put([FromBody] SMTPHost item)
46
+        {
47
+            if (item != null)
48
+            {
49
+                using (var scope = new TransactionScope())
50
+                {
51
+                    _Repo.Update(item);
52
+                    scope.Complete();
53
+                    return new OkResult();
54
+                }
55
+            }
56
+            return new NoContentResult();
57
+        }
58
+
59
+        [HttpDelete("{id}")]
60
+        public IActionResult Delete(int id)
61
+        {
62
+            _Repo.RemoveAtId(id);
63
+            return new OkResult();
64
+        }
65
+    }
66
+}

+ 79
- 0
UnivateProperties_API/Controllers/Properties/PropertyController.cs Vedi File

@@ -0,0 +1,79 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System;
3
+using System.Transactions;
4
+using UnivateProperties_API.Containers.Property;
5
+using UnivateProperties_API.Model.Property;
6
+using UnivateProperties_API.Repository.Properties;
7
+
8
+namespace UnivateProperties_API.Controllers.Properties
9
+{
10
+    [Route("Property/[controller]")]
11
+    [ApiController]
12
+    public class PropertyController : ControllerBase
13
+    {
14
+        private readonly IPropertyRepository _Repo;
15
+
16
+        public PropertyController(IPropertyRepository repo)
17
+        {
18
+            _Repo = repo;
19
+        }
20
+
21
+        [HttpGet]
22
+        public IActionResult Get()
23
+        {
24
+            return new OkObjectResult(_Repo.GetDisplay());
25
+        }
26
+
27
+        [HttpGet("{id}")]
28
+        public IActionResult Get(int id)
29
+        {
30
+            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
31
+        }
32
+
33
+        [HttpGet("search/{type}/{keyword}")]
34
+        public IActionResult Get(string type, string Keyword)
35
+        {
36
+            return new OkObjectResult(_Repo.GetDisplay(Keyword));
37
+        }
38
+
39
+        [HttpGet("search/{type}/{propertytype}/{province}/{city}/{suburb}/{proptype}")]
40
+        public IActionResult Get(string type, string propertyType, string province, string city, string suburb, string propType)
41
+        {
42
+            return new OkObjectResult(_Repo.GetDisplay(type, propertyType, province, city, suburb, propType));
43
+        }
44
+
45
+        [HttpPost]
46
+        public IActionResult Post([FromBody] Property property)
47
+        {
48
+            using (var scope = new TransactionScope())
49
+            {
50
+                _Repo.Insert(property);
51
+                scope.Complete();
52
+                return CreatedAtAction(nameof(Get), new { id = property.Id }, property);
53
+            }
54
+        }
55
+
56
+        [HttpPut]
57
+        public IActionResult Put([FromBody] Property property)
58
+        {
59
+            if (property != null)
60
+            {
61
+                using (var scope = new TransactionScope())
62
+                {
63
+                    _Repo.Update(property);
64
+                    scope.Complete();
65
+                    return new OkResult();
66
+                }
67
+            }
68
+            return new NoContentResult();
69
+        }
70
+
71
+        [HttpDelete("{id}")]
72
+        public IActionResult Delete(int id)
73
+        {
74
+            _Repo.RemoveAtId(id);
75
+            return new OkResult();
76
+        }
77
+    }
78
+}
79
+

+ 38
- 0
UnivateProperties_API/Controllers/Properties/PropertyFieldsController.cs Vedi File

@@ -0,0 +1,38 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using UnivateProperties_API.Repository.Properties;
3
+
4
+namespace UnivateProperties_API.Controllers.Properties
5
+{
6
+    [Route("Property/[controller]")]
7
+    [ApiController]
8
+    public class PropertyFieldsController : ControllerBase
9
+    {
10
+        private readonly IUserDefinedGroupRepository _Repo;
11
+
12
+        public PropertyFieldsController(IUserDefinedGroupRepository repo)
13
+        {
14
+            _Repo = repo;
15
+        }
16
+
17
+        [HttpGet]
18
+        public IActionResult Get()
19
+        {
20
+            return new OkObjectResult(_Repo.GetFieldList(""));
21
+        }
22
+
23
+        [HttpGet("{name}")]
24
+        public IActionResult Get(string name)
25
+        {
26
+            return new OkObjectResult(_Repo.GetFieldList(name));
27
+        }
28
+
29
+        [HttpGet("{PropertyType}/{type}")]
30
+        public IActionResult Get(string PropertyType, string type)
31
+        {
32
+            return new OkObjectResult(_Repo.GetFieldListByPropType(type));
33
+        }
34
+    }
35
+
36
+
37
+}
38
+

+ 71
- 0
UnivateProperties_API/Controllers/Properties/PropertyImageController.cs Vedi File

@@ -0,0 +1,71 @@
1
+using System.Transactions;
2
+using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Model.Property;
4
+using UnivateProperties_API.Repository.Properties;
5
+
6
+namespace UnivateProperties_API.Controllers.Properties
7
+{
8
+    [Route("Property/[controller]")]
9
+    [ApiController]
10
+    public class PropertyImageController : ControllerBase
11
+    {
12
+        private readonly IPropertyImageRepository _Repo;
13
+
14
+        public PropertyImageController(IPropertyImageRepository repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            return new OkObjectResult(_Repo.GetAll());
23
+        }
24
+
25
+        [HttpGet("{id}")]
26
+        public IActionResult Get(int id)
27
+        {
28
+            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
29
+        }
30
+
31
+        [HttpGet("{Property}/{PropertyId}", Name = "GetImagesByProperty")]
32
+        public IActionResult Get(string Property, int PropertyId) //Property string is more of a placeholder here.
33
+        {
34
+            return new OkObjectResult(_Repo.GetImages(PropertyId));
35
+        }
36
+
37
+        [HttpPost]
38
+        public IActionResult Post([FromBody] PropertyImage propertyImage)
39
+        {
40
+            using (var scope = new TransactionScope())
41
+            {
42
+                _Repo.Insert(propertyImage);
43
+                scope.Complete();
44
+                return CreatedAtAction(nameof(Get), new { id = propertyImage.Id }, propertyImage);
45
+            }
46
+        }
47
+
48
+        [HttpPut]
49
+        public IActionResult Put([FromBody] PropertyImage propertyImage)
50
+        {
51
+            if (propertyImage != null)
52
+            {
53
+                using (var scope = new TransactionScope())
54
+                {
55
+                    _Repo.Update(propertyImage);
56
+                    scope.Complete();
57
+                    return new OkResult();
58
+                }
59
+            }
60
+            return new NoContentResult();
61
+        }
62
+
63
+        [HttpDelete("{id}")]
64
+        public IActionResult Delete(int id)
65
+        {
66
+            _Repo.RemoveAtId(id);
67
+            return new OkResult();
68
+        }
69
+    }
70
+}
71
+

+ 83
- 0
UnivateProperties_API/Controllers/Properties/PropertyTypeController.cs Vedi File

@@ -0,0 +1,83 @@
1
+using System.Transactions;
2
+using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Model.Property;
4
+using UnivateProperties_API.Repository;
5
+
6
+namespace UnivateProperties_API.Controllers.Properties
7
+{
8
+    [Route("Property/[controller]")]
9
+    [ApiController]
10
+    public class PropertyTypeController : ControllerBase
11
+    {
12
+        private readonly IRepository<PropertyType> _Repo;
13
+
14
+        public PropertyTypeController(IRepository<PropertyType> repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            return new OkObjectResult(_Repo.GetAll());
23
+        }
24
+
25
+        [HttpGet("{id}")]
26
+        public IActionResult Get(int id)
27
+        {
28
+            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
29
+        }
30
+
31
+        [HttpGet("{type}/{typename}")]
32
+        public IActionResult Get(string Type, string TypeName)
33
+        {
34
+
35
+            PropertyUsageType type = PropertyUsageType.Both;
36
+            switch (TypeName.ToUpper())
37
+            {
38
+                case "RESIDENTIAL":
39
+                    type = PropertyUsageType.Residential;
40
+                    break;
41
+                case "COMMERCIAL":
42
+                    type = PropertyUsageType.Commercial;
43
+                    break;
44
+            }
45
+
46
+            return new OkObjectResult(_Repo.Get(x => x.UsageType == type || x.UsageType == PropertyUsageType.Both));
47
+        }
48
+
49
+        [HttpPost]
50
+        public IActionResult Post([FromBody] PropertyType propertyType)
51
+        {
52
+            using (var scope = new TransactionScope())
53
+            {
54
+                _Repo.Insert(propertyType);
55
+                scope.Complete();
56
+                return CreatedAtAction(nameof(Get), new { id = propertyType.Id }, propertyType);
57
+            }
58
+        }
59
+
60
+        [HttpPut]
61
+        public IActionResult Put([FromBody] PropertyType propertyType)
62
+        {
63
+            if (propertyType != null)
64
+            {
65
+                using (var scope = new TransactionScope())
66
+                {
67
+                    _Repo.Update(propertyType);
68
+                    scope.Complete();
69
+                    return new OkResult();
70
+                }
71
+            }
72
+            return new NoContentResult();
73
+        }
74
+
75
+        [HttpDelete("{id}")]
76
+        public IActionResult Delete(int id)
77
+        {
78
+            _Repo.RemoveAtId(id);
79
+            return new OkResult();
80
+        }
81
+    }
82
+}
83
+

+ 65
- 0
UnivateProperties_API/Controllers/Properties/PropertyUserFieldController.cs Vedi File

@@ -0,0 +1,65 @@
1
+using System.Transactions;
2
+using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Model.Property;
4
+using UnivateProperties_API.Repository;
5
+
6
+namespace UnivateProperties_API.Controllers.Properties
7
+{
8
+    [Route("Property/[controller]")]
9
+    [ApiController]
10
+    public class PropertyUserFieldController : ControllerBase
11
+    {
12
+        private readonly IRepository<PropertyUserField> _Repo;
13
+
14
+        public PropertyUserFieldController(IRepository<PropertyUserField> repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            return new OkObjectResult(_Repo.GetAll());
23
+        }
24
+
25
+        [HttpGet("{id}")]
26
+        public IActionResult Get(int id)
27
+        {
28
+            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
29
+        }
30
+
31
+        [HttpPost]
32
+        public IActionResult Post([FromBody] PropertyUserField propertyUserField)
33
+        {
34
+            using (var scope = new TransactionScope())
35
+            {
36
+                _Repo.Insert(propertyUserField);
37
+                scope.Complete();
38
+                return CreatedAtAction(nameof(Get), new { id = propertyUserField.Id }, propertyUserField);
39
+            }
40
+        }
41
+
42
+        [HttpPut]
43
+        public IActionResult Put([FromBody] PropertyUserField propertyUserField)
44
+        {
45
+            if (propertyUserField != null)
46
+            {
47
+                using (var scope = new TransactionScope())
48
+                {
49
+                    _Repo.Update(propertyUserField);
50
+                    scope.Complete();
51
+                    return new OkResult();
52
+                }
53
+            }
54
+            return new NoContentResult();
55
+        }
56
+
57
+        [HttpDelete("{id}")]
58
+        public IActionResult Delete(int id)
59
+        {
60
+            _Repo.RemoveAtId(id);
61
+            return new OkResult();
62
+        }
63
+    }
64
+}
65
+

+ 71
- 0
UnivateProperties_API/Controllers/Properties/UserDefinedFieldController.cs Vedi File

@@ -0,0 +1,71 @@
1
+using System.Transactions;
2
+using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Model.Property;
4
+using UnivateProperties_API.Repository;
5
+
6
+namespace UnivateProperties_API.Controllers.Properties
7
+{
8
+    [Route("Property/[controller]")]
9
+    [ApiController]
10
+    public class UserDefinedFieldController : ControllerBase
11
+    {
12
+        private readonly IRepository<UserDefinedField> _Repo;
13
+
14
+        public UserDefinedFieldController(IRepository<UserDefinedField> repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            return new OkObjectResult(_Repo.GetAll());
23
+        }
24
+
25
+        [HttpGet("{id}")]
26
+        public IActionResult Get(int id)
27
+        {
28
+            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
29
+        }
30
+
31
+        [HttpGet("{group}/{id}")]
32
+        public IActionResult Get(string group, int id)
33
+        {
34
+            return new OkObjectResult(_Repo.Get(x => x.GroupId == id));
35
+        }
36
+
37
+        [HttpPost]
38
+        public IActionResult Post([FromBody] UserDefinedField userDefinedField)
39
+        {
40
+            using (var scope = new TransactionScope())
41
+            {
42
+                _Repo.Insert(userDefinedField);
43
+                scope.Complete();
44
+                return CreatedAtAction(nameof(Get), new { id = userDefinedField.Id }, userDefinedField);
45
+            }
46
+        }
47
+
48
+        [HttpPut]
49
+        public IActionResult Put([FromBody] UserDefinedField userDefinedField)
50
+        {
51
+            if (userDefinedField != null)
52
+            {
53
+                using (var scope = new TransactionScope())
54
+                {
55
+                    _Repo.Update(userDefinedField);
56
+                    scope.Complete();
57
+                    return new OkResult();
58
+                }
59
+            }
60
+            return new NoContentResult();
61
+        }
62
+
63
+        [HttpDelete("{id}")]
64
+        public IActionResult Delete(int id)
65
+        {
66
+            _Repo.RemoveAtId(id);
67
+            return new OkResult();
68
+        }
69
+    }
70
+}
71
+

+ 65
- 0
UnivateProperties_API/Controllers/Properties/UserDefinedGroupController.cs Vedi File

@@ -0,0 +1,65 @@
1
+using System.Transactions;
2
+using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Model.Property;
4
+using UnivateProperties_API.Repository.Properties;
5
+
6
+namespace UnivateProperties_API.Controllers.Properties
7
+{
8
+    [Route("Property/[controller]")]
9
+    [ApiController]
10
+    public class UserDefinedGroupController : ControllerBase
11
+    {
12
+        private readonly IUserDefinedGroupRepository _Repo;
13
+
14
+        public UserDefinedGroupController(IUserDefinedGroupRepository repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            return new OkObjectResult(_Repo.GetAll());
23
+        }
24
+
25
+        [HttpGet("{id}")]
26
+        public IActionResult Get(int id)
27
+        {
28
+            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
29
+        }
30
+
31
+        [HttpPost]
32
+        public IActionResult Post([FromBody] UserDefinedGroup userDefinedGroup)
33
+        {
34
+            using (var scope = new TransactionScope())
35
+            {
36
+                _Repo.Insert(userDefinedGroup);
37
+                scope.Complete();
38
+                return CreatedAtAction(nameof(Get), new { id = userDefinedGroup.Id }, userDefinedGroup);
39
+            }
40
+        }
41
+
42
+        [HttpPut]
43
+        public IActionResult Put([FromBody] UserDefinedGroup userDefinedGroup)
44
+        {
45
+            if (userDefinedGroup != null)
46
+            {
47
+                using (var scope = new TransactionScope())
48
+                {
49
+                    _Repo.Update(userDefinedGroup);
50
+                    scope.Complete();
51
+                    return new OkResult();
52
+                }
53
+            }
54
+            return new NoContentResult();
55
+        }
56
+
57
+        [HttpDelete("{id}")]
58
+        public IActionResult Delete(int id)
59
+        {
60
+            _Repo.RemoveAtId(id);
61
+            return new OkResult();
62
+        }
63
+    }
64
+}
65
+

+ 71
- 0
UnivateProperties_API/Controllers/Region/CityController.cs Vedi File

@@ -0,0 +1,71 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Transactions;
3
+using UnivateProperties_API.Model.Region;
4
+using UnivateProperties_API.Repository.Region;
5
+
6
+namespace UnivateProperties_API.Controllers.Region
7
+{
8
+    [Route("Region/[controller]")]
9
+    [ApiController]
10
+    public class CityController : ControllerBase
11
+    {
12
+        private readonly ICityRepository _Repo;
13
+
14
+        public CityController(ICityRepository repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+
20
+        [HttpGet]
21
+        public IActionResult Get()
22
+        {
23
+            return new OkObjectResult(_Repo.GetAll());
24
+        }
25
+
26
+        [HttpGet("{id}")]
27
+        public IActionResult Get(int id)
28
+        {
29
+            return new OkObjectResult(_Repo.Get(x => x.Id == id));
30
+        }
31
+
32
+        [HttpGet("getby/{value}")]
33
+        public IActionResult Get(string value)
34
+        {
35
+            return new OkObjectResult(_Repo.GetBy(value));
36
+        }
37
+
38
+        [HttpPost]
39
+        public IActionResult Post([FromBody] City city)
40
+        {
41
+            using (var scope = new TransactionScope())
42
+            {
43
+                _Repo.Insert(city);
44
+                scope.Complete();
45
+                return CreatedAtAction(nameof(Get), new { id = city.Id }, city);
46
+            }
47
+        }
48
+
49
+        [HttpPut]
50
+        public IActionResult Put([FromBody] City city)
51
+        {
52
+            if (city != null)
53
+            {
54
+                using (var scope = new TransactionScope())
55
+                {
56
+                    _Repo.Update(city);
57
+                    scope.Complete();
58
+                    return new OkResult();
59
+                }
60
+            }
61
+            return new NoContentResult();
62
+        }
63
+
64
+        [HttpDelete("{id}")]
65
+        public IActionResult Delete(int id)
66
+        {
67
+            _Repo.RemoveAtId(id);
68
+            return new OkResult();
69
+        }
70
+    }
71
+}

+ 64
- 0
UnivateProperties_API/Controllers/Region/ProvinceController.cs Vedi File

@@ -0,0 +1,64 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Transactions;
3
+using UnivateProperties_API.Model.Region;
4
+using UnivateProperties_API.Repository;
5
+
6
+namespace UnivateProperties_API.Controllers.Region
7
+{
8
+    [Route("Region/[controller]")]
9
+    [ApiController]
10
+    public class ProvinceController : ControllerBase
11
+    {
12
+        private readonly IRepository<Province> _Repo;
13
+
14
+        public ProvinceController(IRepository<Province> repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            return new OkObjectResult(_Repo.GetAll());
23
+        }
24
+
25
+        [HttpGet("{id}")]
26
+        public IActionResult Get(int id)
27
+        {
28
+            return new OkObjectResult(_Repo.Get(x => x.Id == id));
29
+        }
30
+
31
+        [HttpPost]
32
+        public IActionResult Post([FromBody] Province province)
33
+        {
34
+            using (var scope = new TransactionScope())
35
+            {
36
+                _Repo.Insert(province);
37
+                scope.Complete();
38
+                return CreatedAtAction(nameof(Get), new { id = province.Id }, province);
39
+            }
40
+        }
41
+
42
+        [HttpPut]
43
+        public IActionResult Put([FromBody] Province province)
44
+        {
45
+            if (province != null)
46
+            {
47
+                using (var scope = new TransactionScope())
48
+                {
49
+                    _Repo.Update(province);
50
+                    scope.Complete();
51
+                    return new OkResult();
52
+                }
53
+            }
54
+            return new NoContentResult();
55
+        }
56
+
57
+        [HttpDelete("{id}")]
58
+        public IActionResult Delete(int id)
59
+        {
60
+            _Repo.RemoveAtId(id);
61
+            return new OkResult();
62
+        }
63
+    }
64
+}

+ 70
- 0
UnivateProperties_API/Controllers/Region/SuburbController.cs Vedi File

@@ -0,0 +1,70 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Transactions;
3
+using UnivateProperties_API.Model.Region;
4
+using UnivateProperties_API.Repository.Region;
5
+
6
+namespace UnivateProperties_API.Controllers.Region
7
+{
8
+    [Route("Region/[controller]")]
9
+    [ApiController]
10
+    public class SuburbController : ControllerBase
11
+    {
12
+        private readonly ISuburbRepository _Repo;
13
+
14
+        public SuburbController(ISuburbRepository repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            return new OkObjectResult(_Repo.GetAll());
23
+        }
24
+
25
+        [HttpGet("{id}")]
26
+        public IActionResult Get(int id)
27
+        {
28
+            return new OkObjectResult(_Repo.Get(x => x.Id == id));
29
+        }
30
+
31
+        [HttpGet("{province}/{city}")]
32
+        public IActionResult Get(string Province, string City)
33
+        {
34
+            return new OkObjectResult(_Repo.GetBy(Province, City));
35
+        }
36
+
37
+        [HttpPost]
38
+        public IActionResult Post([FromBody] Suburb suburb)
39
+        {
40
+            using (var scope = new TransactionScope())
41
+            {
42
+                _Repo.Insert(suburb);
43
+                scope.Complete();
44
+                return CreatedAtAction(nameof(Get), new { id = suburb.Id }, suburb);
45
+            }
46
+        }
47
+
48
+        [HttpPut]
49
+        public IActionResult Put([FromBody] Suburb suburb)
50
+        {
51
+            if (suburb != null)
52
+            {
53
+                using (var scope = new TransactionScope())
54
+                {
55
+                    _Repo.Update(suburb);
56
+                    scope.Complete();
57
+                    return new OkResult();
58
+                }
59
+            }
60
+            return new NoContentResult();
61
+        }
62
+
63
+        [HttpDelete("{id}")]
64
+        public IActionResult Delete(int id)
65
+        {
66
+            _Repo.RemoveAtId(id);
67
+            return new OkResult();
68
+        }
69
+    }
70
+}

+ 66
- 0
UnivateProperties_API/Controllers/Timeshare/SeasonController.cs Vedi File

@@ -0,0 +1,66 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Transactions;
3
+using UnivateProperties_API.Model.Timeshare;
4
+using UnivateProperties_API.Repository;
5
+
6
+namespace UnivateProperties_API.Controllers.Timeshare
7
+{
8
+    [Route("api/[controller]")]
9
+    [ApiController]
10
+    public class SeasonController : ControllerBase
11
+    {
12
+        private readonly IRepository<Season> _Repo;
13
+
14
+        public SeasonController(IRepository<Season> repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            var items = _Repo.GetAll();
23
+            return new OkObjectResult(items);
24
+        }
25
+
26
+        [HttpGet("{id}")]
27
+        public IActionResult Get(int id)
28
+        {
29
+            var item = _Repo.Get(x => x.Id == id);
30
+            return new OkObjectResult(item);
31
+        }
32
+
33
+        [HttpPost]
34
+        public IActionResult Post([FromBody] Season item)
35
+        {
36
+            using (var scope = new TransactionScope())
37
+            {
38
+                _Repo.Insert(item);
39
+                scope.Complete();
40
+                return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
41
+            }
42
+        }
43
+
44
+        [HttpPut("{id}")]
45
+        public IActionResult Put([FromBody] Season item)
46
+        {
47
+            if (item != null)
48
+            {
49
+                using (var scope = new TransactionScope())
50
+                {
51
+                    _Repo.Update(item);
52
+                    scope.Complete();
53
+                    return new OkResult();
54
+                }
55
+            }
56
+            return new NoContentResult();
57
+        }
58
+
59
+        [HttpDelete("{id}")]
60
+        public IActionResult Delete(int id)
61
+        {
62
+            _Repo.RemoveAtId(id);
63
+            return new OkResult();
64
+        }
65
+    }
66
+}

+ 66
- 0
UnivateProperties_API/Controllers/Timeshare/StatusController.cs Vedi File

@@ -0,0 +1,66 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Transactions;
3
+using UnivateProperties_API.Model.Timeshare;
4
+using UnivateProperties_API.Repository;
5
+
6
+namespace UnivateProperties_API.Controllers.Timeshare
7
+{
8
+    [Route("api/[controller]")]
9
+    [ApiController]
10
+    public class StatusController : ControllerBase
11
+    {
12
+        private readonly IRepository<Status> _Repo;
13
+
14
+        public StatusController(IRepository<Status> repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            var items = _Repo.GetAll();
23
+            return new OkObjectResult(items);
24
+        }
25
+
26
+        [HttpGet("{id}")]
27
+        public IActionResult Get(int id)
28
+        {
29
+            var item = _Repo.Get(x => x.Id == id);
30
+            return new OkObjectResult(item);
31
+        }
32
+
33
+        [HttpPost]
34
+        public IActionResult Post([FromBody] Status item)
35
+        {
36
+            using (var scope = new TransactionScope())
37
+            {
38
+                _Repo.Insert(item);
39
+                scope.Complete();
40
+                return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
41
+            }
42
+        }
43
+
44
+        [HttpPut("{id}")]
45
+        public IActionResult Put([FromBody] Status item)
46
+        {
47
+            if (item != null)
48
+            {
49
+                using (var scope = new TransactionScope())
50
+                {
51
+                    _Repo.Update(item);
52
+                    scope.Complete();
53
+                    return new OkResult();
54
+                }
55
+            }
56
+            return new NoContentResult();
57
+        }
58
+
59
+        [HttpDelete("{id}")]
60
+        public IActionResult Delete(int id)
61
+        {
62
+            _Repo.RemoveAtId(id);
63
+            return new OkResult();
64
+        }
65
+    }
66
+}

+ 66
- 0
UnivateProperties_API/Controllers/Timeshare/TimeshareWeekController.cs Vedi File

@@ -0,0 +1,66 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Transactions;
3
+using UnivateProperties_API.Model.Timeshare;
4
+using UnivateProperties_API.Repository;
5
+
6
+namespace UnivateProperties_API.Controllers.Timeshare
7
+{
8
+    [Route("api/[controller]")]
9
+    [ApiController]
10
+    public class TimeshareWeekController : ControllerBase
11
+    {
12
+        private readonly IRepository<TimeshareWeek> _Repo;
13
+
14
+        public TimeshareWeekController(IRepository<TimeshareWeek> repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            var items = _Repo.GetAll();
23
+            return new OkObjectResult(items);
24
+        }
25
+
26
+        [HttpGet("{id}")]
27
+        public IActionResult Get(int id)
28
+        {
29
+            var item = _Repo.Get(x => x.Id == id);
30
+            return new OkObjectResult(item);
31
+        }
32
+
33
+        [HttpPost]
34
+        public IActionResult Post([FromBody] TimeshareWeek item)
35
+        {
36
+            using (var scope = new TransactionScope())
37
+            {
38
+                _Repo.Insert(item);
39
+                scope.Complete();
40
+                return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
41
+            }
42
+        }
43
+
44
+        [HttpPut("{id}")]
45
+        public IActionResult Put([FromBody] TimeshareWeek item)
46
+        {
47
+            if (item != null)
48
+            {
49
+                using (var scope = new TransactionScope())
50
+                {
51
+                    _Repo.Update(item);
52
+                    scope.Complete();
53
+                    return new OkResult();
54
+                }
55
+            }
56
+            return new NoContentResult();
57
+        }
58
+
59
+        [HttpDelete("{id}")]
60
+        public IActionResult Delete(int id)
61
+        {
62
+            _Repo.RemoveAtId(id);
63
+            return new OkResult();
64
+        }
65
+    }
66
+}

+ 67
- 0
UnivateProperties_API/Controllers/Timeshare/UnitConfigurationController.cs Vedi File

@@ -0,0 +1,67 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Transactions;
3
+using UnivateProperties_API.Model.Timeshare;
4
+using UnivateProperties_API.Repository;
5
+using UnivateProperties_API.Repository.Timeshare;
6
+
7
+namespace UnivateProperties_API.Controllers.Timeshare
8
+{
9
+    [Route("api/[controller]")]
10
+    [ApiController]
11
+    public class UnitConfigurationController : ControllerBase
12
+    {
13
+        private readonly IRepository<UnitConfiguration> _Repo;
14
+
15
+        public UnitConfigurationController(IRepository<UnitConfiguration> repo)
16
+        {
17
+            _Repo = repo;
18
+        }
19
+
20
+        [HttpGet]
21
+        public IActionResult Get()
22
+        {
23
+            var items = (_Repo as UnitConfigurationRepository).GetMyDetailed();
24
+            return new OkObjectResult(items);
25
+        }
26
+
27
+        [HttpGet("{id}")]
28
+        public IActionResult Get(int id)
29
+        {
30
+            var item = _Repo.Get(x => x.Id == id);
31
+            return new OkObjectResult(item);
32
+        }
33
+
34
+        [HttpPost]
35
+        public IActionResult Post([FromBody] UnitConfiguration item)
36
+        {
37
+            using (var scope = new TransactionScope())
38
+            {
39
+                _Repo.Insert(item);
40
+                scope.Complete();
41
+                return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
42
+            }
43
+        }
44
+
45
+        [HttpPut("{id}")]
46
+        public IActionResult Put([FromBody] UnitConfiguration item)
47
+        {
48
+            if (item != null)
49
+            {
50
+                using (var scope = new TransactionScope())
51
+                {
52
+                    _Repo.Update(item);
53
+                    scope.Complete();
54
+                    return new OkResult();
55
+                }
56
+            }
57
+            return new NoContentResult();
58
+        }
59
+
60
+        [HttpDelete("{id}")]
61
+        public IActionResult Delete(int id)
62
+        {
63
+            _Repo.RemoveAtId(id);
64
+            return new OkResult();
65
+        }
66
+    }
67
+}

+ 65
- 0
UnivateProperties_API/Controllers/Users/AgencyController.cs Vedi File

@@ -0,0 +1,65 @@
1
+using System.Transactions;
2
+using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Model.Users;
4
+using UnivateProperties_API.Repository;
5
+using UnivateProperties_API.Repository.Users;
6
+
7
+namespace User_API.Controllers
8
+{
9
+    [Route("api/[controller]")]
10
+    [ApiController]
11
+    public class AgencyController : ControllerBase
12
+    {
13
+        private readonly IRepository<Agency> _Repo;
14
+
15
+        public AgencyController(IRepository<Agency> repo)
16
+        {
17
+            _Repo = repo;
18
+        }
19
+
20
+        [HttpGet]
21
+        public IActionResult Get()
22
+        {
23
+            return new OkObjectResult(_Repo.GetAll());
24
+        }
25
+
26
+        [HttpGet("{id}")]
27
+        public IActionResult Get(int id)
28
+        {
29
+            return new OkObjectResult(_Repo.Get(x => x.Id == id));
30
+        }
31
+
32
+        [HttpPost()]
33
+        public IActionResult Post([FromBody] Agency agency)
34
+        {
35
+            using (var scope = new TransactionScope())
36
+            {
37
+                _Repo.Insert(agency);
38
+                scope.Complete();
39
+                return CreatedAtAction(nameof(Get), new { id = agency.Id }, agency);
40
+            }
41
+        }
42
+
43
+        [HttpPut()]
44
+        public IActionResult Put([FromBody] Agency agency)
45
+        {
46
+            if (agency != null)
47
+            {
48
+                using (var scope = new TransactionScope())
49
+                {
50
+                    _Repo.Update(agency);
51
+                    scope.Complete();
52
+                    return new OkResult();
53
+                }
54
+            }
55
+            return new NoContentResult();
56
+        }
57
+
58
+        [HttpDelete("{id}")]
59
+        public IActionResult Delete(int id)
60
+        {
61
+            _Repo.RemoveAtId(id);
62
+            return new OkResult();
63
+        }
64
+    }
65
+}

+ 65
- 0
UnivateProperties_API/Controllers/Users/AgentController.cs Vedi File

@@ -0,0 +1,65 @@
1
+using System.Transactions;
2
+using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Model.Users;
4
+using UnivateProperties_API.Repository;
5
+using UnivateProperties_API.Repository.Users;
6
+
7
+namespace User_API.Controllers
8
+{
9
+    [Route("api/[controller]")]
10
+    [ApiController]
11
+    public class AgentController : ControllerBase
12
+    {
13
+        private readonly IRepository<Agent> _Repo;
14
+
15
+        public AgentController(IRepository<Agent> repo)
16
+        {
17
+            _Repo = repo;
18
+        }
19
+
20
+        [HttpGet]
21
+        public IActionResult Get()
22
+        {
23
+            return new OkObjectResult(_Repo.GetAll());
24
+        }
25
+
26
+        [HttpGet("{id}")]
27
+        public IActionResult Get(int id)
28
+        {
29
+            return new OkObjectResult(_Repo.Get(x => x.Id == id));
30
+        }
31
+
32
+        [HttpPost()]
33
+        public IActionResult Post([FromBody] Agent agent)
34
+        {
35
+            using (var scope = new TransactionScope())
36
+            {
37
+                _Repo.Insert(agent);
38
+                scope.Complete();
39
+                return CreatedAtAction(nameof(Get), new { id = agent.Id }, agent);
40
+            }
41
+        }
42
+
43
+        [HttpPut()]
44
+        public IActionResult Put([FromBody] Agent agent)
45
+        {
46
+            if (agent != null)
47
+            {
48
+                using (var scope = new TransactionScope())
49
+                {
50
+                    _Repo.Update(agent);
51
+                    scope.Complete();
52
+                    return new OkResult();
53
+                }
54
+            }
55
+            return new NoContentResult();
56
+        }
57
+
58
+        [HttpDelete("{id}")]
59
+        public IActionResult Delete(int id)
60
+        {
61
+            _Repo.RemoveAtId(id);
62
+            return new OkResult();
63
+        }
64
+    }
65
+}

+ 65
- 0
UnivateProperties_API/Controllers/Users/IndividualController.cs Vedi File

@@ -0,0 +1,65 @@
1
+using System.Transactions;
2
+using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Model.Users;
4
+using UnivateProperties_API.Repository;
5
+using UnivateProperties_API.Repository.Users;
6
+
7
+namespace User_API.Controllers
8
+{
9
+    [Route("api/[controller]")]
10
+    [ApiController]
11
+    public class IndividualController : ControllerBase
12
+    {
13
+        private readonly IRepository<Individual> _Repo;
14
+
15
+        public IndividualController(IRepository<Individual> repo)
16
+        {
17
+            _Repo = repo;
18
+        }
19
+
20
+        [HttpGet]
21
+        public IActionResult Get()
22
+        {
23
+            return new OkObjectResult(_Repo.GetAll());
24
+        }
25
+
26
+        [HttpGet("{id}")]
27
+        public IActionResult Get(int id)
28
+        {
29
+            return new OkObjectResult(_Repo.Get(x => x.Id == id));
30
+        }
31
+
32
+        [HttpPost()]
33
+        public IActionResult Post([FromBody] Individual individual)
34
+        {
35
+            using (var scope = new TransactionScope())
36
+            {
37
+                _Repo.Insert(individual);
38
+                scope.Complete();
39
+                return CreatedAtAction(nameof(Get), new { id = individual.Id }, individual);
40
+            }
41
+        }
42
+
43
+        [HttpPut()]
44
+        public IActionResult Put([FromBody] Individual individual)
45
+        {
46
+            if (individual != null)
47
+            {
48
+                using (var scope = new TransactionScope())
49
+                {
50
+                    _Repo.Update(individual);
51
+                    scope.Complete();
52
+                    return new OkResult();
53
+                }
54
+            }
55
+            return new NoContentResult();
56
+        }
57
+
58
+        [HttpDelete("{id}")]
59
+        public IActionResult Delete(int id)
60
+        {
61
+            _Repo.RemoveAtId(id);
62
+            return new OkResult();
63
+        }
64
+    }
65
+}

+ 208
- 0
UnivateProperties_API/Controllers/Users/RegisterController.cs Vedi File

@@ -0,0 +1,208 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.IdentityModel.Tokens.Jwt;
4
+using System.Linq;
5
+using System.Security.Claims;
6
+using System.Text;
7
+using System.Threading.Tasks;
8
+using AutoMapper;
9
+using Microsoft.AspNetCore.Authorization;
10
+using Microsoft.AspNetCore.Mvc;
11
+using Microsoft.Extensions.Options;
12
+using Microsoft.IdentityModel.Tokens;
13
+using UnivateProperties_API.Containers.Users;
14
+using UnivateProperties_API.Helpers;
15
+using UnivateProperties_API.Model.Users;
16
+using UnivateProperties_API.Repository;
17
+using UnivateProperties_API.Repository.Users;
18
+
19
+namespace UnivateProperties_API.Controllers.Users
20
+{
21
+    [Route("api/[controller]")]
22
+    [ApiController]
23
+    public class RegisterController : ControllerBase
24
+    {
25
+        private readonly IRegisterRepository _Repo;
26
+        private IMapper _mapper;
27
+        private readonly AppSettings _appSettings;
28
+
29
+        public RegisterController(IRegisterRepository repo, IMapper mapper, IOptions<AppSettings> appSettings)
30
+        {
31
+            _Repo = repo;
32
+            _mapper = mapper;
33
+            _appSettings = appSettings.Value;
34
+        }
35
+
36
+        [AllowAnonymous]
37
+        [HttpPost("authenticate")]
38
+        public IActionResult Authenticate([FromBody]UserDto userDto)
39
+        {
40
+            var user = _Repo.Authenticate(userDto.Username, userDto.Password);
41
+
42
+            if (user == null)
43
+                return BadRequest(new { message = "Username or password is incorrect" });
44
+
45
+            var tokenHandler = new JwtSecurityTokenHandler();
46
+            var key = Encoding.ASCII.GetBytes(_appSettings.Secret);
47
+            var tokenDescriptor = new SecurityTokenDescriptor
48
+            {
49
+                Subject = new ClaimsIdentity(new Claim[]
50
+                {
51
+                    new Claim(ClaimTypes.Name, user.Id.ToString()),
52
+                    new Claim(ClaimTypes.Role, user.Role)
53
+                }),
54
+                Expires = DateTime.UtcNow.AddMinutes(15),
55
+                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
56
+            };
57
+            var token = tokenHandler.CreateToken(tokenDescriptor);
58
+            var tokenString = tokenHandler.WriteToken(token);
59
+
60
+            // return basic user info (without password) and token to store client side
61
+            return Ok(new
62
+            {
63
+                user.Id,
64
+                user.Username,
65
+                user.Name,
66
+                user.Surname,
67
+                Token = tokenString
68
+            });
69
+        }
70
+
71
+        [AllowAnonymous]
72
+        [HttpPost("register")]
73
+        public IActionResult Register([FromBody]UserDto userDto)
74
+        {
75
+            // map dto to entity
76
+            var user = _mapper.Map<User>(userDto);
77
+
78
+            try
79
+            {
80
+                // save 
81
+                _Repo.Create(user, userDto.Password, true);
82
+                return Ok();
83
+            }
84
+            catch (AppException ex)
85
+            {
86
+                // return error message if there was an exception
87
+                return BadRequest(new { message = ex.Message });
88
+            }
89
+        }
90
+
91
+        [AllowAnonymous]
92
+        [HttpPost("registeragency")]
93
+        public IActionResult RegisterAgency([FromBody]AgencyDto agency)
94
+        {
95
+            // map dto to entity
96
+            _mapper.Map<Agency>(agency);
97
+
98
+            try
99
+            {
100
+                // save 
101
+                _Repo.CreateAgency(agency);
102
+                return Ok();
103
+            }
104
+            catch (AppException ex)
105
+            {
106
+                // return error message if there was an exception
107
+                return BadRequest(new { message = ex.Message });
108
+            }
109
+        }
110
+
111
+        [HttpPut("{id}")]
112
+        public IActionResult Update(int id, [FromBody]UserDto userDto)
113
+        {
114
+            // map dto to entity and set id
115
+            var user = _mapper.Map<User>(userDto);
116
+            user.Id = id;
117
+
118
+            try
119
+            {
120
+                // save 
121
+                _Repo.Update(user, userDto.Password);
122
+                return Ok();
123
+            }
124
+            catch (AppException ex)
125
+            {
126
+                // return error message if there was an exception
127
+                return BadRequest(new { message = ex.Message });
128
+            }
129
+        }
130
+
131
+        [HttpPut("{id}")]
132
+        public IActionResult UpdateAgency(int id, [FromBody]UserDto userDto)
133
+        {
134
+            // map dto to entity and set id
135
+            var agency = _mapper.Map<Agency>(userDto);
136
+            agency.Id = id;
137
+
138
+            try
139
+            {
140
+                // save 
141
+                _Repo.UpdateAgency(agency, userDto.Password);
142
+                return Ok();
143
+            }
144
+            catch (AppException ex)
145
+            {
146
+                // return error message if there was an exception
147
+                return BadRequest(new { message = ex.Message });
148
+            }
149
+        }
150
+
151
+        [HttpGet("{id}")]
152
+        public IActionResult GetById(int id)
153
+        {
154
+            var user = _Repo.GetById(id);
155
+            var userDto = _mapper.Map<UserDto>(user);
156
+
157
+            if (user == null)
158
+            {
159
+                return NotFound();
160
+            }
161
+
162
+            // Only allow SuperAdmins to access other user records
163
+            var currentUserId = int.Parse(User.Identity.Name);
164
+            if (id != currentUserId && !User.IsInRole(Role.SuperAdmin))
165
+            {
166
+                return Forbid();
167
+            }
168
+
169
+            return Ok(userDto);
170
+        }
171
+
172
+        [HttpGet("{id}")]
173
+        public IActionResult GetByAgencyId(int id)
174
+        {
175
+            var agency = _Repo.GetByAgencyId(id);
176
+            var agencyDto = _mapper.Map<AgencyDto>(agency);
177
+
178
+            if (agency == null)
179
+            {
180
+                return NotFound();
181
+            }
182
+
183
+            var currentAgencyId = int.Parse(User.Identity.Name);
184
+            if (id != currentAgencyId && !User.IsInRole(Role.Agency))
185
+            {
186
+                return Forbid();
187
+            }
188
+
189
+            return Ok(agencyDto);
190
+        }
191
+
192
+        [Authorize(Roles = Role.SuperAdmin)]
193
+        [HttpDelete("{id}")]
194
+        public IActionResult Delete(User user)
195
+        {
196
+            _Repo.Delete(user.Id);
197
+            return Ok();
198
+        }
199
+
200
+        [Authorize(Roles = Role.SuperAdmin)]
201
+        [HttpDelete("{id}")]
202
+        public IActionResult DeleteAgency(Agency agency)
203
+        {
204
+            _Repo.DeleteAgency(agency.Id);
205
+            return Ok();
206
+        }
207
+    }
208
+}

+ 67
- 0
UnivateProperties_API/Controllers/Users/UserController.cs Vedi File

@@ -0,0 +1,67 @@
1
+using System.Transactions;
2
+using Microsoft.AspNetCore.Authorization;
3
+using Microsoft.AspNetCore.Mvc;
4
+using UnivateProperties_API.Model.Users;
5
+using UnivateProperties_API.Repository;
6
+using UnivateProperties_API.Repository.Users;
7
+
8
+namespace User_API.Controllers
9
+{
10
+    [Authorize]
11
+    [Route("api/[controller]")]
12
+    [ApiController]
13
+    public class UserController : ControllerBase
14
+    {
15
+        private readonly IRepository<User> _Repo;
16
+
17
+        public UserController(IRepository<User> repo)
18
+        {
19
+            _Repo = repo;
20
+        }
21
+
22
+        [HttpGet]
23
+        public IActionResult Get()
24
+        {
25
+            return new OkObjectResult(_Repo.GetAll());
26
+        }
27
+
28
+        [HttpGet("{id}")]
29
+        public IActionResult Get(int id)
30
+        {
31
+            return new OkObjectResult(_Repo.Get(x => x.Id == id));
32
+        }
33
+
34
+        [HttpPost()]
35
+        public IActionResult Post([FromBody] User user)
36
+        {
37
+            using (var scope = new TransactionScope())
38
+            {
39
+                _Repo.Insert(user);
40
+                scope.Complete();
41
+                return CreatedAtAction(nameof(Get), new { id = user.Id }, user);
42
+            }
43
+        }
44
+
45
+        [HttpPut()]
46
+        public IActionResult Put([FromBody] User user)
47
+        {
48
+            if (user != null)
49
+            {
50
+                using (var scope = new TransactionScope())
51
+                {
52
+                    _Repo.Update(user);
53
+                    scope.Complete();
54
+                    return new OkResult();
55
+                }
56
+            }
57
+            return new NoContentResult();
58
+        }
59
+
60
+        [HttpDelete("{id}")]
61
+        public IActionResult Delete(int id)
62
+        {
63
+            _Repo.RemoveAtId(id);
64
+            return new OkResult();
65
+        }
66
+    }
67
+}

+ 21
- 0
UnivateProperties_API/Enums.cs Vedi File

@@ -0,0 +1,21 @@
1
+namespace UnivateProperties_API
2
+{
3
+    public enum PropertyUsageType
4
+    {
5
+        Residential,
6
+        Commercial,
7
+        Both
8
+    }
9
+
10
+    public enum ValidationResult
11
+    {
12
+        Success,
13
+        Failed
14
+    }
15
+
16
+    public enum PersonType
17
+    {
18
+        Individual,
19
+        Agent
20
+    }
21
+}

+ 24
- 0
UnivateProperties_API/Helpers/AppException.cs Vedi File

@@ -0,0 +1,24 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Globalization;
4
+using System.Linq;
5
+using System.Threading.Tasks;
6
+
7
+namespace UnivateProperties_API.Helpers
8
+{
9
+    public class AppException : Exception
10
+    {
11
+        public AppException() : base()
12
+        {
13
+        }
14
+
15
+        public AppException(string message) : base(message)
16
+        {
17
+        }
18
+
19
+        public AppException(string message, params object[] args)
20
+            : base(String.Format(CultureInfo.CurrentCulture, message, args))
21
+        {
22
+        }
23
+    }
24
+}

+ 17
- 0
UnivateProperties_API/Helpers/AutoMapperProfile.cs Vedi File

@@ -0,0 +1,17 @@
1
+using AutoMapper;
2
+using UnivateProperties_API.Containers.Users;
3
+using UnivateProperties_API.Model.Users;
4
+
5
+namespace UnivateProperties_API.Helpers
6
+{
7
+    public class AutoMapperProfile : Profile
8
+    {
9
+        public AutoMapperProfile()
10
+        {
11
+            CreateMap<User, UserDto>();
12
+            CreateMap<UserDto, User>();
13
+            CreateMap<Agency, AgencyDto>();
14
+            CreateMap<AgencyDto, Agency>();
15
+        }
16
+    }
17
+}

+ 18
- 0
UnivateProperties_API/Helpers/MyCommon.cs Vedi File

@@ -0,0 +1,18 @@
1
+using System.Text.RegularExpressions;
2
+
3
+namespace UnivateProperties_API.Helpers
4
+{
5
+    public static class MyCommon
6
+    {
7
+        public static bool IsValidEmail(string item)
8
+        {
9
+            if (!string.IsNullOrEmpty(item))
10
+            {
11
+                Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
12
+                Match match = regex.Match(item);
13
+                return match.Success;
14
+            }
15
+            else return false;
16
+        }
17
+    }
18
+}

+ 767
- 0
UnivateProperties_API/Migrations/20190828083244_1124.Designer.cs Vedi File

@@ -0,0 +1,767 @@
1
+// <auto-generated />
2
+using System;
3
+using Microsoft.EntityFrameworkCore;
4
+using Microsoft.EntityFrameworkCore.Infrastructure;
5
+using Microsoft.EntityFrameworkCore.Migrations;
6
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
8
+using UnivateProperties_API.Context;
9
+
10
+namespace UnivateProperties_API.Migrations
11
+{
12
+    [DbContext(typeof(DataContext))]
13
+    [Migration("20190828083244_1124")]
14
+    partial class _1124
15
+    {
16
+        protected override void BuildTargetModel(ModelBuilder modelBuilder)
17
+        {
18
+#pragma warning disable 612, 618
19
+            modelBuilder
20
+                .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
21
+                .HasAnnotation("ProductVersion", "2.2.4-servicing-10062")
22
+                .HasAnnotation("Relational:MaxIdentifierLength", 63);
23
+
24
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.Email", b =>
25
+                {
26
+                    b.Property<int>("Id")
27
+                        .ValueGeneratedOnAdd();
28
+
29
+                    b.Property<string>("BCC");
30
+
31
+                    b.Property<string>("Body");
32
+
33
+                    b.Property<string>("CC");
34
+
35
+                    b.Property<string>("Comment");
36
+
37
+                    b.Property<DateTime>("Created");
38
+
39
+                    b.Property<bool>("IsBodyHtml");
40
+
41
+                    b.Property<DateTime>("Modified");
42
+
43
+                    b.Property<string>("ModifiedBy");
44
+
45
+                    b.Property<int>("SenderId");
46
+
47
+                    b.Property<string>("Subject");
48
+
49
+                    b.Property<string>("To");
50
+
51
+                    b.Property<string>("ToDisplay");
52
+
53
+                    b.HasKey("Id");
54
+
55
+                    b.HasIndex("SenderId");
56
+
57
+                    b.ToTable("Emails");
58
+                });
59
+
60
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.SMTPAccount", b =>
61
+                {
62
+                    b.Property<int>("Id")
63
+                        .ValueGeneratedOnAdd();
64
+
65
+                    b.Property<string>("Address");
66
+
67
+                    b.Property<DateTime>("Created");
68
+
69
+                    b.Property<string>("DisplayName");
70
+
71
+                    b.Property<DateTime>("Modified");
72
+
73
+                    b.Property<string>("ModifiedBy");
74
+
75
+                    b.Property<int>("SMTPHostId");
76
+
77
+                    b.HasKey("Id");
78
+
79
+                    b.HasIndex("SMTPHostId");
80
+
81
+                    b.ToTable("Accounts");
82
+                });
83
+
84
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.SMTPHost", b =>
85
+                {
86
+                    b.Property<int>("Id")
87
+                        .ValueGeneratedOnAdd();
88
+
89
+                    b.Property<DateTime>("Created");
90
+
91
+                    b.Property<string>("Host");
92
+
93
+                    b.Property<DateTime>("Modified");
94
+
95
+                    b.Property<string>("ModifiedBy");
96
+
97
+                    b.Property<bool>("NeedsAuthorize");
98
+
99
+                    b.Property<string>("Password");
100
+
101
+                    b.Property<bool>("UseSSL");
102
+
103
+                    b.Property<string>("User");
104
+
105
+                    b.HasKey("Id");
106
+
107
+                    b.ToTable("Hosts");
108
+                });
109
+
110
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.Property", b =>
111
+                {
112
+                    b.Property<int>("Id")
113
+                        .ValueGeneratedOnAdd();
114
+
115
+                    b.Property<string>("AddressLine1");
116
+
117
+                    b.Property<string>("AddressLine2");
118
+
119
+                    b.Property<string>("AddressLine3");
120
+
121
+                    b.Property<int>("CityId");
122
+
123
+                    b.Property<DateTime>("Created");
124
+
125
+                    b.Property<string>("Description");
126
+
127
+                    b.Property<bool>("IsSale");
128
+
129
+                    b.Property<DateTime>("Modified");
130
+
131
+                    b.Property<string>("ModifiedBy");
132
+
133
+                    b.Property<decimal>("OperationalCosts");
134
+
135
+                    b.Property<decimal>("Price");
136
+
137
+                    b.Property<string>("PricePer");
138
+
139
+                    b.Property<string>("PropertyName");
140
+
141
+                    b.Property<int>("PropertyTypeId");
142
+
143
+                    b.Property<int>("ProvinceId");
144
+
145
+                    b.Property<string>("ShortDescription");
146
+
147
+                    b.Property<int>("SuburbId");
148
+
149
+                    b.Property<string>("Unit");
150
+
151
+                    b.HasKey("Id");
152
+
153
+                    b.HasIndex("CityId");
154
+
155
+                    b.HasIndex("PropertyTypeId");
156
+
157
+                    b.HasIndex("ProvinceId");
158
+
159
+                    b.HasIndex("SuburbId");
160
+
161
+                    b.ToTable("Properties");
162
+                });
163
+
164
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.PropertyImage", b =>
165
+                {
166
+                    b.Property<int>("Id")
167
+                        .ValueGeneratedOnAdd();
168
+
169
+                    b.Property<DateTime>("Created");
170
+
171
+                    b.Property<string>("Image");
172
+
173
+                    b.Property<bool>("IsDefault");
174
+
175
+                    b.Property<DateTime>("Modified");
176
+
177
+                    b.Property<string>("ModifiedBy");
178
+
179
+                    b.Property<int>("PropertyId");
180
+
181
+                    b.HasKey("Id");
182
+
183
+                    b.HasIndex("PropertyId");
184
+
185
+                    b.ToTable("PropertyImages");
186
+                });
187
+
188
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.PropertyType", b =>
189
+                {
190
+                    b.Property<int>("Id")
191
+                        .ValueGeneratedOnAdd();
192
+
193
+                    b.Property<DateTime>("Created");
194
+
195
+                    b.Property<string>("Description");
196
+
197
+                    b.Property<DateTime>("Modified");
198
+
199
+                    b.Property<string>("ModifiedBy");
200
+
201
+                    b.Property<int>("UsageType");
202
+
203
+                    b.HasKey("Id");
204
+
205
+                    b.ToTable("PropertyTypes");
206
+                });
207
+
208
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.PropertyUserField", b =>
209
+                {
210
+                    b.Property<int>("Id")
211
+                        .ValueGeneratedOnAdd();
212
+
213
+                    b.Property<DateTime>("Created");
214
+
215
+                    b.Property<string>("Description");
216
+
217
+                    b.Property<DateTime>("Modified");
218
+
219
+                    b.Property<string>("ModifiedBy");
220
+
221
+                    b.Property<int>("PropertyId");
222
+
223
+                    b.Property<int>("UserDefinedFieldId");
224
+
225
+                    b.Property<string>("Value");
226
+
227
+                    b.HasKey("Id");
228
+
229
+                    b.HasIndex("PropertyId");
230
+
231
+                    b.HasIndex("UserDefinedFieldId");
232
+
233
+                    b.ToTable("PropertyUserFields");
234
+                });
235
+
236
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.UserDefinedField", b =>
237
+                {
238
+                    b.Property<int>("Id")
239
+                        .ValueGeneratedOnAdd();
240
+
241
+                    b.Property<DateTime>("Created");
242
+
243
+                    b.Property<string>("FieldName");
244
+
245
+                    b.Property<string>("FieldType");
246
+
247
+                    b.Property<int>("GroupId");
248
+
249
+                    b.Property<DateTime>("Modified");
250
+
251
+                    b.Property<string>("ModifiedBy");
252
+
253
+                    b.Property<int>("Rank");
254
+
255
+                    b.HasKey("Id");
256
+
257
+                    b.HasIndex("GroupId");
258
+
259
+                    b.ToTable("UserDefinedFields");
260
+                });
261
+
262
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.UserDefinedGroup", b =>
263
+                {
264
+                    b.Property<int>("Id")
265
+                        .ValueGeneratedOnAdd();
266
+
267
+                    b.Property<DateTime>("Created");
268
+
269
+                    b.Property<string>("Description");
270
+
271
+                    b.Property<DateTime>("Modified");
272
+
273
+                    b.Property<string>("ModifiedBy");
274
+
275
+                    b.Property<int>("Rank");
276
+
277
+                    b.Property<int>("UsageType");
278
+
279
+                    b.HasKey("Id");
280
+
281
+                    b.ToTable("UserDefinedGroups");
282
+                });
283
+
284
+            modelBuilder.Entity("UnivateProperties_API.Model.Region.City", b =>
285
+                {
286
+                    b.Property<int>("Id")
287
+                        .ValueGeneratedOnAdd();
288
+
289
+                    b.Property<string>("Code");
290
+
291
+                    b.Property<DateTime>("Created");
292
+
293
+                    b.Property<string>("Description");
294
+
295
+                    b.Property<DateTime>("Modified");
296
+
297
+                    b.Property<string>("ModifiedBy");
298
+
299
+                    b.Property<int>("ProvinceId");
300
+
301
+                    b.HasKey("Id");
302
+
303
+                    b.HasIndex("ProvinceId");
304
+
305
+                    b.ToTable("Cities");
306
+                });
307
+
308
+            modelBuilder.Entity("UnivateProperties_API.Model.Region.Province", b =>
309
+                {
310
+                    b.Property<int>("Id")
311
+                        .ValueGeneratedOnAdd();
312
+
313
+                    b.Property<string>("Code");
314
+
315
+                    b.Property<DateTime>("Created");
316
+
317
+                    b.Property<string>("Description");
318
+
319
+                    b.Property<DateTime>("Modified");
320
+
321
+                    b.Property<string>("ModifiedBy");
322
+
323
+                    b.HasKey("Id");
324
+
325
+                    b.ToTable("Provinces");
326
+                });
327
+
328
+            modelBuilder.Entity("UnivateProperties_API.Model.Region.Suburb", b =>
329
+                {
330
+                    b.Property<int>("Id")
331
+                        .ValueGeneratedOnAdd();
332
+
333
+                    b.Property<int>("CityId");
334
+
335
+                    b.Property<DateTime>("Created");
336
+
337
+                    b.Property<string>("Description");
338
+
339
+                    b.Property<DateTime>("Modified");
340
+
341
+                    b.Property<string>("ModifiedBy");
342
+
343
+                    b.Property<string>("PostalCode");
344
+
345
+                    b.HasKey("Id");
346
+
347
+                    b.HasIndex("CityId");
348
+
349
+                    b.ToTable("Suburbs");
350
+                });
351
+
352
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.Season", b =>
353
+                {
354
+                    b.Property<int>("Id")
355
+                        .ValueGeneratedOnAdd();
356
+
357
+                    b.Property<DateTime>("Created");
358
+
359
+                    b.Property<DateTime>("Modified");
360
+
361
+                    b.Property<string>("ModifiedBy");
362
+
363
+                    b.Property<string>("Name");
364
+
365
+                    b.HasKey("Id");
366
+
367
+                    b.ToTable("Seasons");
368
+                });
369
+
370
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.Status", b =>
371
+                {
372
+                    b.Property<int>("Id")
373
+                        .ValueGeneratedOnAdd();
374
+
375
+                    b.Property<string>("Code");
376
+
377
+                    b.Property<DateTime>("Created");
378
+
379
+                    b.Property<string>("Description");
380
+
381
+                    b.Property<DateTime>("Modified");
382
+
383
+                    b.Property<string>("ModifiedBy");
384
+
385
+                    b.HasKey("Id");
386
+
387
+                    b.ToTable("Status");
388
+                });
389
+
390
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.TimeshareWeek", b =>
391
+                {
392
+                    b.Property<int>("Id")
393
+                        .ValueGeneratedOnAdd();
394
+
395
+                    b.Property<int>("AgencyId");
396
+
397
+                    b.Property<int>("AgentId");
398
+
399
+                    b.Property<DateTime>("ArrivalDate");
400
+
401
+                    b.Property<string>("BankedWith");
402
+
403
+                    b.Property<DateTime>("Created");
404
+
405
+                    b.Property<bool>("CurrentYearBanked");
406
+
407
+                    b.Property<DateTime>("DepartureDate");
408
+
409
+                    b.Property<bool>("LeviesPaidInFull");
410
+
411
+                    b.Property<double>("LevyAmount");
412
+
413
+                    b.Property<DateTime>("Modified");
414
+
415
+                    b.Property<string>("ModifiedBy");
416
+
417
+                    b.Property<string>("Module");
418
+
419
+                    b.Property<DateTime>("OriginalPurchaseDate");
420
+
421
+                    b.Property<double>("OriginalPurchasePrice");
422
+
423
+                    b.Property<bool>("OtherResort");
424
+
425
+                    b.Property<bool>("ReferedByAgent");
426
+
427
+                    b.Property<int>("RegionId");
428
+
429
+                    b.Property<string>("ResortCode");
430
+
431
+                    b.Property<string>("ResortName");
432
+
433
+                    b.Property<string>("Season");
434
+
435
+                    b.Property<int>("StatusId");
436
+
437
+                    b.Property<int>("UnitConfigurationId");
438
+
439
+                    b.Property<string>("WeekNumber");
440
+
441
+                    b.Property<bool>("WeekPlacedForRental");
442
+
443
+                    b.HasKey("Id");
444
+
445
+                    b.HasIndex("AgencyId");
446
+
447
+                    b.HasIndex("AgentId");
448
+
449
+                    b.HasIndex("RegionId");
450
+
451
+                    b.HasIndex("StatusId");
452
+
453
+                    b.HasIndex("UnitConfigurationId");
454
+
455
+                    b.ToTable("Weeks");
456
+                });
457
+
458
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.UnitConfiguration", b =>
459
+                {
460
+                    b.Property<int>("Id")
461
+                        .ValueGeneratedOnAdd();
462
+
463
+                    b.Property<int>("Adults");
464
+
465
+                    b.Property<int>("Bedrooms");
466
+
467
+                    b.Property<int>("Children");
468
+
469
+                    b.Property<string>("Code");
470
+
471
+                    b.Property<DateTime>("Created");
472
+
473
+                    b.Property<DateTime>("Modified");
474
+
475
+                    b.Property<string>("ModifiedBy");
476
+
477
+                    b.HasKey("Id");
478
+
479
+                    b.HasIndex("Code")
480
+                        .IsUnique();
481
+
482
+                    b.ToTable("UnitConfigurations");
483
+                });
484
+
485
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.UnitConfigurationType", b =>
486
+                {
487
+                    b.Property<int>("Id")
488
+                        .ValueGeneratedOnAdd();
489
+
490
+                    b.Property<DateTime>("Created");
491
+
492
+                    b.Property<string>("Description");
493
+
494
+                    b.Property<DateTime>("Modified");
495
+
496
+                    b.Property<string>("ModifiedBy");
497
+
498
+                    b.Property<int>("UnitConfigurationId");
499
+
500
+                    b.HasKey("Id");
501
+
502
+                    b.HasIndex("UnitConfigurationId");
503
+
504
+                    b.ToTable("UnitConfigurationTypes");
505
+                });
506
+
507
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.Agency", b =>
508
+                {
509
+                    b.Property<int>("Id")
510
+                        .ValueGeneratedOnAdd();
511
+
512
+                    b.Property<string>("AgencyName");
513
+
514
+                    b.Property<string>("CompanyRegNumber");
515
+
516
+                    b.Property<DateTime>("Created");
517
+
518
+                    b.Property<string>("EAABEFFCNumber");
519
+
520
+                    b.Property<DateTime>("Modified");
521
+
522
+                    b.Property<string>("ModifiedBy");
523
+
524
+                    b.HasKey("Id");
525
+
526
+                    b.ToTable("Agencies");
527
+                });
528
+
529
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.Agent", b =>
530
+                {
531
+                    b.Property<int>("Id")
532
+                        .ValueGeneratedOnAdd();
533
+
534
+                    b.Property<int?>("AgencyId");
535
+
536
+                    b.Property<string>("CellNumber");
537
+
538
+                    b.Property<DateTime>("Created");
539
+
540
+                    b.Property<string>("Email");
541
+
542
+                    b.Property<DateTime>("Modified");
543
+
544
+                    b.Property<string>("ModifiedBy");
545
+
546
+                    b.Property<string>("Name");
547
+
548
+                    b.Property<string>("Surname");
549
+
550
+                    b.Property<string>("Telephone");
551
+
552
+                    b.Property<int>("UserId");
553
+
554
+                    b.HasKey("Id");
555
+
556
+                    b.HasIndex("AgencyId");
557
+
558
+                    b.HasIndex("UserId");
559
+
560
+                    b.ToTable("Agents");
561
+                });
562
+
563
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.Individual", b =>
564
+                {
565
+                    b.Property<int>("Id")
566
+                        .ValueGeneratedOnAdd();
567
+
568
+                    b.Property<string>("CellNumber");
569
+
570
+                    b.Property<DateTime>("Created");
571
+
572
+                    b.Property<string>("Email");
573
+
574
+                    b.Property<DateTime>("Modified");
575
+
576
+                    b.Property<string>("ModifiedBy");
577
+
578
+                    b.Property<string>("Name");
579
+
580
+                    b.Property<string>("Surname");
581
+
582
+                    b.Property<string>("Telephone");
583
+
584
+                    b.Property<int>("UserId");
585
+
586
+                    b.HasKey("Id");
587
+
588
+                    b.HasIndex("UserId");
589
+
590
+                    b.ToTable("Individuals");
591
+                });
592
+
593
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.User", b =>
594
+                {
595
+                    b.Property<int>("Id")
596
+                        .ValueGeneratedOnAdd();
597
+
598
+                    b.Property<DateTime>("Created");
599
+
600
+                    b.Property<DateTime>("Modified");
601
+
602
+                    b.Property<string>("ModifiedBy");
603
+
604
+                    b.Property<string>("Name");
605
+
606
+                    b.Property<byte[]>("PasswordHash");
607
+
608
+                    b.Property<byte[]>("PasswordSalt");
609
+
610
+                    b.Property<string>("Role");
611
+
612
+                    b.Property<string>("Surname");
613
+
614
+                    b.Property<string>("Token");
615
+
616
+                    b.Property<string>("Username");
617
+
618
+                    b.Property<bool>("Verified");
619
+
620
+                    b.HasKey("Id");
621
+
622
+                    b.ToTable("Users");
623
+                });
624
+
625
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.Email", b =>
626
+                {
627
+                    b.HasOne("UnivateProperties_API.Model.Communication.SMTPAccount", "Sender")
628
+                        .WithMany("Emails")
629
+                        .HasForeignKey("SenderId")
630
+                        .OnDelete(DeleteBehavior.Cascade);
631
+                });
632
+
633
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.SMTPAccount", b =>
634
+                {
635
+                    b.HasOne("UnivateProperties_API.Model.Communication.SMTPHost", "SMTPHost")
636
+                        .WithMany("SMTPAccounts")
637
+                        .HasForeignKey("SMTPHostId")
638
+                        .OnDelete(DeleteBehavior.Cascade);
639
+                });
640
+
641
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.Property", b =>
642
+                {
643
+                    b.HasOne("UnivateProperties_API.Model.Region.City", "City")
644
+                        .WithMany()
645
+                        .HasForeignKey("CityId")
646
+                        .OnDelete(DeleteBehavior.Cascade);
647
+
648
+                    b.HasOne("UnivateProperties_API.Model.Property.PropertyType", "PropertyType")
649
+                        .WithMany()
650
+                        .HasForeignKey("PropertyTypeId")
651
+                        .OnDelete(DeleteBehavior.Cascade);
652
+
653
+                    b.HasOne("UnivateProperties_API.Model.Region.Province", "Province")
654
+                        .WithMany()
655
+                        .HasForeignKey("ProvinceId")
656
+                        .OnDelete(DeleteBehavior.Cascade);
657
+
658
+                    b.HasOne("UnivateProperties_API.Model.Region.Suburb", "Suburb")
659
+                        .WithMany()
660
+                        .HasForeignKey("SuburbId")
661
+                        .OnDelete(DeleteBehavior.Cascade);
662
+                });
663
+
664
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.PropertyImage", b =>
665
+                {
666
+                    b.HasOne("UnivateProperties_API.Model.Property.Property", "Property")
667
+                        .WithMany("PropertyImages")
668
+                        .HasForeignKey("PropertyId")
669
+                        .OnDelete(DeleteBehavior.Cascade);
670
+                });
671
+
672
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.PropertyUserField", b =>
673
+                {
674
+                    b.HasOne("UnivateProperties_API.Model.Property.Property", "Property")
675
+                        .WithMany("PropertyUserFields")
676
+                        .HasForeignKey("PropertyId")
677
+                        .OnDelete(DeleteBehavior.Cascade);
678
+
679
+                    b.HasOne("UnivateProperties_API.Model.Property.UserDefinedField", "UserDefinedField")
680
+                        .WithMany()
681
+                        .HasForeignKey("UserDefinedFieldId")
682
+                        .OnDelete(DeleteBehavior.Cascade);
683
+                });
684
+
685
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.UserDefinedField", b =>
686
+                {
687
+                    b.HasOne("UnivateProperties_API.Model.Property.UserDefinedGroup", "Group")
688
+                        .WithMany("Fields")
689
+                        .HasForeignKey("GroupId")
690
+                        .OnDelete(DeleteBehavior.Cascade);
691
+                });
692
+
693
+            modelBuilder.Entity("UnivateProperties_API.Model.Region.City", b =>
694
+                {
695
+                    b.HasOne("UnivateProperties_API.Model.Region.Province", "Province")
696
+                        .WithMany()
697
+                        .HasForeignKey("ProvinceId")
698
+                        .OnDelete(DeleteBehavior.Cascade);
699
+                });
700
+
701
+            modelBuilder.Entity("UnivateProperties_API.Model.Region.Suburb", b =>
702
+                {
703
+                    b.HasOne("UnivateProperties_API.Model.Region.City", "City")
704
+                        .WithMany()
705
+                        .HasForeignKey("CityId")
706
+                        .OnDelete(DeleteBehavior.Cascade);
707
+                });
708
+
709
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.TimeshareWeek", b =>
710
+                {
711
+                    b.HasOne("UnivateProperties_API.Model.Users.Agency", "Agency")
712
+                        .WithMany()
713
+                        .HasForeignKey("AgencyId")
714
+                        .OnDelete(DeleteBehavior.Cascade);
715
+
716
+                    b.HasOne("UnivateProperties_API.Model.Users.Agent", "Agent")
717
+                        .WithMany()
718
+                        .HasForeignKey("AgentId")
719
+                        .OnDelete(DeleteBehavior.Cascade);
720
+
721
+                    b.HasOne("UnivateProperties_API.Model.Region.Province", "Region")
722
+                        .WithMany()
723
+                        .HasForeignKey("RegionId")
724
+                        .OnDelete(DeleteBehavior.Cascade);
725
+
726
+                    b.HasOne("UnivateProperties_API.Model.Timeshare.Status", "Status")
727
+                        .WithMany()
728
+                        .HasForeignKey("StatusId")
729
+                        .OnDelete(DeleteBehavior.Cascade);
730
+
731
+                    b.HasOne("UnivateProperties_API.Model.Timeshare.UnitConfiguration", "UnitConfiguration")
732
+                        .WithMany()
733
+                        .HasForeignKey("UnitConfigurationId")
734
+                        .OnDelete(DeleteBehavior.Cascade);
735
+                });
736
+
737
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.UnitConfigurationType", b =>
738
+                {
739
+                    b.HasOne("UnivateProperties_API.Model.Timeshare.UnitConfiguration", "UnitConfiguration")
740
+                        .WithMany("Types")
741
+                        .HasForeignKey("UnitConfigurationId")
742
+                        .OnDelete(DeleteBehavior.Cascade);
743
+                });
744
+
745
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.Agent", b =>
746
+                {
747
+                    b.HasOne("UnivateProperties_API.Model.Users.Agency", "Agency")
748
+                        .WithMany("Agents")
749
+                        .HasForeignKey("AgencyId");
750
+
751
+                    b.HasOne("UnivateProperties_API.Model.Users.User", "User")
752
+                        .WithMany()
753
+                        .HasForeignKey("UserId")
754
+                        .OnDelete(DeleteBehavior.Cascade);
755
+                });
756
+
757
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.Individual", b =>
758
+                {
759
+                    b.HasOne("UnivateProperties_API.Model.Users.User", "User")
760
+                        .WithMany()
761
+                        .HasForeignKey("UserId")
762
+                        .OnDelete(DeleteBehavior.Cascade);
763
+                });
764
+#pragma warning restore 612, 618
765
+        }
766
+    }
767
+}

+ 740
- 0
UnivateProperties_API/Migrations/20190828083244_1124.cs Vedi File

@@ -0,0 +1,740 @@
1
+using System;
2
+using Microsoft.EntityFrameworkCore.Migrations;
3
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
4
+
5
+namespace UnivateProperties_API.Migrations
6
+{
7
+    public partial class _1124 : Migration
8
+    {
9
+        protected override void Up(MigrationBuilder migrationBuilder)
10
+        {
11
+            migrationBuilder.CreateTable(
12
+                name: "Agencies",
13
+                columns: table => new
14
+                {
15
+                    Id = table.Column<int>(nullable: false)
16
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
17
+                    Created = table.Column<DateTime>(nullable: false),
18
+                    Modified = table.Column<DateTime>(nullable: false),
19
+                    ModifiedBy = table.Column<string>(nullable: true),
20
+                    AgencyName = table.Column<string>(nullable: true),
21
+                    EAABEFFCNumber = table.Column<string>(nullable: true),
22
+                    CompanyRegNumber = table.Column<string>(nullable: true)
23
+                },
24
+                constraints: table =>
25
+                {
26
+                    table.PrimaryKey("PK_Agencies", x => x.Id);
27
+                });
28
+
29
+            migrationBuilder.CreateTable(
30
+                name: "Hosts",
31
+                columns: table => new
32
+                {
33
+                    Id = table.Column<int>(nullable: false)
34
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
35
+                    Created = table.Column<DateTime>(nullable: false),
36
+                    Modified = table.Column<DateTime>(nullable: false),
37
+                    ModifiedBy = table.Column<string>(nullable: true),
38
+                    Host = table.Column<string>(nullable: true),
39
+                    NeedsAuthorize = table.Column<bool>(nullable: false),
40
+                    User = table.Column<string>(nullable: true),
41
+                    Password = table.Column<string>(nullable: true),
42
+                    UseSSL = table.Column<bool>(nullable: false)
43
+                },
44
+                constraints: table =>
45
+                {
46
+                    table.PrimaryKey("PK_Hosts", x => x.Id);
47
+                });
48
+
49
+            migrationBuilder.CreateTable(
50
+                name: "PropertyTypes",
51
+                columns: table => new
52
+                {
53
+                    Id = table.Column<int>(nullable: false)
54
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
55
+                    Created = table.Column<DateTime>(nullable: false),
56
+                    Modified = table.Column<DateTime>(nullable: false),
57
+                    ModifiedBy = table.Column<string>(nullable: true),
58
+                    Description = table.Column<string>(nullable: true),
59
+                    UsageType = table.Column<int>(nullable: false)
60
+                },
61
+                constraints: table =>
62
+                {
63
+                    table.PrimaryKey("PK_PropertyTypes", x => x.Id);
64
+                });
65
+
66
+            migrationBuilder.CreateTable(
67
+                name: "Provinces",
68
+                columns: table => new
69
+                {
70
+                    Id = table.Column<int>(nullable: false)
71
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
72
+                    Created = table.Column<DateTime>(nullable: false),
73
+                    Modified = table.Column<DateTime>(nullable: false),
74
+                    ModifiedBy = table.Column<string>(nullable: true),
75
+                    Description = table.Column<string>(nullable: true),
76
+                    Code = table.Column<string>(nullable: true)
77
+                },
78
+                constraints: table =>
79
+                {
80
+                    table.PrimaryKey("PK_Provinces", x => x.Id);
81
+                });
82
+
83
+            migrationBuilder.CreateTable(
84
+                name: "Seasons",
85
+                columns: table => new
86
+                {
87
+                    Id = table.Column<int>(nullable: false)
88
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
89
+                    Created = table.Column<DateTime>(nullable: false),
90
+                    Modified = table.Column<DateTime>(nullable: false),
91
+                    ModifiedBy = table.Column<string>(nullable: true),
92
+                    Name = table.Column<string>(nullable: true)
93
+                },
94
+                constraints: table =>
95
+                {
96
+                    table.PrimaryKey("PK_Seasons", x => x.Id);
97
+                });
98
+
99
+            migrationBuilder.CreateTable(
100
+                name: "Status",
101
+                columns: table => new
102
+                {
103
+                    Id = table.Column<int>(nullable: false)
104
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
105
+                    Created = table.Column<DateTime>(nullable: false),
106
+                    Modified = table.Column<DateTime>(nullable: false),
107
+                    ModifiedBy = table.Column<string>(nullable: true),
108
+                    Code = table.Column<string>(nullable: true),
109
+                    Description = table.Column<string>(nullable: true)
110
+                },
111
+                constraints: table =>
112
+                {
113
+                    table.PrimaryKey("PK_Status", x => x.Id);
114
+                });
115
+
116
+            migrationBuilder.CreateTable(
117
+                name: "UnitConfigurations",
118
+                columns: table => new
119
+                {
120
+                    Id = table.Column<int>(nullable: false)
121
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
122
+                    Created = table.Column<DateTime>(nullable: false),
123
+                    Modified = table.Column<DateTime>(nullable: false),
124
+                    ModifiedBy = table.Column<string>(nullable: true),
125
+                    Code = table.Column<string>(nullable: true),
126
+                    Bedrooms = table.Column<int>(nullable: false),
127
+                    Adults = table.Column<int>(nullable: false),
128
+                    Children = table.Column<int>(nullable: false)
129
+                },
130
+                constraints: table =>
131
+                {
132
+                    table.PrimaryKey("PK_UnitConfigurations", x => x.Id);
133
+                });
134
+
135
+            migrationBuilder.CreateTable(
136
+                name: "UserDefinedGroups",
137
+                columns: table => new
138
+                {
139
+                    Id = table.Column<int>(nullable: false)
140
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
141
+                    Created = table.Column<DateTime>(nullable: false),
142
+                    Modified = table.Column<DateTime>(nullable: false),
143
+                    ModifiedBy = table.Column<string>(nullable: true),
144
+                    Description = table.Column<string>(nullable: true),
145
+                    UsageType = table.Column<int>(nullable: false),
146
+                    Rank = table.Column<int>(nullable: false)
147
+                },
148
+                constraints: table =>
149
+                {
150
+                    table.PrimaryKey("PK_UserDefinedGroups", x => x.Id);
151
+                });
152
+
153
+            migrationBuilder.CreateTable(
154
+                name: "Users",
155
+                columns: table => new
156
+                {
157
+                    Id = table.Column<int>(nullable: false)
158
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
159
+                    Created = table.Column<DateTime>(nullable: false),
160
+                    Modified = table.Column<DateTime>(nullable: false),
161
+                    ModifiedBy = table.Column<string>(nullable: true),
162
+                    Name = table.Column<string>(nullable: true),
163
+                    Surname = table.Column<string>(nullable: true),
164
+                    Username = table.Column<string>(nullable: true),
165
+                    Role = table.Column<string>(nullable: true),
166
+                    PasswordHash = table.Column<byte[]>(nullable: true),
167
+                    PasswordSalt = table.Column<byte[]>(nullable: true),
168
+                    Verified = table.Column<bool>(nullable: false),
169
+                    Token = table.Column<string>(nullable: true)
170
+                },
171
+                constraints: table =>
172
+                {
173
+                    table.PrimaryKey("PK_Users", x => x.Id);
174
+                });
175
+
176
+            migrationBuilder.CreateTable(
177
+                name: "Accounts",
178
+                columns: table => new
179
+                {
180
+                    Id = table.Column<int>(nullable: false)
181
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
182
+                    Created = table.Column<DateTime>(nullable: false),
183
+                    Modified = table.Column<DateTime>(nullable: false),
184
+                    ModifiedBy = table.Column<string>(nullable: true),
185
+                    Address = table.Column<string>(nullable: true),
186
+                    DisplayName = table.Column<string>(nullable: true),
187
+                    SMTPHostId = table.Column<int>(nullable: false)
188
+                },
189
+                constraints: table =>
190
+                {
191
+                    table.PrimaryKey("PK_Accounts", x => x.Id);
192
+                    table.ForeignKey(
193
+                        name: "FK_Accounts_Hosts_SMTPHostId",
194
+                        column: x => x.SMTPHostId,
195
+                        principalTable: "Hosts",
196
+                        principalColumn: "Id",
197
+                        onDelete: ReferentialAction.Cascade);
198
+                });
199
+
200
+            migrationBuilder.CreateTable(
201
+                name: "Cities",
202
+                columns: table => new
203
+                {
204
+                    Id = table.Column<int>(nullable: false)
205
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
206
+                    Created = table.Column<DateTime>(nullable: false),
207
+                    Modified = table.Column<DateTime>(nullable: false),
208
+                    ModifiedBy = table.Column<string>(nullable: true),
209
+                    ProvinceId = table.Column<int>(nullable: false),
210
+                    Description = table.Column<string>(nullable: true),
211
+                    Code = table.Column<string>(nullable: true)
212
+                },
213
+                constraints: table =>
214
+                {
215
+                    table.PrimaryKey("PK_Cities", x => x.Id);
216
+                    table.ForeignKey(
217
+                        name: "FK_Cities_Provinces_ProvinceId",
218
+                        column: x => x.ProvinceId,
219
+                        principalTable: "Provinces",
220
+                        principalColumn: "Id",
221
+                        onDelete: ReferentialAction.Cascade);
222
+                });
223
+
224
+            migrationBuilder.CreateTable(
225
+                name: "UnitConfigurationTypes",
226
+                columns: table => new
227
+                {
228
+                    Id = table.Column<int>(nullable: false)
229
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
230
+                    Created = table.Column<DateTime>(nullable: false),
231
+                    Modified = table.Column<DateTime>(nullable: false),
232
+                    ModifiedBy = table.Column<string>(nullable: true),
233
+                    Description = table.Column<string>(nullable: true),
234
+                    UnitConfigurationId = table.Column<int>(nullable: false)
235
+                },
236
+                constraints: table =>
237
+                {
238
+                    table.PrimaryKey("PK_UnitConfigurationTypes", x => x.Id);
239
+                    table.ForeignKey(
240
+                        name: "FK_UnitConfigurationTypes_UnitConfigurations_UnitConfiguration~",
241
+                        column: x => x.UnitConfigurationId,
242
+                        principalTable: "UnitConfigurations",
243
+                        principalColumn: "Id",
244
+                        onDelete: ReferentialAction.Cascade);
245
+                });
246
+
247
+            migrationBuilder.CreateTable(
248
+                name: "UserDefinedFields",
249
+                columns: table => new
250
+                {
251
+                    Id = table.Column<int>(nullable: false)
252
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
253
+                    Created = table.Column<DateTime>(nullable: false),
254
+                    Modified = table.Column<DateTime>(nullable: false),
255
+                    ModifiedBy = table.Column<string>(nullable: true),
256
+                    GroupId = table.Column<int>(nullable: false),
257
+                    FieldName = table.Column<string>(nullable: true),
258
+                    FieldType = table.Column<string>(nullable: true),
259
+                    Rank = table.Column<int>(nullable: false)
260
+                },
261
+                constraints: table =>
262
+                {
263
+                    table.PrimaryKey("PK_UserDefinedFields", x => x.Id);
264
+                    table.ForeignKey(
265
+                        name: "FK_UserDefinedFields_UserDefinedGroups_GroupId",
266
+                        column: x => x.GroupId,
267
+                        principalTable: "UserDefinedGroups",
268
+                        principalColumn: "Id",
269
+                        onDelete: ReferentialAction.Cascade);
270
+                });
271
+
272
+            migrationBuilder.CreateTable(
273
+                name: "Agents",
274
+                columns: table => new
275
+                {
276
+                    Id = table.Column<int>(nullable: false)
277
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
278
+                    Created = table.Column<DateTime>(nullable: false),
279
+                    Modified = table.Column<DateTime>(nullable: false),
280
+                    ModifiedBy = table.Column<string>(nullable: true),
281
+                    UserId = table.Column<int>(nullable: false),
282
+                    Name = table.Column<string>(nullable: true),
283
+                    Surname = table.Column<string>(nullable: true),
284
+                    Email = table.Column<string>(nullable: true),
285
+                    Telephone = table.Column<string>(nullable: true),
286
+                    CellNumber = table.Column<string>(nullable: true),
287
+                    AgencyId = table.Column<int>(nullable: true)
288
+                },
289
+                constraints: table =>
290
+                {
291
+                    table.PrimaryKey("PK_Agents", x => x.Id);
292
+                    table.ForeignKey(
293
+                        name: "FK_Agents_Agencies_AgencyId",
294
+                        column: x => x.AgencyId,
295
+                        principalTable: "Agencies",
296
+                        principalColumn: "Id",
297
+                        onDelete: ReferentialAction.Restrict);
298
+                    table.ForeignKey(
299
+                        name: "FK_Agents_Users_UserId",
300
+                        column: x => x.UserId,
301
+                        principalTable: "Users",
302
+                        principalColumn: "Id",
303
+                        onDelete: ReferentialAction.Cascade);
304
+                });
305
+
306
+            migrationBuilder.CreateTable(
307
+                name: "Individuals",
308
+                columns: table => new
309
+                {
310
+                    Id = table.Column<int>(nullable: false)
311
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
312
+                    Created = table.Column<DateTime>(nullable: false),
313
+                    Modified = table.Column<DateTime>(nullable: false),
314
+                    ModifiedBy = table.Column<string>(nullable: true),
315
+                    UserId = table.Column<int>(nullable: false),
316
+                    Name = table.Column<string>(nullable: true),
317
+                    Surname = table.Column<string>(nullable: true),
318
+                    Email = table.Column<string>(nullable: true),
319
+                    Telephone = table.Column<string>(nullable: true),
320
+                    CellNumber = table.Column<string>(nullable: true)
321
+                },
322
+                constraints: table =>
323
+                {
324
+                    table.PrimaryKey("PK_Individuals", x => x.Id);
325
+                    table.ForeignKey(
326
+                        name: "FK_Individuals_Users_UserId",
327
+                        column: x => x.UserId,
328
+                        principalTable: "Users",
329
+                        principalColumn: "Id",
330
+                        onDelete: ReferentialAction.Cascade);
331
+                });
332
+
333
+            migrationBuilder.CreateTable(
334
+                name: "Emails",
335
+                columns: table => new
336
+                {
337
+                    Id = table.Column<int>(nullable: false)
338
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
339
+                    Created = table.Column<DateTime>(nullable: false),
340
+                    Modified = table.Column<DateTime>(nullable: false),
341
+                    ModifiedBy = table.Column<string>(nullable: true),
342
+                    SenderId = table.Column<int>(nullable: false),
343
+                    Comment = table.Column<string>(nullable: true),
344
+                    Subject = table.Column<string>(nullable: true),
345
+                    IsBodyHtml = table.Column<bool>(nullable: false),
346
+                    CC = table.Column<string>(nullable: true),
347
+                    BCC = table.Column<string>(nullable: true),
348
+                    Body = table.Column<string>(nullable: true),
349
+                    To = table.Column<string>(nullable: true),
350
+                    ToDisplay = table.Column<string>(nullable: true)
351
+                },
352
+                constraints: table =>
353
+                {
354
+                    table.PrimaryKey("PK_Emails", x => x.Id);
355
+                    table.ForeignKey(
356
+                        name: "FK_Emails_Accounts_SenderId",
357
+                        column: x => x.SenderId,
358
+                        principalTable: "Accounts",
359
+                        principalColumn: "Id",
360
+                        onDelete: ReferentialAction.Cascade);
361
+                });
362
+
363
+            migrationBuilder.CreateTable(
364
+                name: "Suburbs",
365
+                columns: table => new
366
+                {
367
+                    Id = table.Column<int>(nullable: false)
368
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
369
+                    Created = table.Column<DateTime>(nullable: false),
370
+                    Modified = table.Column<DateTime>(nullable: false),
371
+                    ModifiedBy = table.Column<string>(nullable: true),
372
+                    CityId = table.Column<int>(nullable: false),
373
+                    Description = table.Column<string>(nullable: true),
374
+                    PostalCode = table.Column<string>(nullable: true)
375
+                },
376
+                constraints: table =>
377
+                {
378
+                    table.PrimaryKey("PK_Suburbs", x => x.Id);
379
+                    table.ForeignKey(
380
+                        name: "FK_Suburbs_Cities_CityId",
381
+                        column: x => x.CityId,
382
+                        principalTable: "Cities",
383
+                        principalColumn: "Id",
384
+                        onDelete: ReferentialAction.Cascade);
385
+                });
386
+
387
+            migrationBuilder.CreateTable(
388
+                name: "Weeks",
389
+                columns: table => new
390
+                {
391
+                    Id = table.Column<int>(nullable: false)
392
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
393
+                    Created = table.Column<DateTime>(nullable: false),
394
+                    Modified = table.Column<DateTime>(nullable: false),
395
+                    ModifiedBy = table.Column<string>(nullable: true),
396
+                    ReferedByAgent = table.Column<bool>(nullable: false),
397
+                    AgentId = table.Column<int>(nullable: false),
398
+                    AgencyId = table.Column<int>(nullable: false),
399
+                    UnitConfigurationId = table.Column<int>(nullable: false),
400
+                    OtherResort = table.Column<bool>(nullable: false),
401
+                    ResortCode = table.Column<string>(nullable: true),
402
+                    ResortName = table.Column<string>(nullable: true),
403
+                    RegionId = table.Column<int>(nullable: false),
404
+                    Season = table.Column<string>(nullable: true),
405
+                    Module = table.Column<string>(nullable: true),
406
+                    WeekNumber = table.Column<string>(nullable: true),
407
+                    LevyAmount = table.Column<double>(nullable: false),
408
+                    CurrentYearBanked = table.Column<bool>(nullable: false),
409
+                    BankedWith = table.Column<string>(nullable: true),
410
+                    LeviesPaidInFull = table.Column<bool>(nullable: false),
411
+                    WeekPlacedForRental = table.Column<bool>(nullable: false),
412
+                    OriginalPurchasePrice = table.Column<double>(nullable: false),
413
+                    OriginalPurchaseDate = table.Column<DateTime>(nullable: false),
414
+                    ArrivalDate = table.Column<DateTime>(nullable: false),
415
+                    DepartureDate = table.Column<DateTime>(nullable: false),
416
+                    StatusId = table.Column<int>(nullable: false)
417
+                },
418
+                constraints: table =>
419
+                {
420
+                    table.PrimaryKey("PK_Weeks", x => x.Id);
421
+                    table.ForeignKey(
422
+                        name: "FK_Weeks_Agencies_AgencyId",
423
+                        column: x => x.AgencyId,
424
+                        principalTable: "Agencies",
425
+                        principalColumn: "Id",
426
+                        onDelete: ReferentialAction.Cascade);
427
+                    table.ForeignKey(
428
+                        name: "FK_Weeks_Agents_AgentId",
429
+                        column: x => x.AgentId,
430
+                        principalTable: "Agents",
431
+                        principalColumn: "Id",
432
+                        onDelete: ReferentialAction.Cascade);
433
+                    table.ForeignKey(
434
+                        name: "FK_Weeks_Provinces_RegionId",
435
+                        column: x => x.RegionId,
436
+                        principalTable: "Provinces",
437
+                        principalColumn: "Id",
438
+                        onDelete: ReferentialAction.Cascade);
439
+                    table.ForeignKey(
440
+                        name: "FK_Weeks_Status_StatusId",
441
+                        column: x => x.StatusId,
442
+                        principalTable: "Status",
443
+                        principalColumn: "Id",
444
+                        onDelete: ReferentialAction.Cascade);
445
+                    table.ForeignKey(
446
+                        name: "FK_Weeks_UnitConfigurations_UnitConfigurationId",
447
+                        column: x => x.UnitConfigurationId,
448
+                        principalTable: "UnitConfigurations",
449
+                        principalColumn: "Id",
450
+                        onDelete: ReferentialAction.Cascade);
451
+                });
452
+
453
+            migrationBuilder.CreateTable(
454
+                name: "Properties",
455
+                columns: table => new
456
+                {
457
+                    Id = table.Column<int>(nullable: false)
458
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
459
+                    Created = table.Column<DateTime>(nullable: false),
460
+                    Modified = table.Column<DateTime>(nullable: false),
461
+                    ModifiedBy = table.Column<string>(nullable: true),
462
+                    PropertyTypeId = table.Column<int>(nullable: false),
463
+                    PropertyName = table.Column<string>(nullable: true),
464
+                    Unit = table.Column<string>(nullable: true),
465
+                    OperationalCosts = table.Column<decimal>(nullable: false),
466
+                    Price = table.Column<decimal>(nullable: false),
467
+                    PricePer = table.Column<string>(nullable: true),
468
+                    IsSale = table.Column<bool>(nullable: false),
469
+                    Description = table.Column<string>(nullable: true),
470
+                    ShortDescription = table.Column<string>(nullable: true),
471
+                    AddressLine1 = table.Column<string>(nullable: true),
472
+                    AddressLine2 = table.Column<string>(nullable: true),
473
+                    AddressLine3 = table.Column<string>(nullable: true),
474
+                    SuburbId = table.Column<int>(nullable: false),
475
+                    CityId = table.Column<int>(nullable: false),
476
+                    ProvinceId = table.Column<int>(nullable: false)
477
+                },
478
+                constraints: table =>
479
+                {
480
+                    table.PrimaryKey("PK_Properties", x => x.Id);
481
+                    table.ForeignKey(
482
+                        name: "FK_Properties_Cities_CityId",
483
+                        column: x => x.CityId,
484
+                        principalTable: "Cities",
485
+                        principalColumn: "Id",
486
+                        onDelete: ReferentialAction.Cascade);
487
+                    table.ForeignKey(
488
+                        name: "FK_Properties_PropertyTypes_PropertyTypeId",
489
+                        column: x => x.PropertyTypeId,
490
+                        principalTable: "PropertyTypes",
491
+                        principalColumn: "Id",
492
+                        onDelete: ReferentialAction.Cascade);
493
+                    table.ForeignKey(
494
+                        name: "FK_Properties_Provinces_ProvinceId",
495
+                        column: x => x.ProvinceId,
496
+                        principalTable: "Provinces",
497
+                        principalColumn: "Id",
498
+                        onDelete: ReferentialAction.Cascade);
499
+                    table.ForeignKey(
500
+                        name: "FK_Properties_Suburbs_SuburbId",
501
+                        column: x => x.SuburbId,
502
+                        principalTable: "Suburbs",
503
+                        principalColumn: "Id",
504
+                        onDelete: ReferentialAction.Cascade);
505
+                });
506
+
507
+            migrationBuilder.CreateTable(
508
+                name: "PropertyImages",
509
+                columns: table => new
510
+                {
511
+                    Id = table.Column<int>(nullable: false)
512
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
513
+                    Created = table.Column<DateTime>(nullable: false),
514
+                    Modified = table.Column<DateTime>(nullable: false),
515
+                    ModifiedBy = table.Column<string>(nullable: true),
516
+                    PropertyId = table.Column<int>(nullable: false),
517
+                    Image = table.Column<string>(nullable: true),
518
+                    IsDefault = table.Column<bool>(nullable: false)
519
+                },
520
+                constraints: table =>
521
+                {
522
+                    table.PrimaryKey("PK_PropertyImages", x => x.Id);
523
+                    table.ForeignKey(
524
+                        name: "FK_PropertyImages_Properties_PropertyId",
525
+                        column: x => x.PropertyId,
526
+                        principalTable: "Properties",
527
+                        principalColumn: "Id",
528
+                        onDelete: ReferentialAction.Cascade);
529
+                });
530
+
531
+            migrationBuilder.CreateTable(
532
+                name: "PropertyUserFields",
533
+                columns: table => new
534
+                {
535
+                    Id = table.Column<int>(nullable: false)
536
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
537
+                    Created = table.Column<DateTime>(nullable: false),
538
+                    Modified = table.Column<DateTime>(nullable: false),
539
+                    ModifiedBy = table.Column<string>(nullable: true),
540
+                    PropertyId = table.Column<int>(nullable: false),
541
+                    UserDefinedFieldId = table.Column<int>(nullable: false),
542
+                    Value = table.Column<string>(nullable: true),
543
+                    Description = table.Column<string>(nullable: true)
544
+                },
545
+                constraints: table =>
546
+                {
547
+                    table.PrimaryKey("PK_PropertyUserFields", x => x.Id);
548
+                    table.ForeignKey(
549
+                        name: "FK_PropertyUserFields_Properties_PropertyId",
550
+                        column: x => x.PropertyId,
551
+                        principalTable: "Properties",
552
+                        principalColumn: "Id",
553
+                        onDelete: ReferentialAction.Cascade);
554
+                    table.ForeignKey(
555
+                        name: "FK_PropertyUserFields_UserDefinedFields_UserDefinedFieldId",
556
+                        column: x => x.UserDefinedFieldId,
557
+                        principalTable: "UserDefinedFields",
558
+                        principalColumn: "Id",
559
+                        onDelete: ReferentialAction.Cascade);
560
+                });
561
+
562
+            migrationBuilder.CreateIndex(
563
+                name: "IX_Accounts_SMTPHostId",
564
+                table: "Accounts",
565
+                column: "SMTPHostId");
566
+
567
+            migrationBuilder.CreateIndex(
568
+                name: "IX_Agents_AgencyId",
569
+                table: "Agents",
570
+                column: "AgencyId");
571
+
572
+            migrationBuilder.CreateIndex(
573
+                name: "IX_Agents_UserId",
574
+                table: "Agents",
575
+                column: "UserId");
576
+
577
+            migrationBuilder.CreateIndex(
578
+                name: "IX_Cities_ProvinceId",
579
+                table: "Cities",
580
+                column: "ProvinceId");
581
+
582
+            migrationBuilder.CreateIndex(
583
+                name: "IX_Emails_SenderId",
584
+                table: "Emails",
585
+                column: "SenderId");
586
+
587
+            migrationBuilder.CreateIndex(
588
+                name: "IX_Individuals_UserId",
589
+                table: "Individuals",
590
+                column: "UserId");
591
+
592
+            migrationBuilder.CreateIndex(
593
+                name: "IX_Properties_CityId",
594
+                table: "Properties",
595
+                column: "CityId");
596
+
597
+            migrationBuilder.CreateIndex(
598
+                name: "IX_Properties_PropertyTypeId",
599
+                table: "Properties",
600
+                column: "PropertyTypeId");
601
+
602
+            migrationBuilder.CreateIndex(
603
+                name: "IX_Properties_ProvinceId",
604
+                table: "Properties",
605
+                column: "ProvinceId");
606
+
607
+            migrationBuilder.CreateIndex(
608
+                name: "IX_Properties_SuburbId",
609
+                table: "Properties",
610
+                column: "SuburbId");
611
+
612
+            migrationBuilder.CreateIndex(
613
+                name: "IX_PropertyImages_PropertyId",
614
+                table: "PropertyImages",
615
+                column: "PropertyId");
616
+
617
+            migrationBuilder.CreateIndex(
618
+                name: "IX_PropertyUserFields_PropertyId",
619
+                table: "PropertyUserFields",
620
+                column: "PropertyId");
621
+
622
+            migrationBuilder.CreateIndex(
623
+                name: "IX_PropertyUserFields_UserDefinedFieldId",
624
+                table: "PropertyUserFields",
625
+                column: "UserDefinedFieldId");
626
+
627
+            migrationBuilder.CreateIndex(
628
+                name: "IX_Suburbs_CityId",
629
+                table: "Suburbs",
630
+                column: "CityId");
631
+
632
+            migrationBuilder.CreateIndex(
633
+                name: "IX_UnitConfigurations_Code",
634
+                table: "UnitConfigurations",
635
+                column: "Code",
636
+                unique: true);
637
+
638
+            migrationBuilder.CreateIndex(
639
+                name: "IX_UnitConfigurationTypes_UnitConfigurationId",
640
+                table: "UnitConfigurationTypes",
641
+                column: "UnitConfigurationId");
642
+
643
+            migrationBuilder.CreateIndex(
644
+                name: "IX_UserDefinedFields_GroupId",
645
+                table: "UserDefinedFields",
646
+                column: "GroupId");
647
+
648
+            migrationBuilder.CreateIndex(
649
+                name: "IX_Weeks_AgencyId",
650
+                table: "Weeks",
651
+                column: "AgencyId");
652
+
653
+            migrationBuilder.CreateIndex(
654
+                name: "IX_Weeks_AgentId",
655
+                table: "Weeks",
656
+                column: "AgentId");
657
+
658
+            migrationBuilder.CreateIndex(
659
+                name: "IX_Weeks_RegionId",
660
+                table: "Weeks",
661
+                column: "RegionId");
662
+
663
+            migrationBuilder.CreateIndex(
664
+                name: "IX_Weeks_StatusId",
665
+                table: "Weeks",
666
+                column: "StatusId");
667
+
668
+            migrationBuilder.CreateIndex(
669
+                name: "IX_Weeks_UnitConfigurationId",
670
+                table: "Weeks",
671
+                column: "UnitConfigurationId");
672
+        }
673
+
674
+        protected override void Down(MigrationBuilder migrationBuilder)
675
+        {
676
+            migrationBuilder.DropTable(
677
+                name: "Emails");
678
+
679
+            migrationBuilder.DropTable(
680
+                name: "Individuals");
681
+
682
+            migrationBuilder.DropTable(
683
+                name: "PropertyImages");
684
+
685
+            migrationBuilder.DropTable(
686
+                name: "PropertyUserFields");
687
+
688
+            migrationBuilder.DropTable(
689
+                name: "Seasons");
690
+
691
+            migrationBuilder.DropTable(
692
+                name: "UnitConfigurationTypes");
693
+
694
+            migrationBuilder.DropTable(
695
+                name: "Weeks");
696
+
697
+            migrationBuilder.DropTable(
698
+                name: "Accounts");
699
+
700
+            migrationBuilder.DropTable(
701
+                name: "Properties");
702
+
703
+            migrationBuilder.DropTable(
704
+                name: "UserDefinedFields");
705
+
706
+            migrationBuilder.DropTable(
707
+                name: "Agents");
708
+
709
+            migrationBuilder.DropTable(
710
+                name: "Status");
711
+
712
+            migrationBuilder.DropTable(
713
+                name: "UnitConfigurations");
714
+
715
+            migrationBuilder.DropTable(
716
+                name: "Hosts");
717
+
718
+            migrationBuilder.DropTable(
719
+                name: "PropertyTypes");
720
+
721
+            migrationBuilder.DropTable(
722
+                name: "Suburbs");
723
+
724
+            migrationBuilder.DropTable(
725
+                name: "UserDefinedGroups");
726
+
727
+            migrationBuilder.DropTable(
728
+                name: "Agencies");
729
+
730
+            migrationBuilder.DropTable(
731
+                name: "Users");
732
+
733
+            migrationBuilder.DropTable(
734
+                name: "Cities");
735
+
736
+            migrationBuilder.DropTable(
737
+                name: "Provinces");
738
+        }
739
+    }
740
+}

+ 765
- 0
UnivateProperties_API/Migrations/DataContextModelSnapshot.cs Vedi File

@@ -0,0 +1,765 @@
1
+// <auto-generated />
2
+using System;
3
+using Microsoft.EntityFrameworkCore;
4
+using Microsoft.EntityFrameworkCore.Infrastructure;
5
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
6
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
7
+using UnivateProperties_API.Context;
8
+
9
+namespace UnivateProperties_API.Migrations
10
+{
11
+    [DbContext(typeof(DataContext))]
12
+    partial class DataContextModelSnapshot : ModelSnapshot
13
+    {
14
+        protected override void BuildModel(ModelBuilder modelBuilder)
15
+        {
16
+#pragma warning disable 612, 618
17
+            modelBuilder
18
+                .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
19
+                .HasAnnotation("ProductVersion", "2.2.4-servicing-10062")
20
+                .HasAnnotation("Relational:MaxIdentifierLength", 63);
21
+
22
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.Email", b =>
23
+                {
24
+                    b.Property<int>("Id")
25
+                        .ValueGeneratedOnAdd();
26
+
27
+                    b.Property<string>("BCC");
28
+
29
+                    b.Property<string>("Body");
30
+
31
+                    b.Property<string>("CC");
32
+
33
+                    b.Property<string>("Comment");
34
+
35
+                    b.Property<DateTime>("Created");
36
+
37
+                    b.Property<bool>("IsBodyHtml");
38
+
39
+                    b.Property<DateTime>("Modified");
40
+
41
+                    b.Property<string>("ModifiedBy");
42
+
43
+                    b.Property<int>("SenderId");
44
+
45
+                    b.Property<string>("Subject");
46
+
47
+                    b.Property<string>("To");
48
+
49
+                    b.Property<string>("ToDisplay");
50
+
51
+                    b.HasKey("Id");
52
+
53
+                    b.HasIndex("SenderId");
54
+
55
+                    b.ToTable("Emails");
56
+                });
57
+
58
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.SMTPAccount", b =>
59
+                {
60
+                    b.Property<int>("Id")
61
+                        .ValueGeneratedOnAdd();
62
+
63
+                    b.Property<string>("Address");
64
+
65
+                    b.Property<DateTime>("Created");
66
+
67
+                    b.Property<string>("DisplayName");
68
+
69
+                    b.Property<DateTime>("Modified");
70
+
71
+                    b.Property<string>("ModifiedBy");
72
+
73
+                    b.Property<int>("SMTPHostId");
74
+
75
+                    b.HasKey("Id");
76
+
77
+                    b.HasIndex("SMTPHostId");
78
+
79
+                    b.ToTable("Accounts");
80
+                });
81
+
82
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.SMTPHost", b =>
83
+                {
84
+                    b.Property<int>("Id")
85
+                        .ValueGeneratedOnAdd();
86
+
87
+                    b.Property<DateTime>("Created");
88
+
89
+                    b.Property<string>("Host");
90
+
91
+                    b.Property<DateTime>("Modified");
92
+
93
+                    b.Property<string>("ModifiedBy");
94
+
95
+                    b.Property<bool>("NeedsAuthorize");
96
+
97
+                    b.Property<string>("Password");
98
+
99
+                    b.Property<bool>("UseSSL");
100
+
101
+                    b.Property<string>("User");
102
+
103
+                    b.HasKey("Id");
104
+
105
+                    b.ToTable("Hosts");
106
+                });
107
+
108
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.Property", b =>
109
+                {
110
+                    b.Property<int>("Id")
111
+                        .ValueGeneratedOnAdd();
112
+
113
+                    b.Property<string>("AddressLine1");
114
+
115
+                    b.Property<string>("AddressLine2");
116
+
117
+                    b.Property<string>("AddressLine3");
118
+
119
+                    b.Property<int>("CityId");
120
+
121
+                    b.Property<DateTime>("Created");
122
+
123
+                    b.Property<string>("Description");
124
+
125
+                    b.Property<bool>("IsSale");
126
+
127
+                    b.Property<DateTime>("Modified");
128
+
129
+                    b.Property<string>("ModifiedBy");
130
+
131
+                    b.Property<decimal>("OperationalCosts");
132
+
133
+                    b.Property<decimal>("Price");
134
+
135
+                    b.Property<string>("PricePer");
136
+
137
+                    b.Property<string>("PropertyName");
138
+
139
+                    b.Property<int>("PropertyTypeId");
140
+
141
+                    b.Property<int>("ProvinceId");
142
+
143
+                    b.Property<string>("ShortDescription");
144
+
145
+                    b.Property<int>("SuburbId");
146
+
147
+                    b.Property<string>("Unit");
148
+
149
+                    b.HasKey("Id");
150
+
151
+                    b.HasIndex("CityId");
152
+
153
+                    b.HasIndex("PropertyTypeId");
154
+
155
+                    b.HasIndex("ProvinceId");
156
+
157
+                    b.HasIndex("SuburbId");
158
+
159
+                    b.ToTable("Properties");
160
+                });
161
+
162
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.PropertyImage", b =>
163
+                {
164
+                    b.Property<int>("Id")
165
+                        .ValueGeneratedOnAdd();
166
+
167
+                    b.Property<DateTime>("Created");
168
+
169
+                    b.Property<string>("Image");
170
+
171
+                    b.Property<bool>("IsDefault");
172
+
173
+                    b.Property<DateTime>("Modified");
174
+
175
+                    b.Property<string>("ModifiedBy");
176
+
177
+                    b.Property<int>("PropertyId");
178
+
179
+                    b.HasKey("Id");
180
+
181
+                    b.HasIndex("PropertyId");
182
+
183
+                    b.ToTable("PropertyImages");
184
+                });
185
+
186
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.PropertyType", b =>
187
+                {
188
+                    b.Property<int>("Id")
189
+                        .ValueGeneratedOnAdd();
190
+
191
+                    b.Property<DateTime>("Created");
192
+
193
+                    b.Property<string>("Description");
194
+
195
+                    b.Property<DateTime>("Modified");
196
+
197
+                    b.Property<string>("ModifiedBy");
198
+
199
+                    b.Property<int>("UsageType");
200
+
201
+                    b.HasKey("Id");
202
+
203
+                    b.ToTable("PropertyTypes");
204
+                });
205
+
206
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.PropertyUserField", b =>
207
+                {
208
+                    b.Property<int>("Id")
209
+                        .ValueGeneratedOnAdd();
210
+
211
+                    b.Property<DateTime>("Created");
212
+
213
+                    b.Property<string>("Description");
214
+
215
+                    b.Property<DateTime>("Modified");
216
+
217
+                    b.Property<string>("ModifiedBy");
218
+
219
+                    b.Property<int>("PropertyId");
220
+
221
+                    b.Property<int>("UserDefinedFieldId");
222
+
223
+                    b.Property<string>("Value");
224
+
225
+                    b.HasKey("Id");
226
+
227
+                    b.HasIndex("PropertyId");
228
+
229
+                    b.HasIndex("UserDefinedFieldId");
230
+
231
+                    b.ToTable("PropertyUserFields");
232
+                });
233
+
234
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.UserDefinedField", b =>
235
+                {
236
+                    b.Property<int>("Id")
237
+                        .ValueGeneratedOnAdd();
238
+
239
+                    b.Property<DateTime>("Created");
240
+
241
+                    b.Property<string>("FieldName");
242
+
243
+                    b.Property<string>("FieldType");
244
+
245
+                    b.Property<int>("GroupId");
246
+
247
+                    b.Property<DateTime>("Modified");
248
+
249
+                    b.Property<string>("ModifiedBy");
250
+
251
+                    b.Property<int>("Rank");
252
+
253
+                    b.HasKey("Id");
254
+
255
+                    b.HasIndex("GroupId");
256
+
257
+                    b.ToTable("UserDefinedFields");
258
+                });
259
+
260
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.UserDefinedGroup", b =>
261
+                {
262
+                    b.Property<int>("Id")
263
+                        .ValueGeneratedOnAdd();
264
+
265
+                    b.Property<DateTime>("Created");
266
+
267
+                    b.Property<string>("Description");
268
+
269
+                    b.Property<DateTime>("Modified");
270
+
271
+                    b.Property<string>("ModifiedBy");
272
+
273
+                    b.Property<int>("Rank");
274
+
275
+                    b.Property<int>("UsageType");
276
+
277
+                    b.HasKey("Id");
278
+
279
+                    b.ToTable("UserDefinedGroups");
280
+                });
281
+
282
+            modelBuilder.Entity("UnivateProperties_API.Model.Region.City", b =>
283
+                {
284
+                    b.Property<int>("Id")
285
+                        .ValueGeneratedOnAdd();
286
+
287
+                    b.Property<string>("Code");
288
+
289
+                    b.Property<DateTime>("Created");
290
+
291
+                    b.Property<string>("Description");
292
+
293
+                    b.Property<DateTime>("Modified");
294
+
295
+                    b.Property<string>("ModifiedBy");
296
+
297
+                    b.Property<int>("ProvinceId");
298
+
299
+                    b.HasKey("Id");
300
+
301
+                    b.HasIndex("ProvinceId");
302
+
303
+                    b.ToTable("Cities");
304
+                });
305
+
306
+            modelBuilder.Entity("UnivateProperties_API.Model.Region.Province", b =>
307
+                {
308
+                    b.Property<int>("Id")
309
+                        .ValueGeneratedOnAdd();
310
+
311
+                    b.Property<string>("Code");
312
+
313
+                    b.Property<DateTime>("Created");
314
+
315
+                    b.Property<string>("Description");
316
+
317
+                    b.Property<DateTime>("Modified");
318
+
319
+                    b.Property<string>("ModifiedBy");
320
+
321
+                    b.HasKey("Id");
322
+
323
+                    b.ToTable("Provinces");
324
+                });
325
+
326
+            modelBuilder.Entity("UnivateProperties_API.Model.Region.Suburb", b =>
327
+                {
328
+                    b.Property<int>("Id")
329
+                        .ValueGeneratedOnAdd();
330
+
331
+                    b.Property<int>("CityId");
332
+
333
+                    b.Property<DateTime>("Created");
334
+
335
+                    b.Property<string>("Description");
336
+
337
+                    b.Property<DateTime>("Modified");
338
+
339
+                    b.Property<string>("ModifiedBy");
340
+
341
+                    b.Property<string>("PostalCode");
342
+
343
+                    b.HasKey("Id");
344
+
345
+                    b.HasIndex("CityId");
346
+
347
+                    b.ToTable("Suburbs");
348
+                });
349
+
350
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.Season", b =>
351
+                {
352
+                    b.Property<int>("Id")
353
+                        .ValueGeneratedOnAdd();
354
+
355
+                    b.Property<DateTime>("Created");
356
+
357
+                    b.Property<DateTime>("Modified");
358
+
359
+                    b.Property<string>("ModifiedBy");
360
+
361
+                    b.Property<string>("Name");
362
+
363
+                    b.HasKey("Id");
364
+
365
+                    b.ToTable("Seasons");
366
+                });
367
+
368
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.Status", b =>
369
+                {
370
+                    b.Property<int>("Id")
371
+                        .ValueGeneratedOnAdd();
372
+
373
+                    b.Property<string>("Code");
374
+
375
+                    b.Property<DateTime>("Created");
376
+
377
+                    b.Property<string>("Description");
378
+
379
+                    b.Property<DateTime>("Modified");
380
+
381
+                    b.Property<string>("ModifiedBy");
382
+
383
+                    b.HasKey("Id");
384
+
385
+                    b.ToTable("Status");
386
+                });
387
+
388
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.TimeshareWeek", b =>
389
+                {
390
+                    b.Property<int>("Id")
391
+                        .ValueGeneratedOnAdd();
392
+
393
+                    b.Property<int>("AgencyId");
394
+
395
+                    b.Property<int>("AgentId");
396
+
397
+                    b.Property<DateTime>("ArrivalDate");
398
+
399
+                    b.Property<string>("BankedWith");
400
+
401
+                    b.Property<DateTime>("Created");
402
+
403
+                    b.Property<bool>("CurrentYearBanked");
404
+
405
+                    b.Property<DateTime>("DepartureDate");
406
+
407
+                    b.Property<bool>("LeviesPaidInFull");
408
+
409
+                    b.Property<double>("LevyAmount");
410
+
411
+                    b.Property<DateTime>("Modified");
412
+
413
+                    b.Property<string>("ModifiedBy");
414
+
415
+                    b.Property<string>("Module");
416
+
417
+                    b.Property<DateTime>("OriginalPurchaseDate");
418
+
419
+                    b.Property<double>("OriginalPurchasePrice");
420
+
421
+                    b.Property<bool>("OtherResort");
422
+
423
+                    b.Property<bool>("ReferedByAgent");
424
+
425
+                    b.Property<int>("RegionId");
426
+
427
+                    b.Property<string>("ResortCode");
428
+
429
+                    b.Property<string>("ResortName");
430
+
431
+                    b.Property<string>("Season");
432
+
433
+                    b.Property<int>("StatusId");
434
+
435
+                    b.Property<int>("UnitConfigurationId");
436
+
437
+                    b.Property<string>("WeekNumber");
438
+
439
+                    b.Property<bool>("WeekPlacedForRental");
440
+
441
+                    b.HasKey("Id");
442
+
443
+                    b.HasIndex("AgencyId");
444
+
445
+                    b.HasIndex("AgentId");
446
+
447
+                    b.HasIndex("RegionId");
448
+
449
+                    b.HasIndex("StatusId");
450
+
451
+                    b.HasIndex("UnitConfigurationId");
452
+
453
+                    b.ToTable("Weeks");
454
+                });
455
+
456
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.UnitConfiguration", b =>
457
+                {
458
+                    b.Property<int>("Id")
459
+                        .ValueGeneratedOnAdd();
460
+
461
+                    b.Property<int>("Adults");
462
+
463
+                    b.Property<int>("Bedrooms");
464
+
465
+                    b.Property<int>("Children");
466
+
467
+                    b.Property<string>("Code");
468
+
469
+                    b.Property<DateTime>("Created");
470
+
471
+                    b.Property<DateTime>("Modified");
472
+
473
+                    b.Property<string>("ModifiedBy");
474
+
475
+                    b.HasKey("Id");
476
+
477
+                    b.HasIndex("Code")
478
+                        .IsUnique();
479
+
480
+                    b.ToTable("UnitConfigurations");
481
+                });
482
+
483
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.UnitConfigurationType", b =>
484
+                {
485
+                    b.Property<int>("Id")
486
+                        .ValueGeneratedOnAdd();
487
+
488
+                    b.Property<DateTime>("Created");
489
+
490
+                    b.Property<string>("Description");
491
+
492
+                    b.Property<DateTime>("Modified");
493
+
494
+                    b.Property<string>("ModifiedBy");
495
+
496
+                    b.Property<int>("UnitConfigurationId");
497
+
498
+                    b.HasKey("Id");
499
+
500
+                    b.HasIndex("UnitConfigurationId");
501
+
502
+                    b.ToTable("UnitConfigurationTypes");
503
+                });
504
+
505
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.Agency", b =>
506
+                {
507
+                    b.Property<int>("Id")
508
+                        .ValueGeneratedOnAdd();
509
+
510
+                    b.Property<string>("AgencyName");
511
+
512
+                    b.Property<string>("CompanyRegNumber");
513
+
514
+                    b.Property<DateTime>("Created");
515
+
516
+                    b.Property<string>("EAABEFFCNumber");
517
+
518
+                    b.Property<DateTime>("Modified");
519
+
520
+                    b.Property<string>("ModifiedBy");
521
+
522
+                    b.HasKey("Id");
523
+
524
+                    b.ToTable("Agencies");
525
+                });
526
+
527
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.Agent", b =>
528
+                {
529
+                    b.Property<int>("Id")
530
+                        .ValueGeneratedOnAdd();
531
+
532
+                    b.Property<int?>("AgencyId");
533
+
534
+                    b.Property<string>("CellNumber");
535
+
536
+                    b.Property<DateTime>("Created");
537
+
538
+                    b.Property<string>("Email");
539
+
540
+                    b.Property<DateTime>("Modified");
541
+
542
+                    b.Property<string>("ModifiedBy");
543
+
544
+                    b.Property<string>("Name");
545
+
546
+                    b.Property<string>("Surname");
547
+
548
+                    b.Property<string>("Telephone");
549
+
550
+                    b.Property<int>("UserId");
551
+
552
+                    b.HasKey("Id");
553
+
554
+                    b.HasIndex("AgencyId");
555
+
556
+                    b.HasIndex("UserId");
557
+
558
+                    b.ToTable("Agents");
559
+                });
560
+
561
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.Individual", b =>
562
+                {
563
+                    b.Property<int>("Id")
564
+                        .ValueGeneratedOnAdd();
565
+
566
+                    b.Property<string>("CellNumber");
567
+
568
+                    b.Property<DateTime>("Created");
569
+
570
+                    b.Property<string>("Email");
571
+
572
+                    b.Property<DateTime>("Modified");
573
+
574
+                    b.Property<string>("ModifiedBy");
575
+
576
+                    b.Property<string>("Name");
577
+
578
+                    b.Property<string>("Surname");
579
+
580
+                    b.Property<string>("Telephone");
581
+
582
+                    b.Property<int>("UserId");
583
+
584
+                    b.HasKey("Id");
585
+
586
+                    b.HasIndex("UserId");
587
+
588
+                    b.ToTable("Individuals");
589
+                });
590
+
591
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.User", b =>
592
+                {
593
+                    b.Property<int>("Id")
594
+                        .ValueGeneratedOnAdd();
595
+
596
+                    b.Property<DateTime>("Created");
597
+
598
+                    b.Property<DateTime>("Modified");
599
+
600
+                    b.Property<string>("ModifiedBy");
601
+
602
+                    b.Property<string>("Name");
603
+
604
+                    b.Property<byte[]>("PasswordHash");
605
+
606
+                    b.Property<byte[]>("PasswordSalt");
607
+
608
+                    b.Property<string>("Role");
609
+
610
+                    b.Property<string>("Surname");
611
+
612
+                    b.Property<string>("Token");
613
+
614
+                    b.Property<string>("Username");
615
+
616
+                    b.Property<bool>("Verified");
617
+
618
+                    b.HasKey("Id");
619
+
620
+                    b.ToTable("Users");
621
+                });
622
+
623
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.Email", b =>
624
+                {
625
+                    b.HasOne("UnivateProperties_API.Model.Communication.SMTPAccount", "Sender")
626
+                        .WithMany("Emails")
627
+                        .HasForeignKey("SenderId")
628
+                        .OnDelete(DeleteBehavior.Cascade);
629
+                });
630
+
631
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.SMTPAccount", b =>
632
+                {
633
+                    b.HasOne("UnivateProperties_API.Model.Communication.SMTPHost", "SMTPHost")
634
+                        .WithMany("SMTPAccounts")
635
+                        .HasForeignKey("SMTPHostId")
636
+                        .OnDelete(DeleteBehavior.Cascade);
637
+                });
638
+
639
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.Property", b =>
640
+                {
641
+                    b.HasOne("UnivateProperties_API.Model.Region.City", "City")
642
+                        .WithMany()
643
+                        .HasForeignKey("CityId")
644
+                        .OnDelete(DeleteBehavior.Cascade);
645
+
646
+                    b.HasOne("UnivateProperties_API.Model.Property.PropertyType", "PropertyType")
647
+                        .WithMany()
648
+                        .HasForeignKey("PropertyTypeId")
649
+                        .OnDelete(DeleteBehavior.Cascade);
650
+
651
+                    b.HasOne("UnivateProperties_API.Model.Region.Province", "Province")
652
+                        .WithMany()
653
+                        .HasForeignKey("ProvinceId")
654
+                        .OnDelete(DeleteBehavior.Cascade);
655
+
656
+                    b.HasOne("UnivateProperties_API.Model.Region.Suburb", "Suburb")
657
+                        .WithMany()
658
+                        .HasForeignKey("SuburbId")
659
+                        .OnDelete(DeleteBehavior.Cascade);
660
+                });
661
+
662
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.PropertyImage", b =>
663
+                {
664
+                    b.HasOne("UnivateProperties_API.Model.Property.Property", "Property")
665
+                        .WithMany("PropertyImages")
666
+                        .HasForeignKey("PropertyId")
667
+                        .OnDelete(DeleteBehavior.Cascade);
668
+                });
669
+
670
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.PropertyUserField", b =>
671
+                {
672
+                    b.HasOne("UnivateProperties_API.Model.Property.Property", "Property")
673
+                        .WithMany("PropertyUserFields")
674
+                        .HasForeignKey("PropertyId")
675
+                        .OnDelete(DeleteBehavior.Cascade);
676
+
677
+                    b.HasOne("UnivateProperties_API.Model.Property.UserDefinedField", "UserDefinedField")
678
+                        .WithMany()
679
+                        .HasForeignKey("UserDefinedFieldId")
680
+                        .OnDelete(DeleteBehavior.Cascade);
681
+                });
682
+
683
+            modelBuilder.Entity("UnivateProperties_API.Model.Property.UserDefinedField", b =>
684
+                {
685
+                    b.HasOne("UnivateProperties_API.Model.Property.UserDefinedGroup", "Group")
686
+                        .WithMany("Fields")
687
+                        .HasForeignKey("GroupId")
688
+                        .OnDelete(DeleteBehavior.Cascade);
689
+                });
690
+
691
+            modelBuilder.Entity("UnivateProperties_API.Model.Region.City", b =>
692
+                {
693
+                    b.HasOne("UnivateProperties_API.Model.Region.Province", "Province")
694
+                        .WithMany()
695
+                        .HasForeignKey("ProvinceId")
696
+                        .OnDelete(DeleteBehavior.Cascade);
697
+                });
698
+
699
+            modelBuilder.Entity("UnivateProperties_API.Model.Region.Suburb", b =>
700
+                {
701
+                    b.HasOne("UnivateProperties_API.Model.Region.City", "City")
702
+                        .WithMany()
703
+                        .HasForeignKey("CityId")
704
+                        .OnDelete(DeleteBehavior.Cascade);
705
+                });
706
+
707
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.TimeshareWeek", b =>
708
+                {
709
+                    b.HasOne("UnivateProperties_API.Model.Users.Agency", "Agency")
710
+                        .WithMany()
711
+                        .HasForeignKey("AgencyId")
712
+                        .OnDelete(DeleteBehavior.Cascade);
713
+
714
+                    b.HasOne("UnivateProperties_API.Model.Users.Agent", "Agent")
715
+                        .WithMany()
716
+                        .HasForeignKey("AgentId")
717
+                        .OnDelete(DeleteBehavior.Cascade);
718
+
719
+                    b.HasOne("UnivateProperties_API.Model.Region.Province", "Region")
720
+                        .WithMany()
721
+                        .HasForeignKey("RegionId")
722
+                        .OnDelete(DeleteBehavior.Cascade);
723
+
724
+                    b.HasOne("UnivateProperties_API.Model.Timeshare.Status", "Status")
725
+                        .WithMany()
726
+                        .HasForeignKey("StatusId")
727
+                        .OnDelete(DeleteBehavior.Cascade);
728
+
729
+                    b.HasOne("UnivateProperties_API.Model.Timeshare.UnitConfiguration", "UnitConfiguration")
730
+                        .WithMany()
731
+                        .HasForeignKey("UnitConfigurationId")
732
+                        .OnDelete(DeleteBehavior.Cascade);
733
+                });
734
+
735
+            modelBuilder.Entity("UnivateProperties_API.Model.Timeshare.UnitConfigurationType", b =>
736
+                {
737
+                    b.HasOne("UnivateProperties_API.Model.Timeshare.UnitConfiguration", "UnitConfiguration")
738
+                        .WithMany("Types")
739
+                        .HasForeignKey("UnitConfigurationId")
740
+                        .OnDelete(DeleteBehavior.Cascade);
741
+                });
742
+
743
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.Agent", b =>
744
+                {
745
+                    b.HasOne("UnivateProperties_API.Model.Users.Agency", "Agency")
746
+                        .WithMany("Agents")
747
+                        .HasForeignKey("AgencyId");
748
+
749
+                    b.HasOne("UnivateProperties_API.Model.Users.User", "User")
750
+                        .WithMany()
751
+                        .HasForeignKey("UserId")
752
+                        .OnDelete(DeleteBehavior.Cascade);
753
+                });
754
+
755
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.Individual", b =>
756
+                {
757
+                    b.HasOne("UnivateProperties_API.Model.Users.User", "User")
758
+                        .WithMany()
759
+                        .HasForeignKey("UserId")
760
+                        .OnDelete(DeleteBehavior.Cascade);
761
+                });
762
+#pragma warning restore 612, 618
763
+        }
764
+    }
765
+}

+ 43
- 0
UnivateProperties_API/Model/BaseEntity.cs Vedi File

@@ -0,0 +1,43 @@
1
+using System;
2
+using System.ComponentModel.DataAnnotations;
3
+using System.ComponentModel.DataAnnotations.Schema;
4
+using UnivateProperties_API.Containers;
5
+
6
+namespace UnivateProperties_API.Model
7
+{
8
+    public class BaseEntity
9
+    {
10
+        #region Properties
11
+        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
12
+        [Key]
13
+        public int Id { get; set; }
14
+        public DateTime Created { get; set; } = DateTime.Now;
15
+        public DateTime Modified { get; set; } = DateTime.Now;
16
+        public string ModifiedBy { get; set; }
17
+        [NotMapped]
18
+        public ValidateEntity Valid { get; set; }
19
+        #endregion
20
+
21
+        #region Methods
22
+        public virtual void UpdateModified(string modifiedBy)
23
+        {
24
+            Modified = DateTime.Now;
25
+            if (string.IsNullOrEmpty(modifiedBy))
26
+            {
27
+                ModifiedBy = modifiedBy;
28
+            }
29
+        }
30
+
31
+        public void Validate()
32
+        {
33
+            Valid = ValidateObject();
34
+        }
35
+
36
+        public virtual ValidateEntity ValidateObject()
37
+        {
38
+            ValidateEntity v = new ValidateEntity();
39
+            return v;
40
+        }
41
+        #endregion Methods
42
+    }
43
+}

+ 142
- 0
UnivateProperties_API/Model/Communication/Email.cs Vedi File

@@ -0,0 +1,142 @@
1
+using UnivateProperties_API.Helpers;
2
+using System;
3
+using System.ComponentModel.DataAnnotations.Schema;
4
+using System.Net.Mail;
5
+using System.Text;
6
+
7
+namespace UnivateProperties_API.Model.Communication
8
+{
9
+    public class Email : BaseEntity
10
+    {
11
+        #region Constructor
12
+        public Email()
13
+        {
14
+            
15
+        }
16
+
17
+        public Email(int senderId)
18
+        {
19
+            SenderId = senderId;
20
+        }
21
+
22
+        public Email(int senderId, string toAddress, string toDisplay, string cc, string bcc, string subject, string body, bool isHtml = true)
23
+        {
24
+            SenderId = senderId;
25
+            To = toAddress;
26
+            ToDisplay = toDisplay;
27
+            BCC = bcc;
28
+            CC = cc;
29
+            IsBodyHtml = isHtml;
30
+            Body = body;
31
+            Subject = subject;
32
+        }
33
+        #endregion Constructor
34
+
35
+        #region Properties
36
+        [ForeignKey("Sender")]
37
+        public int SenderId { get; set; }
38
+        public string Comment { get; set; }
39
+        public string Subject { get; set; }
40
+        public bool IsBodyHtml { get; set; }
41
+        public string CC { get; set; }
42
+        public string BCC { get; set; }
43
+        public string Body { get; set; }
44
+        public string To { get; set; }
45
+        public string ToDisplay { get; set; }
46
+
47
+        public virtual SMTPAccount Sender { get; set; }
48
+        #endregion
49
+
50
+        #region Methods
51
+        public virtual void GetSMTPAccount()
52
+        {
53
+            if (SenderId > 0)
54
+            {
55
+
56
+            }
57
+        }
58
+
59
+        public virtual bool SendMail()
60
+        {
61
+            try
62
+            {
63
+                if (MyCommon.IsValidEmail(To))
64
+                {
65
+                    if (Sender != null && Sender.SMTPHost != null)
66
+                    {
67
+                        using (SmtpClient smtp = new SmtpClient(Sender.SMTPHost.Host))
68
+                        {
69
+                            MailMessage mail = GetMailMessage();
70
+                            smtp.UseDefaultCredentials = Sender.SMTPHost.NeedsAuthorize;
71
+                            smtp.Credentials = Sender.SMTPHost.GetNetworkCredential();
72
+                            smtp.EnableSsl = Sender.SMTPHost.UseSSL;
73
+                            smtp.Send(mail);
74
+                            Comment = "Send";
75
+                            return true;
76
+                        };
77
+                    }
78
+                    else Comment = "NoSender";
79
+                }
80
+            }
81
+            catch (SmtpFailedRecipientException ex)
82
+            {
83
+                SmtpStatusCode statusCode = ex.StatusCode;
84
+
85
+                if (statusCode == SmtpStatusCode.MailboxBusy ||
86
+                    statusCode == SmtpStatusCode.MailboxUnavailable ||
87
+                    statusCode == SmtpStatusCode.TransactionFailed)
88
+                {
89
+                    Comment = $"SmtpFailedRecipientException - Msg - {ex.Message} Stack - {ex.StackTrace}";
90
+                    //TODO: Return correct error message
91
+                    return false;
92
+                }
93
+                else
94
+                {
95
+                    Comment = $"SmtpFailedRecipientException - Msg - {ex.Message} Stack - {ex.StackTrace}";
96
+                    //TODO: Return correct error message
97
+                    return false;
98
+                }
99
+            }
100
+            catch (Exception ex)
101
+            {
102
+                Comment = $"Exception - Msg - {ex.Message} Stack - {ex.StackTrace}";
103
+                //TODO: Return correct error message
104
+                return false;
105
+            }
106
+            return true;
107
+        }
108
+
109
+        private MailMessage GetMailMessage()
110
+        {
111
+            MailMessage mail = new MailMessage();
112
+            mail.To.Add(new MailAddress(To, ToDisplay));
113
+            if (!string.IsNullOrEmpty(CC))
114
+            {
115
+                foreach (var item in CC.Split(';'))
116
+                {
117
+                    mail.CC.Add(item);
118
+                }
119
+            }
120
+            if (!string.IsNullOrEmpty(BCC))
121
+            {
122
+                foreach (var item in BCC.Split(';'))
123
+                {
124
+                    mail.Bcc.Add(item);
125
+                }
126
+            }
127
+            mail.Subject = Subject;
128
+            mail.Body = Body;
129
+            mail.IsBodyHtml = IsBodyHtml;
130
+            if (IsBodyHtml)
131
+            {
132
+                mail.BodyEncoding = Encoding.ASCII;
133
+            }
134
+            else mail.BodyEncoding = Encoding.UTF8;
135
+            mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
136
+            mail.Sender = new MailAddress(Sender.Address, Sender.DisplayName);
137
+            mail.From = mail.Sender;
138
+            return mail;
139
+        }
140
+        #endregion Methods
141
+    }
142
+}

+ 43
- 0
UnivateProperties_API/Model/Communication/SMTPAccount.cs Vedi File

@@ -0,0 +1,43 @@
1
+using System.Collections.Generic;
2
+using System.ComponentModel.DataAnnotations.Schema;
3
+
4
+namespace UnivateProperties_API.Model.Communication
5
+{
6
+    public class SMTPAccount : BaseEntity
7
+    {
8
+        #region Constructors
9
+        public SMTPAccount()
10
+        {
11
+
12
+        }
13
+
14
+        public SMTPAccount(string address)
15
+        {
16
+            Address = address;
17
+        }
18
+
19
+        public SMTPAccount(string address, string displayName)
20
+        {
21
+            Address = address;
22
+            DisplayName = displayName;
23
+        }
24
+
25
+        public SMTPAccount(string address, string displayName, int smtpHostId)
26
+        {
27
+            Address = address;
28
+            DisplayName = displayName;
29
+            SMTPHostId = smtpHostId;
30
+        }
31
+        #endregion Constructors
32
+
33
+        #region Properties
34
+        public string Address { get; set; }
35
+        public string DisplayName { get; set; }
36
+        [ForeignKey("SMTPHost")]
37
+        public int SMTPHostId { get; set; }
38
+
39
+        public virtual SMTPHost SMTPHost { get; set; }
40
+        public virtual ICollection<Email> Emails { get; set; }
41
+        #endregion Properties
42
+    }
43
+}

+ 44
- 0
UnivateProperties_API/Model/Communication/SMTPHost.cs Vedi File

@@ -0,0 +1,44 @@
1
+using System.Collections.Generic;
2
+using System.Net;
3
+
4
+namespace UnivateProperties_API.Model.Communication
5
+{
6
+    public class SMTPHost : BaseEntity
7
+    {
8
+        #region Constructor
9
+        public SMTPHost()
10
+        {
11
+
12
+        }
13
+
14
+        public SMTPHost(string host, bool needsAutorize, string user, string password)
15
+        {
16
+            Host = host;
17
+            User = user;
18
+            NeedsAuthorize = needsAutorize;
19
+            Password = password;
20
+        }
21
+        #endregion
22
+
23
+        #region Properties
24
+        public string Host { get; set; }
25
+        public bool NeedsAuthorize { get; set; } = false;
26
+        public string User { get; set; }
27
+        public string Password { get; set; }
28
+        public bool UseSSL { get; set; } = false;
29
+
30
+        public virtual ICollection<SMTPAccount> SMTPAccounts { get; set; }
31
+        #endregion Properties
32
+
33
+        #region Methods
34
+        public NetworkCredential GetNetworkCredential()
35
+        {
36
+            if (NeedsAuthorize)
37
+            {
38
+                return new NetworkCredential(User, Password);
39
+            }
40
+            return null;
41
+        }
42
+        #endregion
43
+    }
44
+}

+ 40
- 0
UnivateProperties_API/Model/Property/Property.cs Vedi File

@@ -0,0 +1,40 @@
1
+using System.Collections.Generic;
2
+using System.ComponentModel.DataAnnotations.Schema;
3
+using UnivateProperties_API.Containers.Property;
4
+using UnivateProperties_API.Model.Region;
5
+
6
+namespace UnivateProperties_API.Model.Property
7
+{
8
+    public class Property : BaseEntity
9
+    {
10
+        #region Properties
11
+        [ForeignKey("PropertyType")]
12
+        public int PropertyTypeId { get; set; }
13
+        public string PropertyName { get; set; }
14
+        public string Unit { get; set; }
15
+        public decimal OperationalCosts { get; set; }           
16
+        public decimal Price { get; set; }
17
+        public string PricePer { get; set; }
18
+        public bool IsSale { get; set; }
19
+        public string Description { get; set; }
20
+        public string ShortDescription { get; set; }
21
+        public string AddressLine1 { get; set; }
22
+        public string AddressLine2 { get; set; }
23
+        public string AddressLine3 { get; set; }
24
+        public int SuburbId { get; set; }
25
+        public int CityId { get; set; }
26
+        public int ProvinceId { get; set; }
27
+
28
+        public virtual PropertyType PropertyType { get; set; }
29
+        public virtual Province Province { get; set; }
30
+        public virtual City City { get; set; }
31
+        public virtual Suburb Suburb { get; set; }
32
+
33
+        public ICollection<PropertyUserField> PropertyUserFields { get; set; }
34
+        public ICollection<PropertyImage> PropertyImages { get; set; }
35
+
36
+        [NotMapped]
37
+        public List<PropertyDetailGroup> DisplayData { get; set; }
38
+        #endregion
39
+    }
40
+}

+ 15
- 0
UnivateProperties_API/Model/Property/PropertyImage.cs Vedi File

@@ -0,0 +1,15 @@
1
+using System.ComponentModel.DataAnnotations.Schema;
2
+
3
+namespace UnivateProperties_API.Model.Property
4
+{
5
+    public class PropertyImage : BaseEntity
6
+    {
7
+        #region Properties 
8
+        [ForeignKey("Property")]
9
+        public int PropertyId { get; set; }
10
+        public string Image { get; set; }
11
+        public bool IsDefault { get; set; }
12
+        public virtual Property Property { get; set; }
13
+        #endregion 
14
+    }
15
+}

+ 10
- 0
UnivateProperties_API/Model/Property/PropertyType.cs Vedi File

@@ -0,0 +1,10 @@
1
+namespace UnivateProperties_API.Model.Property
2
+{
3
+    public class PropertyType : BaseEntity
4
+    {
5
+        #region Properties 
6
+        public string Description { get; set; }
7
+        public PropertyUsageType UsageType { get; set; }
8
+        #endregion 
9
+    }
10
+}

+ 19
- 0
UnivateProperties_API/Model/Property/PropertyUserField.cs Vedi File

@@ -0,0 +1,19 @@
1
+using System.ComponentModel.DataAnnotations.Schema;
2
+
3
+namespace UnivateProperties_API.Model.Property
4
+{
5
+    public class PropertyUserField : BaseEntity
6
+    {
7
+        #region Properties 
8
+        [ForeignKey("Property")]
9
+        public int PropertyId { get; set; }
10
+        [ForeignKey("UserDefinedField")]
11
+        public int UserDefinedFieldId { get; set; }
12
+        public string Value { get; set; }
13
+        public string Description { get; set; }
14
+
15
+        public virtual Property Property { get; set; }
16
+        public virtual UserDefinedField UserDefinedField { get; set; }
17
+        #endregion 
18
+    }
19
+}

+ 17
- 0
UnivateProperties_API/Model/Property/UserDefinedField.cs Vedi File

@@ -0,0 +1,17 @@
1
+using System.ComponentModel.DataAnnotations.Schema;
2
+
3
+namespace UnivateProperties_API.Model.Property
4
+{
5
+    public class UserDefinedField : BaseEntity
6
+    {
7
+        #region Properties 
8
+        [ForeignKey("Group")]
9
+        public int GroupId { get; set; }
10
+        public string FieldName { get; set; }
11
+        public string FieldType { get; set; }        
12
+        public int Rank { get; set; }
13
+
14
+        public virtual UserDefinedGroup Group { get; set; }
15
+        #endregion 
16
+    }
17
+}

+ 15
- 0
UnivateProperties_API/Model/Property/UserDefinedGroup.cs Vedi File

@@ -0,0 +1,15 @@
1
+using System.Collections.Generic;
2
+
3
+namespace UnivateProperties_API.Model.Property
4
+{
5
+    public class UserDefinedGroup : BaseEntity
6
+    {
7
+        #region Properties
8
+        public string Description { get; set; }
9
+        public PropertyUsageType UsageType { get; set; }
10
+        public int Rank { get; set; }
11
+
12
+        public ICollection<UserDefinedField> Fields { get; set; }
13
+        #endregion 
14
+    }
15
+}

+ 16
- 0
UnivateProperties_API/Model/Region/City.cs Vedi File

@@ -0,0 +1,16 @@
1
+using System.ComponentModel.DataAnnotations.Schema;
2
+
3
+namespace UnivateProperties_API.Model.Region
4
+{
5
+    public class City :BaseEntity
6
+    {
7
+        #region Properties 
8
+        [ForeignKey("Province")]
9
+        public int ProvinceId { get; set; }
10
+        public string Description { get; set; }
11
+        public string Code { get; set; }
12
+
13
+        public virtual Province Province { get; set; }
14
+        #endregion
15
+    }
16
+}

+ 10
- 0
UnivateProperties_API/Model/Region/Province.cs Vedi File

@@ -0,0 +1,10 @@
1
+namespace UnivateProperties_API.Model.Region
2
+{
3
+    public class Province : BaseEntity
4
+    {
5
+        #region Properties
6
+        public string Description { get; set; }
7
+        public string Code { get; set; }
8
+        #endregion 
9
+    }
10
+}

+ 16
- 0
UnivateProperties_API/Model/Region/Suburb.cs Vedi File

@@ -0,0 +1,16 @@
1
+using System.ComponentModel.DataAnnotations.Schema;
2
+
3
+namespace UnivateProperties_API.Model.Region
4
+{
5
+    public class Suburb : BaseEntity
6
+    {
7
+        #region Properties
8
+        [ForeignKey("City")]
9
+        public int CityId { get; set; }
10
+        public string Description { get; set; }
11
+        public string PostalCode { get; set; }
12
+
13
+        public virtual City City { get; set; }
14
+        #endregion 
15
+    }
16
+}

+ 7
- 0
UnivateProperties_API/Model/Timeshare/Season.cs Vedi File

@@ -0,0 +1,7 @@
1
+namespace UnivateProperties_API.Model.Timeshare
2
+{
3
+    public class Season : BaseEntity
4
+    {
5
+        public string Name { get; set; }
6
+    }
7
+}

+ 8
- 0
UnivateProperties_API/Model/Timeshare/Status.cs Vedi File

@@ -0,0 +1,8 @@
1
+namespace UnivateProperties_API.Model.Timeshare
2
+{
3
+    public class Status : BaseEntity
4
+    {
5
+        public string Code { get; set; }
6
+        public string Description { get; set; }
7
+    }
8
+}

+ 51
- 0
UnivateProperties_API/Model/Timeshare/TimeshareWeek.cs Vedi File

@@ -0,0 +1,51 @@
1
+using System;
2
+using System.ComponentModel.DataAnnotations.Schema;
3
+using UnivateProperties_API.Model.Region;
4
+using UnivateProperties_API.Model.Users;
5
+
6
+namespace UnivateProperties_API.Model.Timeshare
7
+{
8
+    public class TimeshareWeek : BaseEntity
9
+    {
10
+        #region Properties
11
+        public bool ReferedByAgent { get; set; }
12
+        [ForeignKey("Agent")]
13
+        public int AgentId { get; set; }
14
+        [ForeignKey("Agency")]
15
+        public int AgencyId { get; set; }
16
+        [ForeignKey("UnitConfiguration")]
17
+        public int UnitConfigurationId { get; set; }
18
+
19
+        public bool OtherResort { get; set; }
20
+        public string ResortCode { get; set; }
21
+        public string ResortName { get; set; }
22
+        [ForeignKey("Region")]
23
+        public int RegionId { get; set; }
24
+        public string Season { get; set; }
25
+        public string Module { get; set; }
26
+        public string WeekNumber { get; set; }
27
+        public double LevyAmount { get; set; }
28
+
29
+        public bool CurrentYearBanked { get; set; }
30
+        public string BankedWith { get; set; }
31
+
32
+        public bool LeviesPaidInFull { get; set; }
33
+        public bool WeekPlacedForRental { get; set; }
34
+        public double OriginalPurchasePrice { get; set; }
35
+        public DateTime OriginalPurchaseDate { get; set; }
36
+        public DateTime ArrivalDate { get; set; }
37
+        public DateTime DepartureDate { get; set; }
38
+
39
+        [ForeignKey("Status")]
40
+        public int StatusId { get; set; }
41
+        #endregion
42
+
43
+        #region Navigation
44
+        public virtual Status Status { get; set; }
45
+        public virtual Province Region { get; set; }
46
+        public virtual Agent Agent { get; set; }
47
+        public virtual Agency Agency { get; set; }
48
+        public virtual UnitConfiguration UnitConfiguration { get; set; }
49
+        #endregion Navigation
50
+    }
51
+}

+ 17
- 0
UnivateProperties_API/Model/Timeshare/UnitConfiguration.cs Vedi File

@@ -0,0 +1,17 @@
1
+using System.Collections.Generic;
2
+
3
+namespace UnivateProperties_API.Model.Timeshare
4
+{
5
+    public class UnitConfiguration : BaseEntity
6
+    {
7
+        #region Properties
8
+        public string Code { get; set; }
9
+        public int Bedrooms { get; set; }
10
+        public int Adults { get; set; }
11
+        public int Children { get; set; }
12
+        #endregion Properties
13
+        #region Navigation
14
+        public virtual ICollection<UnitConfigurationType> Types { get; set; }
15
+        #endregion Navigation
16
+    }
17
+}

+ 28
- 0
UnivateProperties_API/Model/Timeshare/UnitConfigurationType.cs Vedi File

@@ -0,0 +1,28 @@
1
+using System.ComponentModel.DataAnnotations.Schema;
2
+using UnivateProperties_API.Containers;
3
+
4
+namespace UnivateProperties_API.Model.Timeshare
5
+{
6
+    public class UnitConfigurationType : BaseEntity
7
+    {
8
+        #region Properties
9
+        public string Description { get; set; }
10
+        [ForeignKey("UnitConfiguration")]
11
+        public int UnitConfigurationId { get; set; }
12
+        #endregion Properties
13
+        #region Navigation
14
+        public virtual UnitConfiguration UnitConfiguration { get; set; }
15
+        #endregion Navigation
16
+        #region Methods
17
+        public override ValidateEntity ValidateObject()
18
+        {
19
+            ValidateEntity v = new ValidateEntity();
20
+            if (string.IsNullOrEmpty(Description))
21
+            {
22
+                v.Errors.Add("Description cant be blank");
23
+            }
24
+            return v;
25
+        }
26
+        #endregion
27
+    }
28
+}

+ 22
- 0
UnivateProperties_API/Model/Users/Agency.cs Vedi File

@@ -0,0 +1,22 @@
1
+using System.Collections.Generic;
2
+
3
+namespace UnivateProperties_API.Model.Users
4
+{
5
+    public class Agency : BaseEntity
6
+    {
7
+        #region Constructor
8
+        public Agency()
9
+        {
10
+
11
+        }
12
+        #endregion Constructor
13
+
14
+        #region Properties
15
+        public string AgencyName { get; set; }
16
+        public string EAABEFFCNumber { get; set; }
17
+        public string CompanyRegNumber { get; set; }
18
+
19
+        public virtual ICollection<Agent> Agents { get; set; }
20
+        #endregion Properties
21
+    }
22
+}

+ 21
- 0
UnivateProperties_API/Model/Users/Agent.cs Vedi File

@@ -0,0 +1,21 @@
1
+using System.Collections.Generic;
2
+using System.ComponentModel.DataAnnotations.Schema;
3
+
4
+namespace UnivateProperties_API.Model.Users
5
+{
6
+    public class Agent : Person
7
+    {
8
+        #region Constructor
9
+        public Agent()
10
+        {
11
+
12
+        }
13
+        #endregion Constructor
14
+
15
+        #region Properties
16
+        [ForeignKey("Agency")]
17
+        public int? AgencyId { get; set; }
18
+        public virtual Agency Agency { get; set; }
19
+        #endregion Properties
20
+    }
21
+}

+ 12
- 0
UnivateProperties_API/Model/Users/AppSettings.cs Vedi File

@@ -0,0 +1,12 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+
6
+namespace UnivateProperties_API.Model.Users
7
+{
8
+    public class AppSettings
9
+    {
10
+        public string Secret { get; set; }
11
+    }
12
+}

+ 20
- 0
UnivateProperties_API/Model/Users/Individual.cs Vedi File

@@ -0,0 +1,20 @@
1
+using System.Collections.Generic;
2
+using System.ComponentModel.DataAnnotations;
3
+using System.ComponentModel.DataAnnotations.Schema;
4
+
5
+namespace UnivateProperties_API.Model.Users
6
+{
7
+    public class Individual : Person
8
+    {
9
+        #region Constructor
10
+        public Individual()
11
+        {
12
+
13
+        }
14
+        #endregion Constructor
15
+
16
+        #region Properties
17
+        
18
+        #endregion Properties
19
+    }
20
+}

+ 28
- 0
UnivateProperties_API/Model/Users/Person.cs Vedi File

@@ -0,0 +1,28 @@
1
+using System.ComponentModel.DataAnnotations;
2
+using System.ComponentModel.DataAnnotations.Schema;
3
+
4
+namespace UnivateProperties_API.Model.Users
5
+{
6
+    public class Person : BaseEntity
7
+    {
8
+        #region Constructor
9
+        public Person()
10
+        {
11
+
12
+        }
13
+        #endregion Constructor
14
+
15
+        #region Properties
16
+        [ForeignKey("User")]
17
+        public int UserId { get; set; }
18
+        public string Name { get; set; }
19
+        public string Surname { get; set; }
20
+        public string Email { get; set; }
21
+        [Phone]
22
+        public string Telephone { get; set; }
23
+        [Phone]
24
+        public string CellNumber { get; set; }
25
+        public virtual User User { get; set; }
26
+        #endregion Properties
27
+    }
28
+}

+ 23
- 0
UnivateProperties_API/Model/Users/User.cs Vedi File

@@ -0,0 +1,23 @@
1
+namespace UnivateProperties_API.Model.Users
2
+{
3
+    public class User : BaseEntity
4
+    {
5
+        #region Constructor
6
+        public User()
7
+        {
8
+
9
+        }
10
+        #endregion Constructor
11
+
12
+        #region Properties
13
+        public string Name { get; set; }
14
+        public string Surname { get; set; }
15
+        public string Username { get; set; }
16
+        public string Role { get; set; }
17
+        public byte[] PasswordHash { get; set; }
18
+        public byte[] PasswordSalt { get; set; }
19
+        public bool Verified { get; set; }
20
+        public string Token { get; set; }
21
+        #endregion Properties
22
+    }
23
+}

+ 24
- 0
UnivateProperties_API/Program.cs Vedi File

@@ -0,0 +1,24 @@
1
+using Microsoft.AspNetCore;
2
+using Microsoft.AspNetCore.Hosting;
3
+
4
+namespace UnivateProperties_API
5
+{
6
+    public class Program
7
+    {
8
+        public static void Main(string[] args)
9
+        {
10
+            CreateWebHostBuilder(args).Build().Run();
11
+            BuildWebHost(args).Run();
12
+        }
13
+
14
+        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
15
+            WebHost.CreateDefaultBuilder(args)
16
+                .UseStartup<Startup>();
17
+
18
+        public static IWebHost BuildWebHost(string[] args) =>
19
+            WebHost.CreateDefaultBuilder(args)
20
+                .UseStartup<Startup>()
21
+                .UseUrls("http://192.168.6.188/Univate-API")
22
+                .Build();
23
+    }
24
+}

+ 30
- 0
UnivateProperties_API/Properties/launchSettings.json Vedi File

@@ -0,0 +1,30 @@
1
+{
2
+  "$schema": "http://json.schemastore.org/launchsettings.json",
3
+  "iisSettings": {
4
+    "windowsAuthentication": false, 
5
+    "anonymousAuthentication": true, 
6
+    "iisExpress": {
7
+      "applicationUrl": "http://localhost:57260",
8
+      "sslPort": 0
9
+    }
10
+  },
11
+  "profiles": {
12
+    "IIS Express": {
13
+      "commandName": "IISExpress",
14
+      "launchBrowser": true,
15
+      "launchUrl": "api/values",
16
+      "environmentVariables": {
17
+        "ASPNETCORE_ENVIRONMENT": "Development"
18
+      }
19
+    },
20
+    "UnivateProperties_API": {
21
+      "commandName": "Project",
22
+      "launchBrowser": true,
23
+      "launchUrl": "api/values",
24
+      "applicationUrl": "http://localhost:5000",
25
+      "environmentVariables": {
26
+        "ASPNETCORE_ENVIRONMENT": "Development"
27
+      }
28
+    }
29
+  }
30
+}

+ 108
- 0
UnivateProperties_API/Repository/Communication/EmailRepository.cs Vedi File

@@ -0,0 +1,108 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Communication;
7
+
8
+namespace UnivateProperties_API.Repository.Communication
9
+{
10
+    public class EmailRepository : IRepository<Email>
11
+    {
12
+        private readonly DataContext _dbContext;
13
+
14
+        public EmailRepository(DataContext dbContext)
15
+        {
16
+            _dbContext = dbContext;
17
+        }
18
+
19
+        public List<Email> Get(Func<Email, bool> where)
20
+        {
21
+            return _dbContext.Emails.Where(where).ToList();
22
+        }
23
+
24
+        public List<Email> GetAll()
25
+        {
26
+            return _dbContext.Emails.ToList();
27
+        }
28
+
29
+        public Email GetDetailed(Func<Email, bool> first)
30
+        {
31
+            var item = _dbContext.Emails.FirstOrDefault(first);
32
+            SMTPAccountRepository account = new SMTPAccountRepository(_dbContext);
33
+            item = GetDetailedObject(item, account);
34
+            return item;
35
+        }
36
+
37
+        private Email GetDetailedObject(Email item, SMTPAccountRepository repo)
38
+        {
39
+            item.Sender = repo.GetDetailed(x => x.Id == item.SenderId);
40
+            return item;
41
+        }
42
+
43
+        public List<Email> GetDetailedAll()
44
+        {
45
+            var list = GetAll();
46
+            SMTPAccountRepository account = new SMTPAccountRepository(_dbContext);
47
+            foreach (var item in list)
48
+            {
49
+                item.Sender = account.GetDetailed(x => x.Id == item.SenderId);
50
+            }
51
+            return list;
52
+        }
53
+
54
+        public void Insert(Email item)
55
+        {
56
+            SMTPAccountRepository account = new SMTPAccountRepository(_dbContext);
57
+            item = GetDetailedObject(item, account);
58
+            item.SendMail();
59
+            _dbContext.Add(item);
60
+            Save();
61
+        }
62
+
63
+        public void Insert(IEnumerable<Email> items)
64
+        {
65
+            foreach (var item in items)
66
+            {
67
+                item.SendMail();
68
+                _dbContext.Add(item);
69
+            }
70
+            Save();
71
+        }
72
+
73
+        public void Remove(Email item)
74
+        {
75
+            var i = _dbContext.Emails.Find(item);
76
+            _dbContext.Emails.Remove(i);
77
+            Save();
78
+        }
79
+
80
+        public void Remove(IEnumerable<Email> items)
81
+        {
82
+            foreach (var item in items)
83
+            {
84
+                Email i = _dbContext.Emails.Find(item);
85
+                _dbContext.Emails.Remove(i);
86
+            }
87
+            Save();
88
+        }
89
+
90
+        public void RemoveAtId(int item)
91
+        {
92
+            var i = _dbContext.Emails.Find(item);
93
+            _dbContext.Emails.Remove(i);
94
+            Save();
95
+        }
96
+
97
+        public void Update(Email item)
98
+        {
99
+            _dbContext.Entry(item).State = EntityState.Modified;
100
+            Save();
101
+        }
102
+
103
+        public void Save()
104
+        {
105
+            _dbContext.SaveChanges();
106
+        }
107
+    }
108
+}

+ 98
- 0
UnivateProperties_API/Repository/Communication/SMTPAccountRepository.cs Vedi File

@@ -0,0 +1,98 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Communication;
7
+
8
+namespace UnivateProperties_API.Repository.Communication
9
+{
10
+    public class SMTPAccountRepository : IRepository<SMTPAccount>
11
+    {
12
+        private readonly DataContext _dbContext;
13
+
14
+        public SMTPAccountRepository(DataContext dbContext)
15
+        {
16
+            _dbContext = dbContext;
17
+        }
18
+
19
+        public List<SMTPAccount> Get(Func<SMTPAccount, bool> where)
20
+        {
21
+            return _dbContext.Accounts.Where(where).ToList();
22
+        }
23
+
24
+        public List<SMTPAccount> GetAll()
25
+        {
26
+            return _dbContext.Accounts.ToList();
27
+        }
28
+
29
+        public SMTPAccount GetDetailed(Func<SMTPAccount, bool> first)
30
+        {
31
+            var item = _dbContext.Accounts.FirstOrDefault(first);
32
+            SMTPHostRepository host = new SMTPHostRepository(_dbContext);
33
+            item.SMTPHost = host.GetDetailed(x => x.Id == item.SMTPHostId);
34
+            return item;
35
+        }
36
+
37
+        public List<SMTPAccount> GetDetailedAll()
38
+        {
39
+            var list = GetAll();
40
+            SMTPHostRepository host = new SMTPHostRepository(_dbContext);
41
+            foreach (var item in list)
42
+            {
43
+                item.SMTPHost = host.GetDetailed(x => x.Id == item.SMTPHostId);
44
+            }
45
+            return list;
46
+        }
47
+
48
+        public void Insert(SMTPAccount item)
49
+        {
50
+            _dbContext.Add(item);
51
+            Save();
52
+        }
53
+
54
+        public void Insert(IEnumerable<SMTPAccount> items)
55
+        {
56
+            foreach (var item in items)
57
+            {
58
+                _dbContext.Add(item);
59
+            }
60
+            Save();
61
+        }
62
+
63
+        public void Remove(SMTPAccount item)
64
+        {
65
+            var i = _dbContext.Accounts.Find(item);
66
+            _dbContext.Accounts.Remove(i);
67
+            Save();
68
+        }
69
+
70
+        public void Remove(IEnumerable<SMTPAccount> items)
71
+        {
72
+            foreach (var item in items)
73
+            {
74
+                SMTPAccount i = _dbContext.Accounts.Find(item);
75
+                _dbContext.Accounts.Remove(i);
76
+            }
77
+            Save();
78
+        }
79
+
80
+        public void RemoveAtId(int item)
81
+        {
82
+            var i = _dbContext.Accounts.Find(item);
83
+            _dbContext.Accounts.Remove(i);
84
+            Save();
85
+        }
86
+
87
+        public void Update(SMTPAccount item)
88
+        {
89
+            _dbContext.Entry(item).State = EntityState.Modified;
90
+            Save();
91
+        }
92
+
93
+        public void Save()
94
+        {
95
+            _dbContext.SaveChanges();
96
+        }
97
+    }
98
+}

+ 89
- 0
UnivateProperties_API/Repository/Communication/SMTPHostRepository.cs Vedi File

@@ -0,0 +1,89 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Communication;
7
+
8
+namespace UnivateProperties_API.Repository.Communication
9
+{
10
+    public class SMTPHostRepository : IRepository<SMTPHost>
11
+    {
12
+        private readonly DataContext _dbContext;
13
+
14
+        public SMTPHostRepository(DataContext dbContext)
15
+        {
16
+            _dbContext = dbContext;
17
+        }
18
+
19
+        public List<SMTPHost> Get(Func<SMTPHost, bool> where)
20
+        {
21
+            return _dbContext.Hosts.Where(where).ToList();
22
+        }
23
+
24
+        public List<SMTPHost> GetAll()
25
+        {
26
+            return _dbContext.Hosts.ToList();
27
+        }
28
+
29
+        public SMTPHost GetDetailed(Func<SMTPHost, bool> first)
30
+        {
31
+            return _dbContext.Hosts.FirstOrDefault(first);
32
+        }
33
+
34
+        public List<SMTPHost> GetDetailedAll()
35
+        {
36
+            return GetAll();
37
+        }
38
+
39
+        public void Insert(SMTPHost item)
40
+        {
41
+            _dbContext.Add(item);
42
+            Save();
43
+        }
44
+
45
+        public void Insert(IEnumerable<SMTPHost> items)
46
+        {
47
+            foreach (var item in items)
48
+            {
49
+                _dbContext.Add(item);
50
+            }
51
+            Save();
52
+        }
53
+
54
+        public void Remove(SMTPHost item)
55
+        {
56
+            var i = _dbContext.Hosts.Find(item);
57
+            _dbContext.Hosts.Remove(i);
58
+            Save();
59
+        }
60
+
61
+        public void Remove(IEnumerable<SMTPHost> items)
62
+        {
63
+            foreach (var item in items)
64
+            {
65
+                SMTPHost i = _dbContext.Hosts.Find(item);
66
+                _dbContext.Hosts.Remove(i);
67
+            }
68
+            Save();
69
+        }
70
+
71
+        public void RemoveAtId(int item)
72
+        {
73
+            var i = _dbContext.Hosts.Find(item);
74
+            _dbContext.Hosts.Remove(i);
75
+            Save();
76
+        }
77
+
78
+        public void Update(SMTPHost item)
79
+        {
80
+            _dbContext.Entry(item).State = EntityState.Modified;
81
+            Save();
82
+        }
83
+
84
+        public void Save()
85
+        {
86
+            _dbContext.SaveChanges();
87
+        }
88
+    }
89
+}

+ 21
- 0
UnivateProperties_API/Repository/IRepository.cs Vedi File

@@ -0,0 +1,21 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using UnivateProperties_API.Model.Users;
4
+
5
+namespace UnivateProperties_API.Repository
6
+{
7
+    public interface IRepository<TEntity> where TEntity : class
8
+    {
9
+        List<TEntity> GetAll();
10
+        List<TEntity> Get(Func<TEntity, bool> where);
11
+        TEntity GetDetailed(Func<TEntity, bool> first);
12
+        List<TEntity> GetDetailedAll();
13
+        void Insert(TEntity item);
14
+        void Insert(IEnumerable<TEntity> items);
15
+        void Remove(TEntity item);
16
+        void Remove(IEnumerable<TEntity> items);
17
+        void RemoveAtId(int item);
18
+        void Update(TEntity item);
19
+        void Save();
20
+    }
21
+}

+ 10
- 0
UnivateProperties_API/Repository/Properties/IPropertyImageRepository.cs Vedi File

@@ -0,0 +1,10 @@
1
+using System.Collections.Generic;
2
+using UnivateProperties_API.Model.Property;
3
+
4
+namespace UnivateProperties_API.Repository.Properties
5
+{
6
+    public interface IPropertyImageRepository : IRepository<PropertyImage>
7
+    {
8
+        List<string> GetImages(int PropertyId);
9
+    }
10
+}

+ 15
- 0
UnivateProperties_API/Repository/Properties/IPropertyRepository.cs Vedi File

@@ -0,0 +1,15 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using UnivateProperties_API.Containers.Property;
4
+using UnivateProperties_API.Model.Property;
5
+
6
+namespace UnivateProperties_API.Repository.Properties
7
+{
8
+    public interface IPropertyRepository : IRepository<Property>
9
+    {
10
+        List<PropertyDisplay> GetDisplay();
11
+        List<PropertyDisplay> GetDisplay(Func<Property, bool> where);
12
+        List<PropertyDisplay> GetDisplay(string Keyword);
13
+        List<PropertyDisplay> GetDisplay(string type, string propertyType, string province, string city, string suburb, string propType);
14
+    }
15
+}

+ 13
- 0
UnivateProperties_API/Repository/Properties/IUserDefinedGroupRepository.cs Vedi File

@@ -0,0 +1,13 @@
1
+using System.Collections.Generic;
2
+using UnivateProperties_API.Containers.Property;
3
+using UnivateProperties_API.Model.Property;
4
+
5
+namespace UnivateProperties_API.Repository.Properties
6
+{
7
+    public interface IUserDefinedGroupRepository : IRepository<UserDefinedGroup>
8
+    {
9
+        List<Group> GetFieldList(string name);
10
+
11
+        List<Group> GetFieldListByPropType(string propertyType);
12
+    }
13
+}

+ 98
- 0
UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs Vedi File

@@ -0,0 +1,98 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Property;
7
+
8
+namespace UnivateProperties_API.Repository.Properties
9
+{
10
+    public class PropertyImageRepository : IPropertyImageRepository
11
+    {
12
+        private readonly DataContext dBContext;
13
+
14
+        public PropertyImageRepository(DataContext _dBContext)
15
+        {
16
+            dBContext = _dBContext;
17
+        }
18
+        public List<PropertyImage> Get(Func<PropertyImage, bool> where)
19
+        {
20
+            return dBContext.PropertyImages.Where(where).ToList();
21
+        }
22
+
23
+        public List<PropertyImage> GetAll()
24
+        {
25
+            return dBContext.PropertyImages.ToList();
26
+        }
27
+
28
+        public PropertyImage GetDetailed(Func<PropertyImage, bool> first)
29
+        {
30
+            return dBContext.PropertyImages.FirstOrDefault(first);
31
+        }
32
+
33
+        public List<PropertyImage> GetDetailedAll()
34
+        {
35
+            throw new NotImplementedException();
36
+        }
37
+
38
+        public List<string> GetImages(int PropertyId)
39
+        {
40
+            var images = (from p in dBContext.PropertyImages
41
+                          where p.PropertyId == PropertyId
42
+                          select p.Image).ToList();
43
+
44
+            return images;
45
+        }
46
+
47
+        public void Insert(PropertyImage item)
48
+        {
49
+            dBContext.PropertyImages.Add(item);
50
+            Save();
51
+        }
52
+
53
+        public void Insert(IEnumerable<PropertyImage> items)
54
+        {
55
+            foreach (var item in items)
56
+            {
57
+                dBContext.PropertyImages.Add(item);
58
+            }
59
+            Save();
60
+        }
61
+
62
+        public void Remove(PropertyImage item)
63
+        {
64
+            dBContext.PropertyImages.Remove(item);
65
+            Save();
66
+        }
67
+
68
+        public void Remove(IEnumerable<PropertyImage> items)
69
+        {
70
+            foreach (var item in items)
71
+            {
72
+                dBContext.PropertyImages.Remove(item);
73
+            }
74
+            Save();
75
+        }
76
+
77
+        public void RemoveAtId(int item)
78
+        {
79
+            var image = Get(x => x.Id == item).FirstOrDefault();
80
+            if (image != null)
81
+            {
82
+                dBContext.PropertyImages.Remove(image);
83
+                Save();
84
+            }
85
+        }
86
+
87
+        public void Save()
88
+        {
89
+            dBContext.SaveChanges();
90
+        }
91
+
92
+        public void Update(PropertyImage item)
93
+        {
94
+            dBContext.Entry(item).State = EntityState.Modified;
95
+            Save();
96
+        }
97
+    }
98
+}

+ 340
- 0
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Vedi File

@@ -0,0 +1,340 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Containers.Property;
6
+using UnivateProperties_API.Context;
7
+using UnivateProperties_API.Model.Property;
8
+
9
+namespace UnivateProperties_API.Repository.Properties
10
+{
11
+    public class PropertyRepository : IPropertyRepository
12
+    {
13
+        private readonly DataContext dBContext;
14
+
15
+        public PropertyRepository(DataContext _dBContext)
16
+        {
17
+            dBContext = _dBContext;
18
+        }
19
+
20
+        public List<Property> Get(Func<Property, bool> where)
21
+        {
22
+            return dBContext.Properties.Where(where).ToList();
23
+        }
24
+
25
+        public List<Property> GetAll()
26
+        {
27
+            var properties = dBContext.Properties.ToList();
28
+            return properties;
29
+        }
30
+
31
+        public Property GetDetailed(Func<Property, bool> first)
32
+        {
33
+            var property = dBContext.Properties.FirstOrDefault(first);
34
+            if (property != null)
35
+            {
36
+                GetDetail(ref property);
37
+            }
38
+            return property;
39
+        }
40
+
41
+        public List<Property> GetDetailedAll()
42
+        {
43
+            var properties = dBContext.Properties.ToList();
44
+            return properties;
45
+        }
46
+
47
+        private void GetDetail(ref Property property)
48
+        {
49
+            int propID = property.Id;
50
+            var propertyType = dBContext.PropertyTypes.Find(property.PropertyTypeId);
51
+            property.Province = dBContext.Provinces.Find(property.ProvinceId);
52
+            property.City = dBContext.Cities.Find(property.CityId);
53
+            property.Suburb = dBContext.Suburbs.Find(property.SuburbId);
54
+            property.DisplayData = new List<PropertyDetailGroup>();
55
+
56
+            var groups = (from g in dBContext.UserDefinedGroups
57
+                          where g.UsageType == propertyType.UsageType
58
+                          || g.UsageType == PropertyUsageType.Both
59
+                          orderby g.Rank
60
+                          select g).ToList();
61
+
62
+            foreach (UserDefinedGroup uGroup in groups)
63
+            {
64
+                var groupFields = (from f in dBContext.PropertyUserFields
65
+                                   join uf in dBContext.UserDefinedFields on f.UserDefinedFieldId equals uf.Id
66
+                                   join g in dBContext.UserDefinedGroups on uf.GroupId equals g.Id
67
+                                   where f.PropertyId == propID
68
+                                   && g.Id == uGroup.Id
69
+                                   orderby g.Rank, uf.Rank
70
+                                   select new { uf.FieldName, f.Value, f.Description }).ToList();
71
+
72
+                if (groupFields.Count > 0)
73
+                {
74
+                    PropertyDetailGroup detailGroup = new PropertyDetailGroup()
75
+                    {
76
+                        GroupName = uGroup.Description,
77
+                        Values = new List<PropertyDetail>()
78
+                    };
79
+
80
+                    if (uGroup.Description == "Property Overview")
81
+                    {
82
+                        detailGroup.Values.Add(new PropertyDetail()
83
+                        {
84
+                            Name = "Property Type",
85
+                            Value = property.PropertyType.Description
86
+                        });
87
+                    }
88
+
89
+                    foreach (var val in groupFields)
90
+                    {
91
+                        var irem = new PropertyDetail()
92
+                        {
93
+                            Name = val.FieldName,
94
+                            Description = val.Description
95
+                        };
96
+
97
+                        detailGroup.Values.Add(irem);
98
+
99
+                        if ((val.FieldName == "Erf Size" || val.FieldName == "Floor Size") && val.Value.EndsWith("2"))
100
+                        {
101
+                            irem.Value = val.Value.Substring(0, val.Value.Length - 1) + "<sup>" + val.Value.Last() + "</sup>";
102
+                        }
103
+                        else
104
+                            irem.Value = val.Value;
105
+                    }
106
+
107
+                    property.DisplayData.Add(detailGroup);
108
+                }
109
+            }
110
+        }
111
+
112
+        public void Insert(Property item)
113
+        {
114
+            PropertyType pt = dBContext.PropertyTypes.Find(item.PropertyTypeId);
115
+            if (pt != null)
116
+            {
117
+                if (pt.UsageType == PropertyUsageType.Residential)
118
+                {
119
+                    if (item.PropertyUserFields.Count > 0)
120
+                    {
121
+                        string shortDesc = "{0} {1} {2}";
122
+                        string type = dBContext.PropertyTypes.Find(item.PropertyTypeId).Description;
123
+                        UserDefinedField bedrooms = dBContext.UserDefinedFields.Where(u => u.FieldName == "Bedrooms").FirstOrDefault();
124
+                        var udValue = item.PropertyUserFields.Where(u => u.UserDefinedFieldId == bedrooms.Id).FirstOrDefault();
125
+                        if (udValue != null)
126
+                            item.ShortDescription = string.Format(shortDesc, udValue.Value, "Bedroom", pt.Description).Trim();
127
+                        else
128
+                            item.ShortDescription = string.Format(shortDesc, "", "", pt.Description).Trim();
129
+                    }
130
+                }
131
+                else
132
+                {
133
+                    item.ShortDescription = pt.Description;
134
+                }
135
+            }
136
+
137
+            dBContext.Properties.Add(item);
138
+            Save();
139
+        }
140
+
141
+        public void Insert(IEnumerable<Property> items)
142
+        {
143
+            foreach (var item in items)
144
+            {
145
+                dBContext.Properties.Add(item);
146
+            }
147
+            Save();
148
+        }
149
+
150
+        public void Remove(Property item)
151
+        {
152
+            dBContext.Properties.Remove(item);
153
+            Save();
154
+        }
155
+
156
+        public void Remove(IEnumerable<Property> items)
157
+        {
158
+            foreach (var item in items)
159
+            {
160
+                dBContext.Properties.Remove(item);
161
+            }
162
+            Save();
163
+        }
164
+
165
+        public void RemoveAtId(int item)
166
+        {
167
+            var property = Get(x => x.Id == item).FirstOrDefault();
168
+            if (property != null)
169
+            {
170
+                dBContext.Properties.Remove(property);
171
+                Save();
172
+            }
173
+        }
174
+
175
+        public void Save()
176
+        {
177
+            dBContext.SaveChanges();
178
+        }
179
+
180
+        public void Update(Property item)
181
+        {
182
+            dBContext.Entry(item).State = EntityState.Modified;
183
+            Save();
184
+        }
185
+
186
+        public List<PropertyDisplay> GetDisplay()
187
+        {
188
+            List<Property> props = GetAll();
189
+            return GetDisplayDetails(props);
190
+        }
191
+
192
+        public List<PropertyDisplay> GetDisplay(Func<Property, bool> where)
193
+        {
194
+            List<Property> props;
195
+            if (where != null)
196
+                props = Get(where);
197
+            else
198
+                props = GetAll();
199
+
200
+            return GetDisplayDetails(props);
201
+        }
202
+
203
+        public List<PropertyDisplay> GetDisplay(string Keyword)
204
+        {
205
+            Keyword = Keyword.ToLower();
206
+
207
+            List<Property> props = (from p in dBContext.Properties
208
+                                    join pr in dBContext.Provinces on p.ProvinceId equals pr.Id
209
+                                    join c in dBContext.Cities on p.CityId equals c.Id
210
+                                    join s in dBContext.Suburbs on p.SuburbId equals s.Id
211
+                                    join pt in dBContext.PropertyTypes on p.PropertyTypeId equals pt.Id
212
+                                    where EF.Functions.Like(p.PropertyName.ToLower(), $"%{Keyword}%")
213
+                                    || EF.Functions.Like(pr.Description.ToLower(), $"%{Keyword}%")
214
+                                    || EF.Functions.Like(c.Description.ToLower(), $"%{Keyword}%")
215
+                                    || EF.Functions.Like(s.Description.ToLower(), $"%{Keyword}%")
216
+                                    || EF.Functions.Like(pt.Description.ToLower(), $"%{Keyword}%")
217
+                                    select p).ToList();
218
+
219
+            return GetDisplayDetails(props);
220
+        }
221
+
222
+        public List<PropertyDisplay> GetDisplay(string type, string propertyType, string province, string city, string suburb, string propType)
223
+        {
224
+            List<Property> props;
225
+            PropertyUsageType uType = PropertyUsageType.Both;
226
+
227
+            if (propertyType != "" && propertyType != "undefined")
228
+            {
229
+                if (propertyType.ToUpper() == "COMMERCIAL")
230
+                    uType = PropertyUsageType.Commercial;
231
+                else
232
+                    uType = PropertyUsageType.Residential;
233
+            }
234
+            props = (from p in dBContext.Properties
235
+                     join pt in dBContext.PropertyTypes on p.PropertyTypeId equals pt.Id
236
+                     where pt.UsageType == uType
237
+                     select p).ToList();
238
+
239
+            if (type != "" && type != "undefined")
240
+            {
241
+                if (type.ToUpper() == "SALE")
242
+                    props = props.Where(p => p.IsSale).ToList();
243
+                else
244
+                    props = props.Where(p => !p.IsSale).ToList();
245
+            }
246
+
247
+            if (province != "" && province != "undefined" && province.ToUpper() != "ALL")
248
+            {
249
+                props = (from p in props
250
+                         join pp in dBContext.Provinces on p.ProvinceId equals pp.Id
251
+                         where pp.Description.ToUpper() == province.ToUpper()
252
+                         select p).ToList();
253
+            }
254
+
255
+            if (city != "" && city != "undefined" && city.ToUpper() != "ALL")
256
+            {
257
+                props = (from p in props
258
+                         join c in dBContext.Cities on p.CityId equals c.Id
259
+                         where c.Description.ToUpper() == city.ToUpper()
260
+                         select p).ToList();
261
+            }
262
+
263
+            if (suburb != "" && suburb != "undefined" && suburb.ToUpper() != "ALL")
264
+            {
265
+                props = (from p in props
266
+                         join s in dBContext.Suburbs on p.SuburbId equals s.Id
267
+                         where s.Description.ToUpper() == suburb.ToUpper()
268
+                         select p).ToList();
269
+            }
270
+            if (propType != "" && propType != "Undefined" && propType.ToUpper() != "ALL")
271
+            {
272
+                var pType = dBContext.PropertyTypes.Where(t => t.Description == propType).FirstOrDefault();
273
+                if (pType != null)
274
+                {
275
+                    props = props.Where(p => p.PropertyTypeId == pType.Id).ToList();
276
+                }
277
+            }
278
+
279
+            return GetDisplayDetails(props);
280
+        }
281
+
282
+        private List<PropertyDisplay> GetDisplayDetails(List<Property> props)
283
+        {
284
+            var properties = new List<PropertyDisplay>();
285
+            foreach (var item in props)
286
+            {
287
+                PropertyDisplay display = new PropertyDisplay
288
+                {
289
+                    Id = item.Id,
290
+                    ShortDescription = item.ShortDescription,
291
+                    IsSale = item.IsSale,
292
+                    DisplayPrice = string.Format("R {0}", item.Price.ToString("N0")),
293
+                    DisplayImage = (from i in dBContext.PropertyImages
294
+                                    where i.PropertyId == item.Id
295
+                                    && i.IsDefault
296
+                                    select i.Image).FirstOrDefault(),
297
+                    Area = (from u in dBContext.PropertyUserFields
298
+                            join f in dBContext.UserDefinedFields on u.UserDefinedFieldId equals f.Id
299
+                            where u.PropertyId == item.Id
300
+                            && f.FieldName == "Floor Size"
301
+                            select u.Value).FirstOrDefault(),
302
+                    Beds = (from u in dBContext.PropertyUserFields
303
+                            join f in dBContext.UserDefinedFields on u.UserDefinedFieldId equals f.Id
304
+                            where u.PropertyId == item.Id
305
+                            && f.FieldName == "Bedrooms"
306
+                            select u.Value).FirstOrDefault(),
307
+                    Baths = (from u in dBContext.PropertyUserFields
308
+                             join f in dBContext.UserDefinedFields on u.UserDefinedFieldId equals f.Id
309
+                             where u.PropertyId == item.Id
310
+                             && f.FieldName == "Bathrooms"
311
+                             select u.Value).FirstOrDefault(),
312
+                    Garages = (from u in dBContext.PropertyUserFields
313
+                               join f in dBContext.UserDefinedFields on u.UserDefinedFieldId equals f.Id
314
+                               where u.PropertyId == item.Id
315
+                               && f.FieldName == "Garages"
316
+                               select u.Value).FirstOrDefault(),
317
+                    Province = (from p in dBContext.Provinces
318
+                                where p.Id == item.ProvinceId
319
+                                select p.Description).FirstOrDefault(),
320
+                    City = (from c in dBContext.Cities
321
+                            where c.Id == item.CityId
322
+                            select c.Description).FirstOrDefault(),
323
+                    Suburb = (from s in dBContext.Suburbs
324
+                              where s.Id == item.SuburbId
325
+                              select s.Description).FirstOrDefault()
326
+
327
+                };
328
+
329
+                if (!string.IsNullOrEmpty(display.Area) && display.Area.EndsWith("2"))
330
+                {
331
+                    display.Area = display.Area.Substring(0, display.Area.Length - 1) + "<sup>" + display.Area.Last() + "</sup>";
332
+                }
333
+
334
+                properties.Add(display);
335
+            }
336
+
337
+            return properties;
338
+        }
339
+    }
340
+}

+ 90
- 0
UnivateProperties_API/Repository/Properties/PropertyTypeRepository.cs Vedi File

@@ -0,0 +1,90 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Property;
7
+
8
+namespace UnivateProperties_API.Repository.Properties
9
+{
10
+    public class PropertyTypeRepository : IRepository<PropertyType>
11
+    {
12
+        private readonly DataContext dBContext;
13
+
14
+        public PropertyTypeRepository(DataContext _dBContext)
15
+        {
16
+            dBContext = _dBContext;
17
+        }
18
+
19
+        public List<PropertyType> Get(Func<PropertyType, bool> where)
20
+        {
21
+            return dBContext.PropertyTypes.Where(where).ToList();
22
+        }
23
+
24
+        public List<PropertyType> GetAll()
25
+        {
26
+            return dBContext.PropertyTypes.ToList();
27
+        }
28
+
29
+        public PropertyType GetDetailed(Func<PropertyType, bool> first)
30
+        {
31
+            return dBContext.PropertyTypes.FirstOrDefault(first);
32
+        }
33
+
34
+        public List<PropertyType> GetDetailedAll()
35
+        {
36
+            return dBContext.PropertyTypes.ToList();
37
+        }
38
+
39
+        public void Insert(PropertyType item)
40
+        {
41
+            dBContext.PropertyTypes.Add(item);
42
+            Save();
43
+        }
44
+
45
+        public void Insert(IEnumerable<PropertyType> items)
46
+        {
47
+            foreach (var item in items)
48
+            {
49
+                dBContext.PropertyTypes.Add(item);
50
+                Save();
51
+            }
52
+        }
53
+
54
+        public void Remove(PropertyType item)
55
+        {
56
+            dBContext.PropertyTypes.Remove(item);
57
+            Save();
58
+        }
59
+
60
+        public void Remove(IEnumerable<PropertyType> items)
61
+        {
62
+            foreach (var item in items)
63
+            {
64
+                dBContext.PropertyTypes.Remove(item);
65
+                Save();
66
+            }
67
+        }
68
+
69
+        public void RemoveAtId(int item)
70
+        {
71
+            var propertyType = Get(x => x.Id == item).FirstOrDefault();
72
+            if (propertyType != null)
73
+            {
74
+                dBContext.PropertyTypes.Remove(propertyType);
75
+                Save();
76
+            }
77
+        }
78
+
79
+        public void Save()
80
+        {
81
+            dBContext.SaveChanges();
82
+        }
83
+
84
+        public void Update(PropertyType item)
85
+        {
86
+            dBContext.Entry(item).State = EntityState.Modified;
87
+            Save();
88
+        }
89
+    }
90
+}

+ 90
- 0
UnivateProperties_API/Repository/Properties/PropertyUserFieldRepository.cs Vedi File

@@ -0,0 +1,90 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Property;
7
+
8
+namespace UnivateProperties_API.Repository.Properties
9
+{
10
+    public class PropertyUserFieldRepository : IRepository<PropertyUserField>
11
+    {
12
+        private readonly DataContext dBContext;
13
+
14
+        public PropertyUserFieldRepository(DataContext _dBContext)
15
+        {
16
+            dBContext = _dBContext;
17
+        }
18
+
19
+        public List<PropertyUserField> Get(Func<PropertyUserField, bool> where)
20
+        {
21
+            return dBContext.PropertyUserFields.Where(where).ToList();
22
+        }
23
+
24
+        public List<PropertyUserField> GetAll()
25
+        {
26
+            return dBContext.PropertyUserFields.ToList();
27
+        }
28
+
29
+        public PropertyUserField GetDetailed(Func<PropertyUserField, bool> first)
30
+        {
31
+            return dBContext.PropertyUserFields.FirstOrDefault(first);
32
+        }
33
+
34
+        public List<PropertyUserField> GetDetailedAll()
35
+        {
36
+            return dBContext.PropertyUserFields.ToList();
37
+        }
38
+
39
+        public void Insert(PropertyUserField item)
40
+        {
41
+            dBContext.PropertyUserFields.Add(item);
42
+            Save();
43
+        }
44
+
45
+        public void Insert(IEnumerable<PropertyUserField> items)
46
+        {
47
+            foreach (var item in items)
48
+            {
49
+                dBContext.PropertyUserFields.Add(item);
50
+                Save();
51
+            }
52
+        }
53
+
54
+        public void Remove(PropertyUserField item)
55
+        {
56
+            dBContext.PropertyUserFields.Remove(item);
57
+            Save();
58
+        }
59
+
60
+        public void Remove(IEnumerable<PropertyUserField> items)
61
+        {
62
+            foreach (var item in items)
63
+            {
64
+                dBContext.PropertyUserFields.Remove(item);
65
+                Save();
66
+            }
67
+        }
68
+
69
+        public void RemoveAtId(int item)
70
+        {
71
+            var propertyUserField = Get(x => x.Id == item).FirstOrDefault();
72
+            if (propertyUserField != null)
73
+            {
74
+                dBContext.PropertyUserFields.Remove(propertyUserField);
75
+                Save();
76
+            }
77
+        }
78
+
79
+        public void Save()
80
+        {
81
+            dBContext.SaveChanges();
82
+        }
83
+
84
+        public void Update(PropertyUserField item)
85
+        {
86
+            dBContext.Entry(item).State = EntityState.Modified;
87
+            Save();
88
+        }
89
+    }
90
+}

+ 90
- 0
UnivateProperties_API/Repository/Properties/UserDefinedFieldRepository.cs Vedi File

@@ -0,0 +1,90 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Property;
7
+
8
+namespace UnivateProperties_API.Repository.Properties
9
+{
10
+    public class UserDefinedFieldRepository : IRepository<UserDefinedField>
11
+    {
12
+        private readonly DataContext dBContext;
13
+
14
+        public UserDefinedFieldRepository(DataContext _dBContext)
15
+        {
16
+            dBContext = _dBContext;
17
+        }
18
+
19
+        public List<UserDefinedField> Get(Func<UserDefinedField, bool> where)
20
+        {
21
+            return dBContext.UserDefinedFields.Where(where).ToList();
22
+        }
23
+
24
+        public List<UserDefinedField> GetAll()
25
+        {
26
+            return dBContext.UserDefinedFields.ToList();
27
+        }
28
+
29
+        public UserDefinedField GetDetailed(Func<UserDefinedField, bool> first)
30
+        {
31
+            return dBContext.UserDefinedFields.FirstOrDefault(first);
32
+        }
33
+
34
+        public List<UserDefinedField> GetDetailedAll()
35
+        {
36
+            return dBContext.UserDefinedFields.ToList();
37
+        }
38
+
39
+        public void Insert(UserDefinedField item)
40
+        {
41
+            dBContext.UserDefinedFields.Add(item);
42
+            Save();
43
+        }
44
+
45
+        public void Insert(IEnumerable<UserDefinedField> items)
46
+        {
47
+            foreach (var item in items)
48
+            {
49
+                dBContext.UserDefinedFields.Add(item);
50
+                Save();
51
+            }
52
+        }
53
+
54
+        public void Remove(UserDefinedField item)
55
+        {
56
+            dBContext.UserDefinedFields.Remove(item);
57
+            Save();
58
+        }
59
+
60
+        public void Remove(IEnumerable<UserDefinedField> items)
61
+        {
62
+            foreach (var item in items)
63
+            {
64
+                dBContext.UserDefinedFields.Add(item);
65
+                Save();
66
+            }
67
+        }
68
+
69
+        public void RemoveAtId(int item)
70
+        {
71
+            var userDefinedField = Get(x => x.Id == item).FirstOrDefault();
72
+            if (userDefinedField != null)
73
+            {
74
+                dBContext.UserDefinedFields.Remove(userDefinedField);
75
+                Save();
76
+            }
77
+        }
78
+
79
+        public void Save()
80
+        {
81
+            dBContext.SaveChanges();
82
+        }
83
+
84
+        public void Update(UserDefinedField item)
85
+        {
86
+            dBContext.Entry(item).State = EntityState.Modified;
87
+            Save();
88
+        }
89
+    }
90
+}

+ 174
- 0
UnivateProperties_API/Repository/Properties/UserDefinedGroupRepository.cs Vedi File

@@ -0,0 +1,174 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Containers.Property;
6
+using UnivateProperties_API.Context;
7
+using UnivateProperties_API.Model.Property;
8
+
9
+namespace UnivateProperties_API.Repository.Properties
10
+{
11
+    public class UserDefinedGroupRepository : IUserDefinedGroupRepository
12
+    {
13
+        private readonly DataContext dBContext;
14
+
15
+        public UserDefinedGroupRepository(DataContext _dBContext)
16
+        {
17
+            dBContext = _dBContext;
18
+        }
19
+
20
+        public List<UserDefinedGroup> Get(Func<UserDefinedGroup, bool> where)
21
+        {
22
+            return dBContext.UserDefinedGroups.Where(where).ToList();
23
+        }
24
+
25
+        public List<UserDefinedGroup> GetAll()
26
+        {
27
+            return dBContext.UserDefinedGroups.ToList();
28
+        }
29
+
30
+        public UserDefinedGroup GetDetailed(Func<UserDefinedGroup, bool> first)
31
+        {
32
+            return dBContext.UserDefinedGroups.FirstOrDefault(first);
33
+        }
34
+
35
+        public List<UserDefinedGroup> GetDetailedAll()
36
+        {
37
+            return dBContext.UserDefinedGroups.ToList();
38
+        }
39
+
40
+        public List<Group> GetFieldList(string name)
41
+        {
42
+            List<Group> FieldGroups = new List<Group>();
43
+            List<UserDefinedGroup> Groups;
44
+            if (name == "Property Overview")
45
+                Groups = dBContext.UserDefinedGroups.Where(x => x.Description == "Property Overview").OrderBy(x => x.Rank).ToList();
46
+            else
47
+                Groups = dBContext.UserDefinedGroups.Where(x => x.Description != "Property Overview").OrderBy(x => x.Rank).ToList();
48
+
49
+
50
+            foreach (var group in Groups)
51
+            {
52
+                var fields = dBContext.UserDefinedFields.Where(x => x.GroupId == group.Id).ToList();
53
+                if (fields.Count > 0)
54
+                {
55
+                    var item = new Group()
56
+                    {
57
+                        Name = group.Description,
58
+                        Fields = new List<GroupFields>()
59
+                    };
60
+
61
+                    FieldGroups.Add(item);
62
+
63
+                    foreach (var field in fields)
64
+                    {
65
+                        item.Fields.Add(new GroupFields()
66
+                        {
67
+                            ID = field.Id,
68
+                            Name = field.FieldName,
69
+                            Type = field.FieldType
70
+                        });
71
+                    }
72
+                }
73
+            }
74
+
75
+            return FieldGroups;
76
+        }
77
+
78
+        public List<Group> GetFieldListByPropType(string propertyType)
79
+        {
80
+            List<Group> FieldGroups = new List<Group>();
81
+            List<UserDefinedGroup> Groups;
82
+            PropertyUsageType usageType = PropertyUsageType.Both;
83
+            switch (propertyType.ToUpper())
84
+            {
85
+                case "RESIDENTIAL":
86
+                    usageType = PropertyUsageType.Residential;
87
+                    break;
88
+                case "COMMERCIAL":
89
+                    usageType = PropertyUsageType.Commercial;
90
+                    break;
91
+            }
92
+
93
+            Groups = dBContext.UserDefinedGroups.Where(x => (x.UsageType == usageType || x.UsageType == PropertyUsageType.Both) && x.Description != "Property Overview").OrderBy(x => x.Rank).ToList();
94
+
95
+            foreach (var group in Groups)
96
+            {
97
+                var fields = dBContext.UserDefinedFields.Where(x => x.GroupId == group.Id).ToList();
98
+                if (fields.Count > 0)
99
+                {
100
+                    var item = new Group()
101
+                    {
102
+                        Name = group.Description,
103
+                        Fields = new List<GroupFields>()
104
+                    };
105
+
106
+                    FieldGroups.Add(item);
107
+
108
+                    foreach (var field in fields)
109
+                    {
110
+                        item.Fields.Add(new GroupFields()
111
+                        {
112
+                            ID = field.Id,
113
+                            Name = field.FieldName,
114
+                            Type = field.FieldType
115
+                        });
116
+                    }
117
+                }
118
+            }
119
+
120
+            return FieldGroups;
121
+        }
122
+
123
+        public void Insert(UserDefinedGroup item)
124
+        {
125
+            dBContext.UserDefinedGroups.Add(item);
126
+            Save();
127
+        }
128
+
129
+        public void Insert(IEnumerable<UserDefinedGroup> items)
130
+        {
131
+            foreach (var item in items)
132
+            {
133
+                dBContext.UserDefinedGroups.Add(item);
134
+                Save();
135
+            }
136
+        }
137
+
138
+        public void Remove(UserDefinedGroup item)
139
+        {
140
+            dBContext.UserDefinedGroups.Remove(item);
141
+            Save();
142
+        }
143
+
144
+        public void Remove(IEnumerable<UserDefinedGroup> items)
145
+        {
146
+            foreach (var item in items)
147
+            {
148
+                dBContext.UserDefinedGroups.Remove(item);
149
+                Save();
150
+            }
151
+        }
152
+
153
+        public void RemoveAtId(int item)
154
+        {
155
+            var userDefinedGroups = Get(x => x.Id == item).FirstOrDefault();
156
+            if (userDefinedGroups != null)
157
+            {
158
+                dBContext.UserDefinedGroups.Remove(userDefinedGroups);
159
+                Save();
160
+            }
161
+        }
162
+
163
+        public void Save()
164
+        {
165
+            dBContext.SaveChanges();
166
+        }
167
+
168
+        public void Update(UserDefinedGroup item)
169
+        {
170
+            dBContext.Entry(item).State = EntityState.Modified;
171
+            Save();
172
+        }
173
+    }
174
+}

+ 99
- 0
UnivateProperties_API/Repository/Region/CityRepository.cs Vedi File

@@ -0,0 +1,99 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Region;
7
+
8
+namespace UnivateProperties_API.Repository.Region
9
+{
10
+    public class CityRepository : ICityRepository
11
+    {
12
+        private readonly DataContext dBContext;
13
+
14
+        public CityRepository(DataContext _dBContext)
15
+        {
16
+            dBContext = _dBContext;
17
+        }
18
+
19
+        public List<City> Get(Func<City, bool> where)
20
+        {
21
+            return dBContext.Cities.Where(where).ToList();
22
+        }        
23
+
24
+        public List<City> GetAll()
25
+        {
26
+            return dBContext.Cities.ToList();
27
+        }
28
+
29
+        public List<City> GetBy(string province)
30
+        {
31
+            var provObj = dBContext.Provinces.Where(p => p.Description == province).First();
32
+            if (provObj != null)
33
+                return dBContext.Cities.Where(c => c.ProvinceId == provObj.Id).OrderBy(c => c.Description).ToList();
34
+            else
35
+                return null;
36
+        }
37
+
38
+        public City GetDetailed(Func<City, bool> first)
39
+        {
40
+            throw new NotImplementedException();
41
+        }
42
+
43
+        public List<City> GetDetailedAll()
44
+        {
45
+            throw new NotImplementedException();
46
+        }
47
+
48
+        public void Insert(City item)
49
+        {
50
+            dBContext.Cities.Add(item);
51
+            Save();
52
+        }
53
+
54
+        public void Insert(IEnumerable<City> items)
55
+        {
56
+            foreach (var item in items)
57
+            {
58
+                dBContext.Cities.Add(item);
59
+                Save();
60
+            }
61
+        }
62
+
63
+        public void Remove(City item)
64
+        {
65
+            dBContext.Cities.Remove(item);
66
+            Save();
67
+        }
68
+
69
+        public void Remove(IEnumerable<City> items)
70
+        {
71
+            foreach (var item in items)
72
+            {
73
+                dBContext.Cities.Remove(item);
74
+            }
75
+            Save();
76
+        }
77
+
78
+        public void RemoveAtId(int item)
79
+        {
80
+            var city = Get(x => x.Id == item).FirstOrDefault();
81
+            if (city != null)
82
+            {
83
+                dBContext.Cities.Remove(city);
84
+                Save();
85
+            }
86
+        }
87
+
88
+        public void Save()
89
+        {
90
+            dBContext.SaveChanges();
91
+        }
92
+
93
+        public void Update(City item)
94
+        {
95
+            dBContext.Entry(item).State = EntityState.Modified;
96
+            Save();
97
+        }
98
+    }
99
+}

+ 10
- 0
UnivateProperties_API/Repository/Region/ICityRepository.cs Vedi File

@@ -0,0 +1,10 @@
1
+using System.Collections.Generic;
2
+using UnivateProperties_API.Model.Region;
3
+
4
+namespace UnivateProperties_API.Repository.Region
5
+{
6
+    public interface ICityRepository : IRepository<City>
7
+    {
8
+        List<City> GetBy(string province);
9
+    }
10
+}

+ 10
- 0
UnivateProperties_API/Repository/Region/ISuburbRepository.cs Vedi File

@@ -0,0 +1,10 @@
1
+using System.Collections.Generic;
2
+using UnivateProperties_API.Model.Region;
3
+
4
+namespace UnivateProperties_API.Repository.Region
5
+{
6
+    public interface ISuburbRepository : IRepository<Suburb>
7
+    {
8
+        List<Suburb> GetBy(string province, string city);
9
+    }
10
+}

+ 90
- 0
UnivateProperties_API/Repository/Region/ProvinceRepository.cs Vedi File

@@ -0,0 +1,90 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Region;
7
+
8
+namespace UnivateProperties_API.Repository.Region
9
+{
10
+    public class ProvinceRepository : IRepository<Province>
11
+    {
12
+        private readonly DataContext dBContext;
13
+
14
+        public ProvinceRepository(DataContext _dBContext)
15
+        {
16
+            dBContext = _dBContext;
17
+        }
18
+
19
+        public List<Province> Get(Func<Province, bool> where)
20
+        {
21
+            return dBContext.Provinces.Where(where).ToList();
22
+        }
23
+
24
+        public List<Province> GetAll()
25
+        {
26
+            return dBContext.Provinces.OrderBy(p => p.Description).ToList();
27
+        }
28
+
29
+        public Province GetDetailed(Func<Province, bool> first)
30
+        {
31
+            throw new NotImplementedException();
32
+        }
33
+
34
+        public List<Province> GetDetailedAll()
35
+        {
36
+            throw new NotImplementedException();
37
+        }
38
+
39
+        public void Insert(Province item)
40
+        {
41
+            dBContext.Provinces.Add(item);
42
+            Save();
43
+        }
44
+
45
+        public void Insert(IEnumerable<Province> items)
46
+        {
47
+            foreach (var item in items)
48
+            {
49
+                dBContext.Provinces.Add(item);
50
+                Save();
51
+            }
52
+        }
53
+
54
+        public void Remove(Province item)
55
+        {
56
+            dBContext.Provinces.Remove(item);
57
+            Save();
58
+        }
59
+
60
+        public void Remove(IEnumerable<Province> items)
61
+        {
62
+            foreach (var item in items)
63
+            {
64
+                dBContext.Provinces.Remove(item);
65
+            }
66
+            Save();
67
+        }
68
+
69
+        public void RemoveAtId(int item)
70
+        {
71
+            var province = Get(x => x.Id == item).FirstOrDefault();
72
+            if (province != null)
73
+            {
74
+                dBContext.Provinces.Remove(province);
75
+                Save();
76
+            }
77
+        }
78
+
79
+        public void Save()
80
+        {
81
+            dBContext.SaveChanges();
82
+        }
83
+
84
+        public void Update(Province item)
85
+        {
86
+            dBContext.Entry(item).State = EntityState.Modified;
87
+            Save();
88
+        }
89
+    }
90
+}

+ 100
- 0
UnivateProperties_API/Repository/Region/SuburbRepository.cs Vedi File

@@ -0,0 +1,100 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Region;
7
+
8
+namespace UnivateProperties_API.Repository.Region
9
+{
10
+    public class SuburbRepository : ISuburbRepository
11
+    {
12
+        private readonly DataContext dBContext;
13
+
14
+        public SuburbRepository(DataContext _dBContext)
15
+        {
16
+            dBContext = _dBContext;
17
+        }
18
+
19
+        public List<Suburb> Get(Func<Suburb, bool> where)
20
+        {
21
+            return dBContext.Suburbs.Where(where).ToList();
22
+        }
23
+
24
+        public List<Suburb> GetAll()
25
+        {
26
+            return dBContext.Suburbs.ToList();
27
+        }
28
+
29
+        public List<Suburb> GetBy(string province, string city)
30
+        {
31
+            var provObj = dBContext.Provinces.Where(p => p.Description == province).FirstOrDefault();
32
+            var cityObj = dBContext.Cities.Where(c => c.ProvinceId == provObj.Id && c.Description == city).FirstOrDefault();
33
+            if (cityObj != null)
34
+                return dBContext.Suburbs.Where(s => s.CityId == cityObj.Id).OrderBy(s => s.Description).ToList();
35
+            else
36
+                return null;
37
+        }
38
+
39
+        public Suburb GetDetailed(Func<Suburb, bool> first)
40
+        {
41
+            throw new NotImplementedException();
42
+        }
43
+
44
+        public List<Suburb> GetDetailedAll()
45
+        {
46
+            throw new NotImplementedException();
47
+        }
48
+
49
+        public void Insert(Suburb item)
50
+        {
51
+            dBContext.Suburbs.Add(item);
52
+            Save();
53
+        }
54
+
55
+        public void Insert(IEnumerable<Suburb> items)
56
+        {
57
+            foreach (var item in items)
58
+            {
59
+                dBContext.Suburbs.Add(item);
60
+                Save();
61
+            }
62
+        }
63
+
64
+        public void Remove(Suburb item)
65
+        {
66
+            dBContext.Suburbs.Remove(item);
67
+            Save();
68
+        }
69
+
70
+        public void Remove(IEnumerable<Suburb> items)
71
+        {
72
+            foreach (var item in items)
73
+            {
74
+                dBContext.Suburbs.Remove(item);
75
+            }
76
+            Save();
77
+        }
78
+
79
+        public void RemoveAtId(int item)
80
+        {
81
+            var suburb = Get(x => x.Id == item).FirstOrDefault();
82
+            if (suburb != null)
83
+            {
84
+                dBContext.Suburbs.Remove(suburb);
85
+                Save();
86
+            }
87
+        }
88
+
89
+        public void Save()
90
+        {
91
+            dBContext.SaveChanges();
92
+        }
93
+
94
+        public void Update(Suburb item)
95
+        {
96
+            dBContext.Entry(item).State = EntityState.Modified;
97
+            Save();
98
+        }
99
+    }
100
+}

+ 90
- 0
UnivateProperties_API/Repository/Timeshare/SeasonRepository.cs Vedi File

@@ -0,0 +1,90 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Timeshare;
7
+
8
+namespace UnivateProperties_API.Repository.Timeshare
9
+{
10
+    public class SeasonRepository : IRepository<Season>
11
+    {
12
+        private readonly DataContext _dbContext;
13
+
14
+        public SeasonRepository(DataContext dbContext)
15
+        {
16
+            _dbContext = dbContext;
17
+        }
18
+
19
+        public List<Season> Get(Func<Season, bool> where)
20
+        {
21
+            return _dbContext.Seasons.Where(where).ToList();
22
+        }
23
+
24
+        public List<Season> GetAll()
25
+        {
26
+            return _dbContext.Seasons.ToList();
27
+        }
28
+
29
+        public Season GetDetailed(Func<Season, bool> first)
30
+        {
31
+            var item = _dbContext.Seasons.FirstOrDefault(first);
32
+            return item;
33
+        }
34
+
35
+        public List<Season> GetDetailedAll()
36
+        {
37
+            return GetAll();
38
+        }
39
+
40
+        public void Insert(Season item)
41
+        {
42
+            _dbContext.Add(item);
43
+            Save();
44
+        }
45
+
46
+        public void Insert(IEnumerable<Season> items)
47
+        {
48
+            foreach (var item in items)
49
+            {
50
+                _dbContext.Add(item);
51
+            }
52
+            Save();
53
+        }
54
+
55
+        public void Remove(Season item)
56
+        {
57
+            var i = _dbContext.Seasons.Find(item);
58
+            _dbContext.Seasons.Remove(i);
59
+            Save();
60
+        }
61
+
62
+        public void Remove(IEnumerable<Season> items)
63
+        {
64
+            foreach (var item in items)
65
+            {
66
+                var i = _dbContext.Seasons.Find(item);
67
+                _dbContext.Seasons.Remove(i);
68
+            }
69
+            Save();
70
+        }
71
+
72
+        public void RemoveAtId(int item)
73
+        {
74
+            var i = _dbContext.Seasons.Find(item);
75
+            _dbContext.Seasons.Remove(i);
76
+            Save();
77
+        }
78
+
79
+        public void Save()
80
+        {
81
+            _dbContext.SaveChanges();
82
+        }
83
+
84
+        public void Update(Season item)
85
+        {
86
+            _dbContext.Entry(item).State = EntityState.Modified;
87
+            Save();
88
+        }
89
+    }
90
+}

+ 90
- 0
UnivateProperties_API/Repository/Timeshare/StatusRepository.cs Vedi File

@@ -0,0 +1,90 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Timeshare;
7
+
8
+namespace UnivateProperties_API.Repository.Timeshare
9
+{
10
+    public class StatusRepository : IRepository<Status>
11
+    {
12
+        private readonly DataContext _dbContext;
13
+
14
+        public StatusRepository(DataContext dbContext)
15
+        {
16
+            _dbContext = dbContext;
17
+        }
18
+
19
+        public List<Status> Get(Func<Status, bool> where)
20
+        {
21
+            return _dbContext.Status.Where(where).ToList();
22
+        }
23
+
24
+        public List<Status> GetAll()
25
+        {
26
+            return _dbContext.Status.ToList();
27
+        }
28
+
29
+        public Status GetDetailed(Func<Status, bool> first)
30
+        {
31
+            var item = _dbContext.Status.FirstOrDefault(first);
32
+            return item;
33
+        }
34
+
35
+        public List<Status> GetDetailedAll()
36
+        {
37
+            return GetAll();
38
+        }
39
+
40
+        public void Insert(Status item)
41
+        {
42
+            _dbContext.Add(item);
43
+            Save();
44
+        }
45
+
46
+        public void Insert(IEnumerable<Status> items)
47
+        {
48
+            foreach (var item in items)
49
+            {
50
+                _dbContext.Add(item);
51
+            }
52
+            Save();
53
+        }
54
+
55
+        public void Remove(Status item)
56
+        {
57
+            var i = _dbContext.Status.Find(item);
58
+            _dbContext.Status.Remove(i);
59
+            Save();
60
+        }
61
+
62
+        public void Remove(IEnumerable<Status> items)
63
+        {
64
+            foreach (var item in items)
65
+            {
66
+                var i = _dbContext.Status.Find(item);
67
+                _dbContext.Status.Remove(i);
68
+            }
69
+            Save();
70
+        }
71
+
72
+        public void RemoveAtId(int item)
73
+        {
74
+            var i = _dbContext.Status.Find(item);
75
+            _dbContext.Status.Remove(i);
76
+            Save();
77
+        }
78
+
79
+        public void Save()
80
+        {
81
+            _dbContext.SaveChanges();
82
+        }
83
+
84
+        public void Update(Status item)
85
+        {
86
+            _dbContext.Entry(item).State = EntityState.Modified;
87
+            Save();
88
+        }
89
+    }
90
+}

+ 141
- 0
UnivateProperties_API/Repository/Timeshare/UnitConfigurationRepository.cs Vedi File

@@ -0,0 +1,141 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Containers.Timeshare;
6
+using UnivateProperties_API.Context;
7
+using UnivateProperties_API.Model.Timeshare;
8
+
9
+namespace UnivateProperties_API.Repository.Timeshare
10
+{
11
+    public class UnitConfigurationRepository : IRepository<UnitConfiguration>
12
+    {
13
+        private readonly DataContext _dbContext;
14
+
15
+        public UnitConfigurationRepository(DataContext dbContext)
16
+        {
17
+            _dbContext = dbContext;
18
+        }
19
+
20
+        public List<UnitConfiguration> Get(Func<UnitConfiguration, bool> where)
21
+        {
22
+            return _dbContext.UnitConfigurations.Where(where).ToList();
23
+        }
24
+
25
+        public List<UnitConfigurationType> GetTypes(Func<UnitConfigurationType, bool> where)
26
+        {
27
+            return _dbContext.UnitConfigurationTypes.Where(where).ToList();
28
+        }
29
+
30
+        public List<UnitConfiguration> GetAll()
31
+        {
32
+            return _dbContext.UnitConfigurations.ToList();
33
+        }
34
+
35
+        public UnitConfiguration GetDetailed(Func<UnitConfiguration, bool> first)
36
+        {
37
+            var item = _dbContext.UnitConfigurations.FirstOrDefault(first);
38
+            item.Types = GetTypes(t => t.UnitConfigurationId == item.Id);
39
+            return item;
40
+        }
41
+
42
+        public List<UnitConfigurationDto> GetMyDetailed()
43
+        {
44
+            var list = new List<UnitConfigurationDto>();
45
+            UnitConfigurationDto dto = new UnitConfigurationDto();
46
+
47
+            foreach (var item in GetAll())
48
+            {
49
+                dto = new UnitConfigurationDto()
50
+                {
51
+                    Id = item.Id,
52
+                    Code = item.Code,
53
+                    Bedrooms = item.Bedrooms,
54
+                    Adults = item.Adults,
55
+                    Children = item.Children
56
+                };
57
+                dto.Types = new List<string>();
58
+                foreach (var subItem in GetTypes(t => t.UnitConfigurationId == item.Id))
59
+                {
60
+                    dto.Types.Add(subItem.Description);
61
+                }
62
+                list.Add(dto);
63
+            }
64
+            return list;
65
+        }
66
+
67
+        public List<UnitConfiguration> GetDetailedAll()
68
+        {
69
+            var list = new List<UnitConfiguration>();
70
+            foreach(var item in GetAll())
71
+            {
72
+                item.Types = GetTypes(t => t.UnitConfigurationId == item.Id);
73
+                list.Add(item);
74
+            }
75
+            return list;
76
+        }
77
+
78
+        public void Insert(UnitConfiguration item)
79
+        {
80
+            _dbContext.Add(item);
81
+            Save();
82
+        }
83
+
84
+        public void InsertType(UnitConfigurationType type)
85
+        {
86
+            _dbContext.Add(type);
87
+            Save();
88
+        }
89
+
90
+        public void Insert(IEnumerable<UnitConfiguration> items)
91
+        {
92
+            foreach (var item in items)
93
+            {
94
+                _dbContext.Add(item);
95
+            }
96
+            Save();
97
+        }
98
+
99
+        public void Remove(UnitConfiguration item)
100
+        {
101
+            var i = _dbContext.UnitConfigurations.Find(item);
102
+            _dbContext.UnitConfigurations.Remove(i);
103
+            Save();
104
+        }
105
+
106
+        public void RemoveType(UnitConfigurationType item)
107
+        {
108
+            var i = _dbContext.UnitConfigurationTypes.Find(item);
109
+            _dbContext.UnitConfigurationTypes.Remove(i);
110
+            Save();
111
+        }
112
+
113
+        public void Remove(IEnumerable<UnitConfiguration> items)
114
+        {
115
+            foreach (var item in items)
116
+            {
117
+                var i = _dbContext.UnitConfigurations.Find(item);
118
+                _dbContext.UnitConfigurations.Remove(i);
119
+            }
120
+            Save();
121
+        }
122
+
123
+        public void RemoveAtId(int item)
124
+        {
125
+            var i = _dbContext.UnitConfigurations.Find(item);
126
+            _dbContext.UnitConfigurations.Remove(i);
127
+            Save();
128
+        }
129
+
130
+        public void Save()
131
+        {
132
+            _dbContext.SaveChanges();
133
+        }
134
+
135
+        public void Update(UnitConfiguration item)
136
+        {
137
+            _dbContext.Entry(item).State = EntityState.Modified;
138
+            Save();
139
+        }
140
+    }
141
+}

+ 129
- 0
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs Vedi File

@@ -0,0 +1,129 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Timeshare;
7
+using UnivateProperties_API.Repository.Region;
8
+using UnivateProperties_API.Repository.Users;
9
+
10
+namespace UnivateProperties_API.Repository.Timeshare
11
+{
12
+    public class WeekRepository : IRepository<TimeshareWeek>
13
+    {
14
+        private readonly DataContext _dbContext;
15
+
16
+        public WeekRepository(DataContext dbContext)
17
+        {
18
+            _dbContext = dbContext;
19
+        }
20
+
21
+        public List<TimeshareWeek> Get(Func<TimeshareWeek, bool> where)
22
+        {
23
+            return _dbContext.Weeks.Where(where).ToList();
24
+        }
25
+
26
+        public List<TimeshareWeek> GetAll()
27
+        {
28
+            return _dbContext.Weeks.ToList();
29
+        }
30
+
31
+        private TimeshareWeek GetWeekDetailed(TimeshareWeek week)
32
+        {
33
+            // Get Agent
34
+            if(week.AgentId != 0 && week.Agent == null)
35
+            {
36
+                AgentRepository agentRepo = new AgentRepository(_dbContext);
37
+                week.Agent = agentRepo.GetDetailed(x => x.Id == week.AgentId);
38
+            }
39
+            // Get Agency
40
+            if(week.AgencyId != 0 && week.Agency == null)
41
+            {
42
+                AgencyRepository agencyRepo = new AgencyRepository(_dbContext);
43
+                week.Agency = agencyRepo.GetDetailed(x => x.Id == week.AgencyId);
44
+            }
45
+            // Get Region
46
+            if(week.RegionId != 0 && week.Region == null)
47
+            {
48
+                ProvinceRepository provinceRepo = new ProvinceRepository(_dbContext);
49
+                week.Region = provinceRepo.GetDetailed(x => x.Id == week.RegionId);
50
+            }
51
+            // Get Status
52
+            if(week.StatusId != 0 && week.Status == null)
53
+            {
54
+                StatusRepository statusRepo = new StatusRepository(_dbContext);
55
+                week.Status = statusRepo.GetDetailed(x => x.Id == week.StatusId);
56
+            }
57
+            return week;
58
+        }
59
+
60
+        public TimeshareWeek GetDetailed(Func<TimeshareWeek, bool> first)
61
+        {
62
+            var item = _dbContext.Weeks.FirstOrDefault(first);
63
+            item = GetWeekDetailed(item);
64
+            return item;
65
+        }
66
+
67
+        public List<TimeshareWeek> GetDetailedAll()
68
+        {
69
+            var list = GetAll();
70
+            List<TimeshareWeek> weeklist = new List<TimeshareWeek>();
71
+            foreach(var item in list)
72
+            {
73
+                weeklist.Add(GetWeekDetailed(item));
74
+            }
75
+            return weeklist;
76
+        }
77
+
78
+        public void Insert(TimeshareWeek item)
79
+        {
80
+            item = GetWeekDetailed(item);
81
+            _dbContext.Add(item);
82
+            Save();
83
+        }
84
+
85
+        public void Insert(IEnumerable<TimeshareWeek> items)
86
+        {
87
+            foreach (var item in items)
88
+            {
89
+                _dbContext.Add(item);
90
+            }
91
+            Save();
92
+        }
93
+
94
+        public void Remove(TimeshareWeek item)
95
+        {
96
+            var i = _dbContext.Weeks.Find(item);
97
+            _dbContext.Weeks.Remove(i);
98
+            Save();
99
+        }
100
+
101
+        public void Remove(IEnumerable<TimeshareWeek> items)
102
+        {
103
+            foreach (var item in items)
104
+            {
105
+                var i = _dbContext.Weeks.Find(item);
106
+                _dbContext.Weeks.Remove(i);
107
+            }
108
+            Save();
109
+        }
110
+
111
+        public void RemoveAtId(int item)
112
+        {
113
+            var i = _dbContext.Weeks.Find(item);
114
+            _dbContext.Weeks.Remove(i);
115
+            Save();
116
+        }
117
+
118
+        public void Save()
119
+        {
120
+            _dbContext.SaveChanges();            
121
+        }
122
+
123
+        public void Update(TimeshareWeek item)
124
+        {
125
+            _dbContext.Entry(item).State = EntityState.Modified;
126
+            Save();
127
+        }
128
+    }
129
+}

+ 97
- 0
UnivateProperties_API/Repository/Users/AgencyRepository.cs Vedi File

@@ -0,0 +1,97 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using System.Threading.Tasks;
6
+using UnivateProperties_API.Context;
7
+using UnivateProperties_API.Model.Users;
8
+
9
+namespace UnivateProperties_API.Repository.Users
10
+{
11
+    public class AgencyRepository : IRepository<Agency>
12
+    {
13
+        private readonly DataContext _dbContext;
14
+
15
+        public AgencyRepository(DataContext dbContext)
16
+        {
17
+            _dbContext = dbContext;
18
+        }
19
+
20
+        public List<Agency> Get(Func<Agency, bool> where)
21
+        {
22
+            return _dbContext.Agencies.Where(where).ToList();
23
+        }
24
+
25
+        public List<Agency> GetAll()
26
+        {
27
+            return _dbContext.Agencies.ToList();
28
+        }
29
+
30
+        public Agency GetDetailed(Func<Agency, bool> first)
31
+        {
32
+            var item = _dbContext.Agencies.FirstOrDefault(first);
33
+            AgencyRepository account = new AgencyRepository(_dbContext);
34
+            item = GetDetailedObject(item, account);
35
+            return item;
36
+        }
37
+
38
+        private Agency GetDetailedObject(Agency item, AgencyRepository repo)
39
+        {
40
+            item = repo.GetDetailed(x => x.Id == item.Id);
41
+            return item;
42
+        }
43
+
44
+        public void Insert(Agency item)
45
+        {
46
+            _dbContext.Add(item);
47
+            Save();
48
+        }
49
+
50
+        public void Insert(IEnumerable<Agency> item)
51
+        {
52
+            _dbContext.Add(item);
53
+            Save();
54
+        }
55
+
56
+        public void Remove(Agency item)
57
+        {
58
+            var i = _dbContext.Agencies.Find(item);
59
+            _dbContext.Agencies.Remove(i);
60
+            Save();
61
+        }
62
+
63
+        public void Remove(IEnumerable<Agency> items)
64
+        {
65
+            foreach (var item in items)
66
+            {
67
+                Agency i = _dbContext.Agencies.Find(item);
68
+                _dbContext.Agencies.Remove(i);
69
+            }
70
+            Save();
71
+        }
72
+
73
+        public void RemoveAtId(int item)
74
+        {
75
+            var i = _dbContext.Agencies.Find(item);
76
+            _dbContext.Agencies.Remove(i);
77
+            Save();
78
+        }
79
+
80
+        public void Update(Agency item)
81
+        {
82
+            _dbContext.Entry(item).State = EntityState.Modified;
83
+            Save();
84
+        }
85
+
86
+        public void Save()
87
+        {
88
+            _dbContext.SaveChanges();
89
+        }
90
+
91
+        public List<Agency> GetDetailedAll()
92
+        {
93
+            //TODO: GetDetailed Agency
94
+            throw new NotImplementedException();
95
+        }
96
+    }
97
+}

+ 96
- 0
UnivateProperties_API/Repository/Users/AgentRepository.cs Vedi File

@@ -0,0 +1,96 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Users;
7
+
8
+namespace UnivateProperties_API.Repository.Users
9
+{
10
+    public class AgentRepository : IRepository<Agent>
11
+    {
12
+        private readonly DataContext _dbContext;
13
+
14
+        public AgentRepository(DataContext dbContext)
15
+        {
16
+            _dbContext = dbContext;
17
+        }
18
+
19
+        public List<Agent> Get(Func<Agent, bool> where)
20
+        {
21
+            return _dbContext.Agents.Where(where).ToList();
22
+        }
23
+
24
+        public List<Agent> GetAll()
25
+        {
26
+            return _dbContext.Agents.ToList();
27
+        }
28
+
29
+        public Agent GetDetailed(Func<Agent, bool> first)
30
+        {
31
+            var item = _dbContext.Agents.FirstOrDefault(first);
32
+            AgentRepository account = new AgentRepository(_dbContext);
33
+            item = GetDetailedObject(item, account);
34
+            return item;
35
+        }
36
+
37
+        private Agent GetDetailedObject(Agent item, AgentRepository repo)
38
+        {
39
+            item = repo.GetDetailed(x => x.Id == item.Id);
40
+            return item;
41
+        }
42
+
43
+        public void Insert(Agent item)
44
+        {
45
+            _dbContext.Add(item);
46
+            Save();
47
+        }
48
+
49
+        public void Insert(IEnumerable<Agent> item)
50
+        {
51
+            _dbContext.Add(item);
52
+            Save();
53
+        }
54
+
55
+        public void Remove(Agent item)
56
+        {
57
+            var i = _dbContext.Agents.Find(item);
58
+            _dbContext.Agents.Remove(i);
59
+            Save();
60
+        }
61
+
62
+        public void Remove(IEnumerable<Agent> items)
63
+        {
64
+            foreach (var item in items)
65
+            {
66
+                Agent i = _dbContext.Agents.Find(item);
67
+                _dbContext.Agents.Remove(i);
68
+            }
69
+            Save();
70
+        }
71
+
72
+        public void RemoveAtId(int item)
73
+        {
74
+            var i = _dbContext.Agents.Find(item);
75
+            _dbContext.Agents.Remove(i);
76
+            Save();
77
+        }
78
+
79
+        public void Update(Agent item)
80
+        {
81
+            _dbContext.Entry(item).State = EntityState.Modified;
82
+            Save();
83
+        }
84
+
85
+        public void Save()
86
+        {
87
+            _dbContext.SaveChanges();
88
+        }
89
+
90
+        public List<Agent> GetDetailedAll()
91
+        {
92
+            // TODO: GetDetailed
93
+            throw new NotImplementedException();
94
+        }
95
+    }
96
+}

+ 26
- 0
UnivateProperties_API/Repository/Users/IRegisterRepository.cs Vedi File

@@ -0,0 +1,26 @@
1
+using System.Collections.Generic;
2
+using UnivateProperties_API.Containers.Users;
3
+using UnivateProperties_API.Model.Users;
4
+
5
+namespace UnivateProperties_API.Repository.Users
6
+{
7
+    public interface IRegisterRepository
8
+    {
9
+        User Authenticate(string username, string password);
10
+        IEnumerable<User> GetAllUsers();
11
+        IEnumerable<Agency> GetAllAgencies();
12
+        IEnumerable<Individual> GetAllIndividuals();
13
+        User GetById(int id);
14
+        Agency GetByAgencyId(int id);
15
+        Individual GetByIndividualId(int id);
16
+        User Create(User user, string password, bool save);
17
+        Agency CreateAgency(AgencyDto agency);
18
+        void CreatePerson(UserDto individual, PersonType personType, bool save, Agency agency);
19
+        void Update(User user, string password = null);
20
+        void UpdateAgency(Agency agency, string agencyname = null);
21
+        void UpdatePerson(Person person, PersonType personType);
22
+        void Delete(int id);
23
+        void DeleteAgency(int id);
24
+        void DeleteIndividual(int id);
25
+    }
26
+}

+ 96
- 0
UnivateProperties_API/Repository/Users/IndividualRepository.cs Vedi File

@@ -0,0 +1,96 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Users;
7
+
8
+namespace UnivateProperties_API.Repository.Users
9
+{
10
+    public class IndividualRepository : IRepository<Individual>
11
+    {
12
+        private readonly DataContext _dbContext;
13
+
14
+        public IndividualRepository(DataContext dbContext)
15
+        {
16
+            _dbContext = dbContext;
17
+        }
18
+
19
+        public List<Individual> Get(Func<Individual, bool> where)
20
+        {
21
+            return _dbContext.Individuals.Where(where).ToList();
22
+        }
23
+
24
+        public List<Individual> GetAll()
25
+        {
26
+            return _dbContext.Individuals.ToList();
27
+        }
28
+
29
+        public Individual GetDetailed(Func<Individual, bool> first)
30
+        {
31
+            var item = _dbContext.Individuals.FirstOrDefault(first);
32
+            IndividualRepository account = new IndividualRepository(_dbContext);
33
+            item = GetDetailedObject(item, account);
34
+            return item;
35
+        }
36
+
37
+        private Individual GetDetailedObject(Individual item, IndividualRepository repo)
38
+        {
39
+            item = repo.GetDetailed(x => x.Id == item.Id);
40
+            return item;
41
+        }
42
+
43
+        public void Insert(Individual item)
44
+        {
45
+            _dbContext.Add(item);
46
+            Save();
47
+        }
48
+
49
+        public void Insert(IEnumerable<Individual> item)
50
+        {
51
+            _dbContext.Add(item);
52
+            Save();
53
+        }
54
+
55
+        public void Remove(Individual item)
56
+        {
57
+            var i = _dbContext.Individuals.Find(item);
58
+            _dbContext.Individuals.Remove(i);
59
+            Save();
60
+        }
61
+
62
+        public void Remove(IEnumerable<Individual> items)
63
+        {
64
+            foreach (var item in items)
65
+            {
66
+                Individual i = _dbContext.Individuals.Find(item);
67
+                _dbContext.Individuals.Remove(i);
68
+            }
69
+            Save();
70
+        }
71
+
72
+        public void RemoveAtId(int item)
73
+        {
74
+            var i = _dbContext.Individuals.Find(item);
75
+            _dbContext.Individuals.Remove(i);
76
+            Save();
77
+        }
78
+
79
+        public void Update(Individual item)
80
+        {
81
+            _dbContext.Entry(item).State = EntityState.Modified;
82
+            Save();
83
+        }
84
+
85
+        public void Save()
86
+        {
87
+            _dbContext.SaveChanges();
88
+        }
89
+
90
+        public List<Individual> GetDetailedAll()
91
+        {
92
+            // TODO: GetDetailed
93
+            throw new NotImplementedException();
94
+        }
95
+    }
96
+}

+ 325
- 0
UnivateProperties_API/Repository/Users/RegisterRepository.cs Vedi File

@@ -0,0 +1,325 @@
1
+using Microsoft.AspNetCore.Authorization;
2
+using Microsoft.EntityFrameworkCore;
3
+using Microsoft.Extensions.Options;
4
+using Microsoft.IdentityModel.Tokens;
5
+using System;
6
+using System.Collections.Generic;
7
+using System.IdentityModel.Tokens.Jwt;
8
+using System.Linq;
9
+using System.Security.Claims;
10
+using System.Text;
11
+using UnivateProperties_API.Containers;
12
+using UnivateProperties_API.Containers.Users;
13
+using UnivateProperties_API.Context;
14
+using UnivateProperties_API.Helpers;
15
+using UnivateProperties_API.Model.Users;
16
+
17
+namespace UnivateProperties_API.Repository.Users
18
+{
19
+    public class RegisterRepository : IRegisterRepository
20
+    {
21
+        private readonly DataContext _dbContext;
22
+
23
+        private readonly AppSettings _appSettings;
24
+
25
+        public RegisterRepository(DataContext dbContext, IOptions<AppSettings> appSettings)
26
+        {
27
+            _dbContext = dbContext;
28
+            _appSettings = appSettings.Value;
29
+        }
30
+
31
+        public User Authenticate(string username, string password)
32
+        {
33
+            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
34
+                return null;
35
+
36
+            var user = _dbContext.Users.SingleOrDefault(x => x.Username == username);
37
+
38
+            // check if username exists
39
+            if (user == null)
40
+                return null;
41
+
42
+            // check if password is correct
43
+            if (!VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt))
44
+                return null;
45
+
46
+            // authentication successful
47
+            return user;
48
+        }
49
+
50
+        public User Create(User user, string password, bool save)
51
+        {
52
+            // validation
53
+            if (string.IsNullOrWhiteSpace(password))
54
+                throw new AppException("Password is required");
55
+
56
+            if (_dbContext.Users.Any(x => x.Username == user.Username))
57
+                throw new AppException("Username \"" + user.Username + "\" is already taken");
58
+
59
+            byte[] passwordHash, passwordSalt;
60
+            CreatePasswordHash(password, out passwordHash, out passwordSalt);
61
+
62
+            user.PasswordHash = passwordHash;
63
+            user.PasswordSalt = passwordSalt;
64
+
65
+            _dbContext.Users.Add(user);
66
+            if (save)
67
+            {
68
+                _dbContext.SaveChanges();
69
+            }
70
+
71
+            return user;
72
+        }
73
+
74
+        public Agency CreateAgency(AgencyDto agency)
75
+        {
76
+            // validation
77
+            if (string.IsNullOrWhiteSpace(agency.EaabeffcNumber))
78
+                throw new AppException("eaabeffcNumber is required");
79
+
80
+            if (_dbContext.Agencies.Any(x => x.EAABEFFCNumber == agency.EaabeffcNumber))
81
+                throw new AppException("eaabeffcNumber \"" + agency.EaabeffcNumber + "\" already exists");
82
+
83
+            Agency a = new Agency()
84
+            {
85
+                AgencyName = agency.Name,
86
+                EAABEFFCNumber = agency.EaabeffcNumber,
87
+                CompanyRegNumber = agency.RegNo
88
+            };
89
+
90
+            _dbContext.Agencies.Add(a);
91
+            CreatePerson(agency.User, PersonType.Agent, false, a);
92
+
93
+            _dbContext.SaveChanges();
94
+
95
+            return a;
96
+        }
97
+
98
+        public void CreatePerson(UserDto individual, PersonType personType, bool save, Agency agency)
99
+        {
100
+            // validation
101
+            if (string.IsNullOrWhiteSpace(individual.Password))
102
+                throw new AppException("Password is required");
103
+
104
+            if (_dbContext.Users.Any(x => x.Username == individual.Username))
105
+                throw new AppException("Individual \"" + individual.Username + "\" is already taken");
106
+            byte[] passwordHash, passwordSalt;
107
+
108
+            CreatePasswordHash(individual.Password, out passwordHash, out passwordSalt);
109
+
110
+            User createUser = new User()
111
+            {
112
+                Username = individual.Username,
113
+                PasswordHash = passwordHash,
114
+                PasswordSalt = passwordSalt
115
+            };
116
+            Create(createUser, individual.Password, save);
117
+            Person person = new Person()
118
+            {
119
+            };
120
+            if (personType == PersonType.Agent)
121
+            {
122
+                Agent agent = new Agent()
123
+                {
124
+                    Name = individual.Name,
125
+                    Surname = individual.Surname,
126
+                    User = createUser,
127
+                    Email = individual.Email,
128
+                    CellNumber = individual.CellNumber,
129
+                    Telephone = individual.Telephone,
130
+                    Agency = agency
131
+                };
132
+                _dbContext.Agents.Add(agent);
133
+            }
134
+            else if (personType == PersonType.Individual)
135
+            {
136
+                Individual i = new Individual()
137
+                {
138
+                    Name = individual.Name,
139
+                    Surname = individual.Surname,
140
+                    User = createUser,
141
+                    Email = individual.Email,
142
+                    CellNumber = individual.CellNumber,
143
+                    Telephone = individual.Telephone
144
+                };
145
+                _dbContext.Individuals.Add(i);
146
+            }
147
+            if (save)
148
+            {
149
+                Save();
150
+            }
151
+        }
152
+
153
+        public void UpdatePerson(Person person, PersonType personType)
154
+        {
155
+            if (personType == PersonType.Agent)
156
+            {
157
+                var item = (person as Agent);
158
+                _dbContext.Entry(item).State = EntityState.Modified;
159
+                Save();
160
+            }
161
+            else if (personType == PersonType.Individual)
162
+            {
163
+                var item = (person as Individual);
164
+                _dbContext.Entry(item).State = EntityState.Modified;
165
+                Save();
166
+            }
167
+        }
168
+
169
+        public void Update(User userParam, string password = null)
170
+        {
171
+            var user = _dbContext.Users.Find(userParam.Id);
172
+
173
+            if (user == null)
174
+                throw new AppException("User not found");
175
+
176
+            if (userParam.Username != user.Username)
177
+            {
178
+                // username has changed so check if the new username is already taken
179
+                if (_dbContext.Users.Any(x => x.Username == userParam.Username))
180
+                    throw new AppException("Username " + userParam.Username + " is already taken");
181
+            }
182
+
183
+            // update user properties
184
+            user.Name = userParam.Name;
185
+            user.Surname = userParam.Surname;
186
+            user.Username = userParam.Username;
187
+
188
+            // update password if it was entered
189
+            if (!string.IsNullOrWhiteSpace(password))
190
+            {
191
+                byte[] passwordHash, passwordSalt;
192
+                CreatePasswordHash(password, out passwordHash, out passwordSalt);
193
+
194
+                user.PasswordHash = passwordHash;
195
+                user.PasswordSalt = passwordSalt;
196
+            }
197
+
198
+            _dbContext.Users.Update(user);
199
+            _dbContext.SaveChanges();
200
+        }
201
+
202
+        public void UpdateAgency(Agency agencyParam, string agencyname = null)
203
+        {
204
+            var agency = _dbContext.Agencies.Find(agencyParam.Id);
205
+
206
+            if (agency == null)
207
+                throw new AppException("Agency not found");
208
+
209
+            if (agencyParam.AgencyName != agency.AgencyName)
210
+            {
211
+                // username has changed so check if the new username is already taken
212
+                if (_dbContext.Agencies.Any(x => x.AgencyName == agencyParam.AgencyName))
213
+                    throw new AppException("AgencyName " + agencyParam.AgencyName + " is already taken");
214
+            }
215
+
216
+            // update user properties
217
+            agency.AgencyName = agencyParam.AgencyName;
218
+            agency.EAABEFFCNumber = agencyParam.EAABEFFCNumber;
219
+            agency.CompanyRegNumber = agencyParam.CompanyRegNumber;
220
+
221
+            // update password if it was entered
222
+            _dbContext.Agencies.Update(agency);
223
+            _dbContext.SaveChanges();
224
+        }
225
+
226
+        [Authorize(Roles = Role.SuperAdmin)]
227
+        public IEnumerable<User> GetAllUsers()
228
+        {
229
+            return _dbContext.Users;
230
+        }
231
+
232
+        [Authorize(Roles = Role.SuperAdmin)]
233
+        public IEnumerable<Agency> GetAllAgencies()
234
+        {
235
+            return _dbContext.Agencies;
236
+        }
237
+
238
+        [Authorize(Roles = Role.SuperAdmin)]
239
+        public IEnumerable<Individual> GetAllIndividuals()
240
+        {
241
+            return _dbContext.Individuals;
242
+        }
243
+
244
+        public User GetById(int id)
245
+        {
246
+            return _dbContext.Users.Find(id);
247
+        }
248
+
249
+        public Agency GetByAgencyId(int id)
250
+        {
251
+            return _dbContext.Agencies.Find(id);
252
+        }
253
+
254
+        public Individual GetByIndividualId(int id)
255
+        {
256
+            return _dbContext.Individuals.Find(id);
257
+        }
258
+
259
+        public void Delete(int id)
260
+        {
261
+            var user = _dbContext.Users.Find(id);
262
+            if (user != null)
263
+            {
264
+                _dbContext.Users.Remove(user);
265
+                _dbContext.SaveChanges();
266
+            }
267
+        }
268
+
269
+        public void DeleteAgency(int id)
270
+        {
271
+            var agency = _dbContext.Agencies.Find(id);
272
+            if (agency != null)
273
+            {
274
+                _dbContext.Remove(agency);
275
+                _dbContext.SaveChanges();
276
+            }
277
+        }
278
+
279
+        public void DeleteIndividual(int id)
280
+        {
281
+            var individual = _dbContext.Individuals.Find(id);
282
+            if (individual != null)
283
+            {
284
+                _dbContext.Individuals.Remove(individual);
285
+                _dbContext.SaveChanges();
286
+            }
287
+        }
288
+
289
+        private void Save()
290
+        {
291
+            _dbContext.SaveChanges();
292
+        }
293
+
294
+        private static void CreatePasswordHash(string password, out byte[] passwordHash, out byte[] passwordSalt)
295
+        {
296
+            if (password == null) throw new ArgumentNullException("password");
297
+            if (string.IsNullOrWhiteSpace(password)) throw new ArgumentException("Value cannot be empty or whitespace only string.", "password");
298
+
299
+            using (var hmac = new System.Security.Cryptography.HMACSHA512())
300
+            {
301
+                passwordSalt = hmac.Key;
302
+                passwordHash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
303
+            }
304
+        }
305
+
306
+        private static bool VerifyPasswordHash(string password, byte[] storedHash, byte[] storedSalt)
307
+        {
308
+            if (password == null) throw new ArgumentNullException("password");
309
+            if (string.IsNullOrWhiteSpace(password)) throw new ArgumentException("Value cannot be empty or whitespace only string.", "password");
310
+            if (storedHash.Length != 64) throw new ArgumentException("Invalid length of password hash (64 bytes expected).", "passwordHash");
311
+            if (storedSalt.Length != 128) throw new ArgumentException("Invalid length of password salt (128 bytes expected).", "passwordHash");
312
+
313
+            using (var hmac = new System.Security.Cryptography.HMACSHA512(storedSalt))
314
+            {
315
+                var computedHash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
316
+                for (int i = 0; i < computedHash.Length; i++)
317
+                {
318
+                    if (computedHash[i] != storedHash[i]) return false;
319
+                }
320
+            }
321
+
322
+            return true;
323
+        }
324
+    }
325
+}

+ 100
- 0
UnivateProperties_API/Repository/Users/UserRepository.cs Vedi File

@@ -0,0 +1,100 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using Microsoft.Extensions.Options;
3
+using Microsoft.IdentityModel.Tokens;
4
+using System;
5
+using System.Collections.Generic;
6
+using System.IdentityModel.Tokens.Jwt;
7
+using System.Linq;
8
+using System.Security.Claims;
9
+using System.Text;
10
+using UnivateProperties_API.Context;
11
+using UnivateProperties_API.Model.Users;
12
+
13
+namespace UnivateProperties_API.Repository.Users
14
+{
15
+    public class UserRepository : IRepository<User>
16
+    {
17
+        private readonly DataContext _dbContext;
18
+
19
+        public UserRepository(DataContext dbContext)
20
+        {
21
+            _dbContext = dbContext;
22
+        }
23
+
24
+        public List<User> Get(Func<User, bool> where)
25
+        {
26
+            return _dbContext.Users.Where(where).ToList();
27
+        }
28
+
29
+        public List<User> GetAll()
30
+        {
31
+            return _dbContext.Users.ToList();
32
+        }
33
+
34
+        public User GetDetailed(Func<User, bool> first)
35
+        {
36
+            var item = _dbContext.Users.FirstOrDefault(first);
37
+            UserRepository account = new UserRepository(_dbContext);
38
+            item = GetDetailedObject(item, account);
39
+            return item;
40
+        }
41
+
42
+        private User GetDetailedObject(User item, UserRepository repo)
43
+        {
44
+            item = repo.GetDetailed(x => x.Id == item.Id);
45
+            return item;
46
+        }
47
+
48
+        public void Insert(User item)
49
+        {
50
+            _dbContext.Add(item);
51
+            Save();
52
+        }
53
+
54
+        public void Insert(IEnumerable<User> item)
55
+        {
56
+            _dbContext.Add(item);
57
+            Save();
58
+        }
59
+
60
+        public void Remove(User item)
61
+        {
62
+            var i = _dbContext.Users.Find(item);
63
+            _dbContext.Users.Remove(i);
64
+            Save();
65
+        }
66
+
67
+        public void Remove(IEnumerable<User> items)
68
+        {
69
+            foreach (var item in items)
70
+            {
71
+                User i = _dbContext.Users.Find(item);
72
+                _dbContext.Users.Remove(i);
73
+            }
74
+            Save();
75
+        }
76
+
77
+        public void RemoveAtId(int item)
78
+        {
79
+            var i = _dbContext.Users.Find(item);
80
+            _dbContext.Users.Remove(i);
81
+            Save();
82
+        }
83
+
84
+        public void Update(User item)
85
+        {
86
+            _dbContext.Entry(item).State = EntityState.Modified;
87
+            Save();
88
+        }
89
+
90
+        public void Save()
91
+        {
92
+            _dbContext.SaveChanges();
93
+        }
94
+
95
+        public List<User> GetDetailedAll()
96
+        {
97
+            throw new NotImplementedException();
98
+        }
99
+    }
100
+}

+ 147
- 0
UnivateProperties_API/Startup.cs Vedi File

@@ -0,0 +1,147 @@
1
+using AutoMapper;
2
+using Microsoft.AspNetCore.Authentication.JwtBearer;
3
+using Microsoft.AspNetCore.Builder;
4
+using Microsoft.AspNetCore.Hosting;
5
+using Microsoft.AspNetCore.Mvc;
6
+using Microsoft.AspNetCore.Mvc.Cors.Internal;
7
+using Microsoft.EntityFrameworkCore;
8
+using Microsoft.Extensions.Configuration;
9
+using Microsoft.Extensions.DependencyInjection;
10
+using Microsoft.IdentityModel.Tokens;
11
+using System.Text;
12
+using System.Threading.Tasks;
13
+using UnivateProperties_API.Context;
14
+using UnivateProperties_API.Model.Communication;
15
+using UnivateProperties_API.Model.Property;
16
+using UnivateProperties_API.Model.Region;
17
+using UnivateProperties_API.Model.Timeshare;
18
+using UnivateProperties_API.Model.Users;
19
+using UnivateProperties_API.Repository;
20
+using UnivateProperties_API.Repository.Communication;
21
+using UnivateProperties_API.Repository.Properties;
22
+using UnivateProperties_API.Repository.Region;
23
+using UnivateProperties_API.Repository.Timeshare;
24
+using UnivateProperties_API.Repository.Users;
25
+
26
+namespace UnivateProperties_API
27
+{
28
+    public class Startup
29
+    {
30
+        public Startup(IConfiguration configuration)
31
+        {
32
+            Configuration = configuration;
33
+        }
34
+
35
+        public IConfiguration Configuration { get; }
36
+
37
+        public void ConfigureServices(IServiceCollection services)
38
+        {
39
+            services.AddAutoMapper();
40
+            services.AddCors(o => o.AddPolicy("MyPolicy", builder =>
41
+            {
42
+                builder.AllowAnyOrigin()
43
+                       .AllowAnyMethod()
44
+                       .AllowAnyHeader();
45
+            }));
46
+            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
47
+            services.AddDbContext<DataContext>(o => o.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
48
+
49
+            var appSettingsSection = Configuration.GetSection("AppSettings");
50
+            services.Configure<AppSettings>(appSettingsSection);
51
+
52
+            // configure jwt authentication
53
+            var appSettings = appSettingsSection.Get<AppSettings>();
54
+            var key = Encoding.ASCII.GetBytes(appSettings.Secret);
55
+            services.AddAuthentication(x =>
56
+            {
57
+                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
58
+                x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
59
+            })
60
+            .AddJwtBearer(x =>
61
+            {
62
+                x.Events = new JwtBearerEvents
63
+                {
64
+                    OnTokenValidated = context =>
65
+                    {
66
+                        var registerRepository = context.HttpContext.RequestServices.GetRequiredService<IRegisterRepository>();
67
+                        var userId = int.Parse(context.Principal.Identity.Name);
68
+                        var user = registerRepository.GetById(userId);
69
+                        if (user == null)
70
+                        {
71
+                            // return unauthorized if user no longer exists
72
+                            context.Fail("Unauthorized");
73
+                        }
74
+                        return Task.CompletedTask;
75
+                    }
76
+                };
77
+                x.RequireHttpsMetadata = false;
78
+                x.SaveToken = true;
79
+                x.TokenValidationParameters = new TokenValidationParameters
80
+                {
81
+                    ValidateIssuerSigningKey = true,
82
+                    IssuerSigningKey = new SymmetricSecurityKey(key),
83
+                    ValidateIssuer = false,
84
+                    ValidateAudience = false
85
+                };
86
+            });
87
+
88
+            #region Property
89
+            services.AddTransient<IRepository<Agent>, AgentRepository>();
90
+            services.AddTransient<IRegisterRepository, RegisterRepository>();
91
+            services.AddTransient<IRepository<Agency>, AgencyRepository>();
92
+            services.AddTransient<IRepository<Email>, EmailRepository>();
93
+            services.AddTransient<IRepository<SMTPAccount>, SMTPAccountRepository>();
94
+            services.AddTransient<IRepository<SMTPHost>, SMTPHostRepository>();
95
+            services.AddTransient<IPropertyRepository, PropertyRepository>();
96
+            services.AddTransient<IPropertyImageRepository, PropertyImageRepository>();
97
+            services.AddTransient<IRepository<PropertyType>, PropertyTypeRepository>();
98
+            services.AddTransient<IRepository<PropertyUserField>, PropertyUserFieldRepository>();
99
+            services.AddTransient<IRepository<UserDefinedField>, UserDefinedFieldRepository>();
100
+            services.AddTransient<IUserDefinedGroupRepository, UserDefinedGroupRepository>();
101
+            #endregion Property
102
+            #region Region
103
+            services.AddTransient<IRepository<Province>, ProvinceRepository>();
104
+            services.AddTransient<ICityRepository, CityRepository>();
105
+            services.AddTransient<ISuburbRepository, SuburbRepository>();
106
+            #endregion Region
107
+            #region Timeshare
108
+            services.AddTransient<IRepository<Status>, StatusRepository>();
109
+            services.AddTransient<IRepository<Season>, SeasonRepository>();
110
+            services.AddTransient<IRepository<UnitConfiguration>, UnitConfigurationRepository>();
111
+            services.AddTransient<IRepository<TimeshareWeek>, WeekRepository>();
112
+            #endregion Timeshare
113
+            #region User
114
+            services.AddScoped<IRegisterRepository, RegisterRepository>();
115
+            services.AddTransient<IRepository<Agent>, AgentRepository>();
116
+            services.AddTransient<IRegisterRepository, RegisterRepository>();
117
+            services.AddTransient<IRepository<Agency>, AgencyRepository>();
118
+            services.AddTransient<IRepository<User>, UserRepository>();
119
+            services.AddTransient<IRepository<Individual>, IndividualRepository>();
120
+            #endregion User
121
+            #region Communication
122
+            services.AddTransient<IRepository<Email>, EmailRepository>();
123
+            services.AddTransient<IRepository<SMTPAccount>, SMTPAccountRepository>();
124
+            services.AddTransient<IRepository<SMTPHost>, SMTPHostRepository>();
125
+            #endregion Communication
126
+            services.Configure<MvcOptions>(options =>
127
+            {
128
+                options.Filters.Add(new CorsAuthorizationFilterFactory("MyPolicy"));
129
+            });
130
+        }
131
+
132
+        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
133
+        {
134
+            if (env.IsDevelopment())
135
+            {
136
+                app.UseDeveloperExceptionPage();
137
+            }
138
+            app.UseCors(x => x
139
+                .AllowAnyOrigin()
140
+                .AllowAnyMethod()
141
+                .AllowAnyHeader());
142
+            app.UseAuthentication();
143
+            app.UseHttpsRedirection();
144
+            app.UseMvc();
145
+        }
146
+    }
147
+}

+ 25
- 0
UnivateProperties_API/UnivateProperties_API.csproj Vedi File

@@ -0,0 +1,25 @@
1
+<Project Sdk="Microsoft.NET.Sdk.Web">
2
+
3
+  <PropertyGroup>
4
+    <TargetFramework>netcoreapp2.2</TargetFramework>
5
+    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
6
+  </PropertyGroup>
7
+
8
+  <ItemGroup>
9
+    <Compile Remove="Migrations\20190826105340_InitialCreate.cs" />
10
+    <Compile Remove="Migrations\20190826105340_InitialCreate.Designer.cs" />
11
+    <Compile Remove="Model\Users\AgencyAgent.cs" />
12
+  </ItemGroup>
13
+
14
+  <ItemGroup>
15
+    <PackageReference Include="Abp.AutoMapper" Version="4.8.1" />
16
+    <PackageReference Include="AutoMapper" Version="9.0.0" />
17
+    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.0.0" />
18
+    <PackageReference Include="Microsoft.AspNetCore.App" />
19
+    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
20
+    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
21
+    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
22
+    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.4" />
23
+  </ItemGroup>
24
+
25
+</Project>

+ 0
- 0
UnivateProperties_API/appsettings.Development.json Vedi File


Dato che sono stati cambiati molti file in questo diff, alcuni di essi non verranno mostrati

Loading…
Annulla
Salva