|
|
@@ -33,6 +33,7 @@ namespace UnivateProperties_API.Controllers.Users
|
|
33
|
33
|
_appSettings = appSettings.Value;
|
|
34
|
34
|
}
|
|
35
|
35
|
|
|
|
36
|
+ //Works
|
|
36
|
37
|
[AllowAnonymous]
|
|
37
|
38
|
[HttpPost("authenticate")]
|
|
38
|
39
|
public IActionResult Authenticate([FromBody]UserDto userDto)
|
|
|
@@ -68,26 +69,25 @@ namespace UnivateProperties_API.Controllers.Users
|
|
68
|
69
|
});
|
|
69
|
70
|
}
|
|
70
|
71
|
|
|
|
72
|
+ //Writes to DB
|
|
71
|
73
|
[AllowAnonymous]
|
|
72
|
74
|
[HttpPost("register")]
|
|
73
|
|
- public IActionResult Register([FromBody]UserDto userDto)
|
|
|
75
|
+ public IActionResult Register([FromBody]UserDto individual)
|
|
74
|
76
|
{
|
|
75
|
|
- // map dto to entity
|
|
76
|
|
- var user = _mapper.Map<User>(userDto);
|
|
|
77
|
+ _mapper.Map<Individual>(individual);
|
|
77
|
78
|
|
|
78
|
79
|
try
|
|
79
|
80
|
{
|
|
80
|
|
- // save
|
|
81
|
|
- _Repo.Create(user, userDto.Password, true);
|
|
|
81
|
+ _Repo.CreatePerson(individual, PersonType.Individual, true, null);
|
|
82
|
82
|
return Ok();
|
|
83
|
83
|
}
|
|
84
|
84
|
catch (AppException ex)
|
|
85
|
85
|
{
|
|
86
|
|
- // return error message if there was an exception
|
|
87
|
|
- return BadRequest(new { message = ex.Message });
|
|
|
86
|
+ return BadRequest(new { messge = ex.Message });
|
|
88
|
87
|
}
|
|
89
|
88
|
}
|
|
90
|
89
|
|
|
|
90
|
+ //Writes to DB
|
|
91
|
91
|
[AllowAnonymous]
|
|
92
|
92
|
[HttpPost("registeragency")]
|
|
93
|
93
|
public IActionResult RegisterAgency([FromBody]AgencyDto agency)
|
|
|
@@ -108,101 +108,61 @@ namespace UnivateProperties_API.Controllers.Users
|
|
108
|
108
|
}
|
|
109
|
109
|
}
|
|
110
|
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
|
|
- }
|
|
|
111
|
+ //[HttpGet("{id}")]
|
|
|
112
|
+ //public IActionResult GetById(int id)
|
|
|
113
|
+ //{
|
|
|
114
|
+ // var user = _Repo.GetById(id);
|
|
|
115
|
+ // var userDto = _mapper.Map<UserDto>(user);
|
|
|
116
|
+
|
|
|
117
|
+ // if (user == null)
|
|
|
118
|
+ // {
|
|
|
119
|
+ // return NotFound();
|
|
|
120
|
+ // }
|
|
|
121
|
+
|
|
|
122
|
+ // // Only allow SuperAdmins to access other user records
|
|
|
123
|
+ // var currentUserId = int.Parse(User.Identity.Name);
|
|
|
124
|
+ // if (id != currentUserId && !User.IsInRole(Role.SuperAdmin))
|
|
|
125
|
+ // {
|
|
|
126
|
+ // return Forbid();
|
|
|
127
|
+ // }
|
|
|
128
|
+
|
|
|
129
|
+ // return Ok(userDto);
|
|
|
130
|
+ //}
|
|
|
131
|
+
|
|
|
132
|
+ //[HttpGet("{id}")]
|
|
|
133
|
+ //public IActionResult GetByAgencyId(int id)
|
|
|
134
|
+ //{
|
|
|
135
|
+ // var agency = _Repo.GetByAgencyId(id);
|
|
|
136
|
+ // var agencyDto = _mapper.Map<AgencyDto>(agency);
|
|
|
137
|
+
|
|
|
138
|
+ // if (agency == null)
|
|
|
139
|
+ // {
|
|
|
140
|
+ // return NotFound();
|
|
|
141
|
+ // }
|
|
|
142
|
+
|
|
|
143
|
+ // var currentAgencyId = int.Parse(User.Identity.Name);
|
|
|
144
|
+ // if (id != currentAgencyId && !User.IsInRole(Role.Agency))
|
|
|
145
|
+ // {
|
|
|
146
|
+ // return Forbid();
|
|
|
147
|
+ // }
|
|
|
148
|
+
|
|
|
149
|
+ // return Ok(agencyDto);
|
|
|
150
|
+ //}
|
|
|
151
|
+
|
|
|
152
|
+ //[Authorize(Roles = Role.SuperAdmin)]
|
|
|
153
|
+ //[HttpDelete("{id}")]
|
|
|
154
|
+ //public IActionResult Delete(User user)
|
|
|
155
|
+ //{
|
|
|
156
|
+ // _Repo.Delete(user.Id);
|
|
|
157
|
+ // return Ok();
|
|
|
158
|
+ //}
|
|
|
159
|
+
|
|
|
160
|
+ //[Authorize(Roles = Role.SuperAdmin)]
|
|
|
161
|
+ //[HttpDelete("{id}")]
|
|
|
162
|
+ //public IActionResult DeleteAgency(Agency agency)
|
|
|
163
|
+ //{
|
|
|
164
|
+ // _Repo.DeleteAgency(agency.Id);
|
|
|
165
|
+ // return Ok();
|
|
|
166
|
+ //}
|
|
207
|
167
|
}
|
|
208
|
168
|
}
|