|
@@ -18,7 +18,7 @@ namespace UnivateProperties_API.Repository.Users
|
18
|
18
|
|
19
|
19
|
public List<Agent> Get(Func<Agent, bool> where)
|
20
|
20
|
{
|
21
|
|
- return _dbContext.Agents.Where(where).ToList();
|
|
21
|
+ return _dbContext.Agents.Include("User").Where(where).ToList();
|
22
|
22
|
}
|
23
|
23
|
|
24
|
24
|
public List<Agent> GetAll()
|
|
@@ -51,11 +51,11 @@ namespace UnivateProperties_API.Repository.Users
|
51
|
51
|
if (item.User.Role == "Agent" || item.User.Role == "Agency" || item.User.Role == "Managing Agent")
|
52
|
52
|
{
|
53
|
53
|
if (agent == null)
|
54
|
|
- {
|
|
54
|
+ {
|
55
|
55
|
if (individual != null)
|
56
|
56
|
{
|
57
|
57
|
individual.IsDeleted = true;
|
58
|
|
- _dbContext.Individuals.Update(individual);
|
|
58
|
+ _dbContext.Individuals.Update(individual);
|
59
|
59
|
}
|
60
|
60
|
item.Id = 0;
|
61
|
61
|
_dbContext.Agents.Add(item);
|
|
@@ -95,7 +95,7 @@ namespace UnivateProperties_API.Repository.Users
|
95
|
95
|
if (individual != null)
|
96
|
96
|
{
|
97
|
97
|
individual.IsDeleted = true;
|
98
|
|
- _dbContext.Individuals.Update(individual);
|
|
98
|
+ _dbContext.Individuals.Update(individual);
|
99
|
99
|
}
|
100
|
100
|
_dbContext.Agents.Update(agent);
|
101
|
101
|
if (item.User.Role != user.Role)
|
|
@@ -180,11 +180,40 @@ namespace UnivateProperties_API.Repository.Users
|
180
|
180
|
|
181
|
181
|
public void Update(Agent item)
|
182
|
182
|
{
|
183
|
|
- //var savedAgent = _dbContext.Agents.Where(x => x.Id == item.Id).FirstOrDefault();
|
|
183
|
+ var individual = _dbContext.Individuals.Include("User").Include("Address").Include("BankAccount").FirstOrDefault(x => x.UserId == item.UserId);
|
|
184
|
+ var user = _dbContext.Users.Where(x => x.Id == item.User.Id).FirstOrDefault();
|
184
|
185
|
|
185
|
|
-
|
186
|
|
- _dbContext.Entry(item).State = EntityState.Modified;
|
187
|
|
- _dbContext.Entry(item.User).State = EntityState.Modified;
|
|
186
|
+ if (item.User.Role == "Agent" || item.User.Role == "Agency" || item.User.Role == "Managing Agent")
|
|
187
|
+ {
|
|
188
|
+ item.IsDeleted = false;
|
|
189
|
+ if (individual != null)
|
|
190
|
+ {
|
|
191
|
+ individual.IsDeleted = true;
|
|
192
|
+ }
|
|
193
|
+ }
|
|
194
|
+ else
|
|
195
|
+ {
|
|
196
|
+ item.IsDeleted = true;
|
|
197
|
+ if (individual != null)
|
|
198
|
+ {
|
|
199
|
+ individual.IsDeleted = false;
|
|
200
|
+ }
|
|
201
|
+
|
|
202
|
+ }
|
|
203
|
+ if (individual != null)
|
|
204
|
+ {
|
|
205
|
+ _dbContext.Individuals.Update(individual);
|
|
206
|
+ //_dbContext.Entry(individual).State = EntityState.Modified;
|
|
207
|
+ }
|
|
208
|
+ if (item.User.Role != user.Role)
|
|
209
|
+ {
|
|
210
|
+ user.Role = item.User.Role;
|
|
211
|
+ _dbContext.Users.Update(user);
|
|
212
|
+ //_dbContext.Entry(user).State = EntityState.Modified;
|
|
213
|
+ }
|
|
214
|
+ _dbContext.Agents.Update(item);
|
|
215
|
+ //_dbContext.Entry(item).State = EntityState.Modified;
|
|
216
|
+ //_dbContext.Entry(item.User).State = EntityState.Modified;
|
188
|
217
|
Save();
|
189
|
218
|
}
|
190
|
219
|
|