|
|
@@ -6,6 +6,7 @@ using UnivateProperties_API.Containers.Communication;
|
|
6
|
6
|
using UnivateProperties_API.Context;
|
|
7
|
7
|
using UnivateProperties_API.Model;
|
|
8
|
8
|
using UnivateProperties_API.Model.Communication;
|
|
|
9
|
+using UnivateProperties_API.Model.Timeshare;
|
|
9
|
10
|
using UnivateProperties_API.Model.Users;
|
|
10
|
11
|
|
|
11
|
12
|
namespace UnivateProperties_API.Repository.Communication
|
|
|
@@ -94,18 +95,18 @@ namespace UnivateProperties_API.Repository.Communication
|
|
94
|
95
|
|
|
95
|
96
|
private void CheckListChange(List<PlaceHolder> holderOld, List<PlaceHolder> holderNew)
|
|
96
|
97
|
{
|
|
97
|
|
- foreach(var item in holderOld)
|
|
|
98
|
+ foreach (var item in holderOld)
|
|
98
|
99
|
{
|
|
99
|
|
- if(!holderNew.Any(x => x.Id== item.Id))
|
|
|
100
|
+ if (!holderNew.Any(x => x.Id == item.Id))
|
|
100
|
101
|
{
|
|
101
|
102
|
var i = _dbContext.PlaceHolders.FirstOrDefault(x => x.Id == item.Id);
|
|
102
|
|
- if(item != null)
|
|
|
103
|
+ if (item != null)
|
|
103
|
104
|
{
|
|
104
|
105
|
_dbContext.PlaceHolders.Remove(i);
|
|
105
|
106
|
}
|
|
106
|
107
|
}
|
|
107
|
108
|
}
|
|
108
|
|
- foreach(var item in holderNew.Where(x => x.Id == 0))
|
|
|
109
|
+ foreach (var item in holderNew.Where(x => x.Id == 0))
|
|
109
|
110
|
{
|
|
110
|
111
|
_dbContext.Add(item);
|
|
111
|
112
|
}
|
|
|
@@ -130,7 +131,7 @@ namespace UnivateProperties_API.Repository.Communication
|
|
130
|
131
|
public List<TemplateDto> GetSimpleAll()
|
|
131
|
132
|
{
|
|
132
|
133
|
List<TemplateDto> list = new List<TemplateDto>();
|
|
133
|
|
- foreach(var item in GetAll())
|
|
|
134
|
+ foreach (var item in GetAll())
|
|
134
|
135
|
{
|
|
135
|
136
|
list.Add(new TemplateDto()
|
|
136
|
137
|
{
|
|
|
@@ -147,7 +148,7 @@ namespace UnivateProperties_API.Repository.Communication
|
|
147
|
148
|
private List<PlaceHolderDto> GetPlaceHolders(int id)
|
|
148
|
149
|
{
|
|
149
|
150
|
List<PlaceHolderDto> list = new List<PlaceHolderDto>();
|
|
150
|
|
- foreach(var item in _dbContext.PlaceHolders.Where(x => x.TemplateId == id).ToList())
|
|
|
151
|
+ foreach (var item in _dbContext.PlaceHolders.Where(x => x.TemplateId == id).ToList())
|
|
151
|
152
|
{
|
|
152
|
153
|
list.Add(new PlaceHolderDto()
|
|
153
|
154
|
{
|
|
|
@@ -161,46 +162,46 @@ namespace UnivateProperties_API.Repository.Communication
|
|
161
|
162
|
return list;
|
|
162
|
163
|
}
|
|
163
|
164
|
|
|
164
|
|
- public void SendEmailTemplate(int id)
|
|
|
165
|
+ public void SendEmailTemplate(Template template, TimeshareWeek week, Individual owner, Person sendTo, List<BaseEntity> args)
|
|
165
|
166
|
{
|
|
166
|
|
- var item = _dbContext.Weeks.FirstOrDefault(x => x.Id == 4);
|
|
167
|
|
- var indiv = _dbContext.Individuals.FirstOrDefault(x => x.Id == 73);
|
|
168
|
|
- List<BaseEntity> list = new List<BaseEntity>
|
|
|
167
|
+ if (template != null)
|
|
169
|
168
|
{
|
|
170
|
|
- item,
|
|
171
|
|
- indiv
|
|
172
|
|
- };
|
|
173
|
|
- var template = _dbContext.Templates.FirstOrDefault(x => x.Id == id);
|
|
174
|
|
- if (template.SenderId == null)
|
|
175
|
|
- {
|
|
176
|
|
- var acc = _dbContext.Accounts.FirstOrDefault(x => x.Default);
|
|
177
|
|
- if (acc != null)
|
|
|
169
|
+ List<BaseEntity> list = new List<BaseEntity>();
|
|
|
170
|
+ if (owner != null)
|
|
178
|
171
|
{
|
|
179
|
|
- template.SenderId = acc.Id;
|
|
180
|
|
- template.Sender = acc;
|
|
|
172
|
+ list.Add(owner);
|
|
181
|
173
|
}
|
|
182
|
|
- }
|
|
183
|
|
- else template.Sender = _dbContext.Accounts.FirstOrDefault(x => x.Id == template.SenderId);
|
|
184
|
|
- template.PlaceHolders = _dbContext.PlaceHolders.Where(x => x.TemplateId == id).ToList();
|
|
185
|
|
- if(template != null)
|
|
186
|
|
- {
|
|
187
|
|
- Person person = _dbContext.Individuals.FirstOrDefault(x => x.Email == "kobusb@provision-sa.com");
|
|
188
|
|
- if(person == null)
|
|
|
174
|
+ if (week != null)
|
|
189
|
175
|
{
|
|
190
|
|
- person = _dbContext.Agents.FirstOrDefault(x => x.Email == "kobusb@provision-sa.com");
|
|
|
176
|
+ list.Add(week);
|
|
191
|
177
|
}
|
|
192
|
|
- if(person != null)
|
|
|
178
|
+ if (args != null && args.Count > 1)
|
|
|
179
|
+ {
|
|
|
180
|
+ list.AddRange(args);
|
|
|
181
|
+ }
|
|
|
182
|
+ if (template.SenderId == null)
|
|
|
183
|
+ {
|
|
|
184
|
+ var acc = _dbContext.Accounts.FirstOrDefault(x => x.Default);
|
|
|
185
|
+ if (acc != null)
|
|
|
186
|
+ {
|
|
|
187
|
+ template.SenderId = acc.Id;
|
|
|
188
|
+ template.Sender = acc;
|
|
|
189
|
+ }
|
|
|
190
|
+ }
|
|
|
191
|
+ else template.Sender = _dbContext.Accounts.FirstOrDefault(x => x.Id == template.SenderId);
|
|
|
192
|
+ template.PlaceHolders = _dbContext.PlaceHolders.Where(x => x.TemplateId == template.Id).ToList();
|
|
|
193
|
+ if (sendTo != null)
|
|
193
|
194
|
{
|
|
194
|
195
|
try
|
|
195
|
196
|
{
|
|
196
|
|
- Email email = new Email(template, person, list);
|
|
|
197
|
+ Email email = new Email(template, sendTo, list);
|
|
197
|
198
|
EmailRepository emailRepo = new EmailRepository(_dbContext);
|
|
198
|
199
|
emailRepo.Insert(email);
|
|
199
|
200
|
}
|
|
200
|
|
- catch(Exception)
|
|
|
201
|
+ catch (Exception)
|
|
201
|
202
|
{
|
|
202
|
|
- }
|
|
203
|
|
- }
|
|
|
203
|
+ }
|
|
|
204
|
+ }
|
|
204
|
205
|
}
|
|
205
|
206
|
}
|
|
206
|
207
|
}
|