|
@@ -12,6 +12,7 @@ using UnivateProperties_API.Containers.Users;
|
12
|
12
|
using UnivateProperties_API.Context;
|
13
|
13
|
using UnivateProperties_API.Helpers;
|
14
|
14
|
using UnivateProperties_API.Model;
|
|
15
|
+using UnivateProperties_API.Model.Communication;
|
15
|
16
|
using UnivateProperties_API.Model.Region;
|
16
|
17
|
using UnivateProperties_API.Model.Timeshare;
|
17
|
18
|
using UnivateProperties_API.Repository.Communication;
|
|
@@ -197,33 +198,41 @@ namespace UnivateProperties_API.Repository.Timeshare
|
197
|
198
|
public void Insert(TimeshareWeek item)
|
198
|
199
|
{
|
199
|
200
|
item = GetDetailedWeek(item);
|
200
|
|
- item.Id = _dbContext.Weeks.Max(x => x.Id) + 1;
|
201
|
|
- if (item.Owner != null && item.Owner.Id == 0)
|
202
|
|
- {
|
203
|
|
- item.Owner.Id = _dbContext.Individuals.Max(x => x.Id) + 1;
|
204
|
|
- }
|
205
|
|
- // Set starting Status of A1
|
206
|
201
|
StatusRepository repo = new StatusRepository(_dbContext);
|
207
|
|
- item.Status = repo.GetDetailed(s => s.Code == "A1");
|
208
|
|
- if (item.Status != null)
|
|
202
|
+ var stat = repo.Get(x => x.Code == "A1" && x.StatusType == StatusType.Timeshare).FirstOrDefault();
|
|
203
|
+ if (stat == null)
|
209
|
204
|
{
|
210
|
205
|
//Create initial
|
211
|
|
- item.Status = new Status()
|
|
206
|
+ stat = new Status()
|
212
|
207
|
{
|
213
|
208
|
Code = "A1",
|
214
|
209
|
Description = "Pending verification",
|
215
|
210
|
StatusType = StatusType.Timeshare,
|
216
|
211
|
ModifiedBy = "KobusB"
|
217
|
212
|
};
|
|
213
|
+ repo.Insert(stat);
|
218
|
214
|
}
|
219
|
215
|
item.Id = NewId();
|
220
|
|
- UnivateProperties_API.Model.ProcessFlow.ProcessFlow flowItem = new Model.ProcessFlow.ProcessFlow()
|
|
216
|
+ item.ProcessFlows.Add(new Model.ProcessFlow.ProcessFlow()
|
221
|
217
|
{
|
222
|
218
|
Status = item.Status,
|
223
|
219
|
Timeshare = item
|
224
|
|
- };
|
|
220
|
+ });
|
|
221
|
+ TemplateRepository templateRepository = new TemplateRepository(_dbContext);
|
|
222
|
+ if(item.Owner != null)
|
|
223
|
+ {
|
|
224
|
+ var template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekLoaded-Owner");
|
|
225
|
+ if(template != null)
|
|
226
|
+ {
|
|
227
|
+ templateRepository.SendEmailTemplate(template, item.Owner, new List<BaseEntity>() { item, item.Owner });
|
|
228
|
+ }
|
|
229
|
+ template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekLoaded-UV");
|
|
230
|
+ if(template != null)
|
|
231
|
+ {
|
|
232
|
+ templateRepository.SendEmailTemplate(template, item.Owner, new List<BaseEntity>() { item, item.Owner });
|
|
233
|
+ }
|
|
234
|
+ }
|
225
|
235
|
_dbContext.Add(item);
|
226
|
|
- _dbContext.Add(flowItem);
|
227
|
236
|
Save();
|
228
|
237
|
}
|
229
|
238
|
|
|
@@ -403,8 +412,9 @@ namespace UnivateProperties_API.Repository.Timeshare
|
403
|
412
|
var template = _dbContext.Templates.Where(x => x.Name == "WeekAuthorized").FirstOrDefault();
|
404
|
413
|
if(template != null)
|
405
|
414
|
{
|
|
415
|
+
|
406
|
416
|
TemplateRepository tempRepo = new TemplateRepository(_dbContext);
|
407
|
|
- tempRepo.SendEmailTemplate(template, week, week.Owner, week.Owner, new List<BaseEntity>());
|
|
417
|
+ tempRepo.SendEmailTemplate(template, week.Owner, new List<BaseEntity>() { week, week.Owner});
|
408
|
418
|
}
|
409
|
419
|
}
|
410
|
420
|
}
|
|
@@ -417,12 +427,6 @@ namespace UnivateProperties_API.Repository.Timeshare
|
417
|
427
|
{
|
418
|
428
|
week.Status = newStatus;
|
419
|
429
|
Update(week);
|
420
|
|
- var template = _dbContext.Templates.Where(x => x.Name == "WeekAuthorized").FirstOrDefault();
|
421
|
|
- if (template != null)
|
422
|
|
- {
|
423
|
|
- TemplateRepository tempRepo = new TemplateRepository(_dbContext);
|
424
|
|
- tempRepo.SendEmailTemplate(template, week, week.Owner, week.Owner, new List<BaseEntity>());
|
425
|
|
- }
|
426
|
430
|
}
|
427
|
431
|
}
|
428
|
432
|
}
|