API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MailRepository.cs 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. using Abp.Specifications;
  2. using Microsoft.EntityFrameworkCore;
  3. using MimeKit;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Dynamic;
  7. using System.Linq;
  8. using System.Linq.Dynamic.Core;
  9. using System.Net.Mail;
  10. using System.Text;
  11. using UnivateProperties_API.Containers.Timeshare;
  12. using UnivateProperties_API.Context;
  13. using UnivateProperties_API.Helpers;
  14. using UnivateProperties_API.Model.Communication;
  15. using UnivateProperties_API.Model.ProcessFlow;
  16. using UnivateProperties_API.Model.Timeshare;
  17. using UnivateProperties_API.Model.Users;
  18. namespace UnivateProperties_API.Repository.Communication
  19. {
  20. public interface IMailRepository
  21. {
  22. void ContactUs(MailModel mm);
  23. void EnquireNow(MailModel mm);
  24. void AddRecipient(MailRecipient rec);
  25. List<MailRecipient> GetMailRecipients();
  26. MailRecipient GetMailRecipientById(int id);
  27. void UpdateMailRecipient(MailRecipient rec);
  28. void DeleteMailRecipient(int id);
  29. List<MailModel> GetEnquireNowLog();
  30. List<MailModel> GetContactUsLog();
  31. }
  32. public class MailRepository : IMailRepository
  33. {
  34. private readonly DataContext _dbContext;
  35. string error;
  36. public MailRepository(DataContext db)
  37. {
  38. _dbContext = db;
  39. }
  40. public MailRepository()
  41. {
  42. }
  43. public void ContactUs(MailModel mm)
  44. {
  45. var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "ContactUs").Where(y => y.IsDeleted == false).ToList();
  46. string body = _dbContext.Templates.Where(x => x.Name == "ContactUs").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
  47. var source = _dbContext.MailSources.Where(x => x.Id == Convert.ToInt32(mm.MailSourceId)).FirstOrDefault();
  48. body = body.Replace("[FULLNAME]", mm.Name);
  49. body = body.Replace("[USEREMAIL]", mm.Email);
  50. body = body.Replace("[USERCELLPHONE]", mm.Phone);
  51. body = body.Replace("[PROPERTYREF]", mm.Property);
  52. body = body.Replace("[SOURCE]", source.Description);
  53. body = body.Replace("[USERMESSAGE]", mm.Message);
  54. body = body.Replace("[USERCONSENT]", mm.Consent.ToString());
  55. string toList = "";
  56. int emailCount = 0;
  57. foreach (var recipient in recipients)
  58. {
  59. toList += recipient.RecipientMail + ", ";
  60. emailCount++;
  61. }
  62. if (toList.Length > 0)
  63. {
  64. if (emailCount == 1)
  65. toList = toList.Substring(0, toList.Length - 2);
  66. else
  67. toList = toList.Substring(0, toList.Length - 2);
  68. }
  69. try
  70. {
  71. var host = _dbContext.Hosts.FirstOrDefault();
  72. using (SmtpClient smtp = new SmtpClient(host.Host))
  73. {
  74. MailMessage mail = new MailMessage();
  75. mail.To.Add(toList);
  76. mail.Subject = "Uni-Vate - New Contact Request";
  77. mail.Body = body;
  78. mail.IsBodyHtml = true;
  79. mail.BodyEncoding = Encoding.ASCII;
  80. mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
  81. mail.Sender = new MailAddress(host.User, "UniVate Properties");
  82. mail.From = new MailAddress(mm.Email, mm.Name);
  83. smtp.UseDefaultCredentials = host.NeedsAuthorize;
  84. smtp.Credentials = host.GetNetworkCredential();
  85. smtp.EnableSsl = host.UseSSL;
  86. smtp.Send(mail);
  87. }
  88. error = "None";
  89. }
  90. catch (Exception ex)
  91. {
  92. error = ex.ToString();
  93. }
  94. mm.ComType = "Contact Us";
  95. mm.Error = error;
  96. _dbContext.CommunicationLog.Add(mm);
  97. _dbContext.SaveChanges();
  98. if (error != "None")
  99. {
  100. throw new AppException("SMTP Server Error - Please try later.");
  101. }
  102. }
  103. public void EnquireNow(MailModel mm)
  104. {
  105. var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "EnquireNow").Where(y => y.IsDeleted == false).ToList();
  106. string body = _dbContext.Templates.Where(x => x.Name == "EnquireNow").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
  107. var property = _dbContext.Properties.Where(x => x.Id == Convert.ToInt32(mm.Property)).FirstOrDefault();
  108. string error = "";
  109. body = body.Replace("[FULLNAME]", " " + mm.Name);
  110. body = body.Replace("[USEREMAIL]", " " + mm.Email);
  111. body = body.Replace("[USERCELLPHONE]", " " + mm.Phone);
  112. body = body.Replace("[PROPERTYID]", " " + mm.Property);
  113. body = body.Replace("[PROPERTYNAME]", property.PropertyName);
  114. body = body.Replace("[PROPERTYREF]", property.PropertyRef);
  115. body = body.Replace("[PROPERTYPRICE]", property.Price.ToString());
  116. body = body.Replace("[USERMESSAGE]", " " + mm.Message);
  117. body = body.Replace("[USERHEARDFROM]", " " + mm.HeardFrom);
  118. string toList = "";
  119. int emailCount = 0;
  120. foreach (var recipient in recipients)
  121. {
  122. toList += recipient.RecipientMail + ", ";
  123. emailCount++;
  124. }
  125. if (toList.Length > 0)
  126. {
  127. if (emailCount == 1)
  128. toList = toList.Substring(0, toList.Length - 2);
  129. else
  130. toList = toList.Substring(0, toList.Length - 2);
  131. }
  132. try
  133. {
  134. var host = _dbContext.Hosts.FirstOrDefault();
  135. using (SmtpClient smtp = new SmtpClient(host.Host))
  136. {
  137. MailMessage mail = new MailMessage();
  138. mail.To.Add(toList);
  139. mail.Subject = "Uni-Vate - Enquiry to view property";
  140. mail.Body = body;
  141. mail.IsBodyHtml = true;
  142. mail.BodyEncoding = Encoding.ASCII;
  143. mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
  144. mail.Sender = new MailAddress(host.User, "UniVate Properties");
  145. mail.From = new MailAddress(mm.Email, mm.Name);
  146. smtp.UseDefaultCredentials = host.NeedsAuthorize;
  147. smtp.Credentials = host.GetNetworkCredential();
  148. smtp.EnableSsl = host.UseSSL;
  149. smtp.Send(mail);
  150. }
  151. error = "None";
  152. }
  153. catch (Exception ex)
  154. {
  155. error = ex.ToString();
  156. }
  157. mm.ComType = "Enquire Now";
  158. mm.Error = error;
  159. _dbContext.CommunicationLog.Add(mm);
  160. _dbContext.SaveChanges();
  161. if (error != "None")
  162. {
  163. throw new AppException("SMTP Server Error - Please try later.");
  164. }
  165. }
  166. public void ForgotPassword(Individual toPerson, string link)
  167. {
  168. string body = "<div style=\"margin: 5px\">" +
  169. "<h4>Dear " + toPerson.FullName + "</h4>" +
  170. "<h4>There has been a request to reset your password. If this is incorrect please send an email to info@univateproperties.co.za</h4>" +
  171. "<h4>Once your password has been reset you can use the username "+ toPerson.User.Username + " and the new password to log in.</h4>" +
  172. "<div>" +
  173. "<h4><a href='" + link + "'>Click here</a> to reset your password.</h4>" +
  174. "<br />"+
  175. "<h4>Thank You</h4>" +
  176. "<h4>Team Uni-Vate</h4>" +
  177. "</div>" +
  178. "</div>";
  179. var host = _dbContext.Hosts.FirstOrDefault();
  180. using (SmtpClient smtp = new SmtpClient(host.Host))
  181. {
  182. MailMessage mail = new MailMessage();
  183. mail.To.Add(new MailAddress(toPerson.Email, toPerson.FullName));
  184. mail.Subject = "Uni-Vate - Password Reset Request";
  185. mail.Body = body;
  186. mail.IsBodyHtml = true;
  187. mail.BodyEncoding = Encoding.ASCII;
  188. mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
  189. mail.Sender = new MailAddress(host.User, "UniVate Properties");
  190. mail.From = mail.Sender;
  191. smtp.UseDefaultCredentials = host.NeedsAuthorize;
  192. smtp.Credentials = host.GetNetworkCredential();
  193. smtp.EnableSsl = host.UseSSL;
  194. smtp.Send(mail);
  195. }
  196. }
  197. public void WeekOfferMadeOwner(TimeshareWeek week, BidItem bid)
  198. {
  199. var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "WeekOfferMade-Owner").Where(y => y.IsDeleted == false).ToList();
  200. string body = _dbContext.Templates.Where(x => x.Name == "WeekOfferMade-Owner").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
  201. body = body.Replace("[OWNER]", week.DisplayOwner);
  202. body = body.Replace("[RESORTNAME]", week.ResortName);
  203. body = body.Replace("[UNITNUMBER]", week.UnitNumber);
  204. body = body.Replace("[MODULE]", week.Module);
  205. body = body.Replace("[OFFERMADE]", bid.Amount.ToString());
  206. body = body.Replace("[FULLNAME]", bid.BidMaker.Display);
  207. body = body.Replace("[USEREMAIL]", bid.BidMaker.Email);
  208. body = body.Replace("[USERCELLPHONE]", bid.BidMaker.CellNumber);
  209. body = body.Replace("[USERTELEPHONE]", bid.BidMaker.Telephone);
  210. body = body.Replace("[USERCOMMENT]", bid.Comment);
  211. body = body.Replace("[USERCONSENT]", bid.Consent.ToString());
  212. string toList = "";
  213. int emailCount = 0;
  214. foreach (var recipient in recipients)
  215. {
  216. toList += recipient.RecipientMail + ", ";
  217. emailCount++;
  218. }
  219. if (toList.Length > 0)
  220. {
  221. if (emailCount == 1)
  222. toList = toList.Substring(0, toList.Length - 2);
  223. else
  224. toList = toList.Substring(0, toList.Length - 2);
  225. }
  226. try
  227. {
  228. var host = _dbContext.Hosts.FirstOrDefault();
  229. using (SmtpClient smtp = new SmtpClient(host.Host))
  230. {
  231. MailMessage mail = new MailMessage();
  232. mail.To.Add(toList);
  233. mail.Subject = "Uni-Vate - New Contact Request";
  234. mail.Body = body;
  235. mail.IsBodyHtml = true;
  236. mail.BodyEncoding = Encoding.ASCII;
  237. mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
  238. mail.Sender = new MailAddress(host.User, "UniVate Properties");
  239. mail.From = mail.Sender;
  240. smtp.UseDefaultCredentials = host.NeedsAuthorize;
  241. smtp.Credentials = host.GetNetworkCredential();
  242. smtp.EnableSsl = host.UseSSL;
  243. smtp.Send(mail);
  244. }
  245. }
  246. catch (Exception ex)
  247. {
  248. error = ex.ToString();
  249. }
  250. }
  251. public void WeekOfferMadeUser(TimeshareWeek week, BidItem bid)
  252. {
  253. //var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "WeekOfferMade-User").Where(y => y.IsDeleted == false).ToList();
  254. string body = _dbContext.Templates.Where(x => x.Name == "WeekOfferMade-User").Where(y => y.IsDeleted == false).FirstOrDefault().Body; ;
  255. body = body.Replace("[OWNER]", week.DisplayOwner);
  256. body = body.Replace("[RESORTNAME]", week.ResortName);
  257. body = body.Replace("[UNITNUMBER]", week.UnitNumber);
  258. body = body.Replace("[MODULE]", week.Module);
  259. body = body.Replace("[OFFERMADE]", bid.Amount.ToString());
  260. body = body.Replace("[FULLNAME]", bid.BidMaker.Display);
  261. body = body.Replace("[USEREMAIL]", bid.BidMaker.Email);
  262. body = body.Replace("[USERCELLPHONE]", bid.BidMaker.CellNumber);
  263. body = body.Replace("[USERTELEPHONE]", bid.BidMaker.Telephone);
  264. body = body.Replace("[USERCOMMENT]", bid.Comment);
  265. body = body.Replace("[USERCONSENT]", bid.Consent.ToString());
  266. try
  267. {
  268. var host = _dbContext.Hosts.FirstOrDefault();
  269. using (SmtpClient smtp = new SmtpClient(host.Host))
  270. {
  271. MailMessage mail = new MailMessage();
  272. mail.To.Add(bid.BidMaker.Email);
  273. mail.Subject = "Uni-Vate - New Contact Request";
  274. mail.Body = body;
  275. mail.IsBodyHtml = true;
  276. mail.BodyEncoding = Encoding.ASCII;
  277. mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
  278. mail.Sender = new MailAddress(host.User, "UniVate Properties");
  279. mail.From = mail.Sender;
  280. smtp.UseDefaultCredentials = host.NeedsAuthorize;
  281. smtp.Credentials = host.GetNetworkCredential();
  282. smtp.EnableSsl = host.UseSSL;
  283. smtp.Send(mail);
  284. }
  285. error = "None";
  286. }
  287. catch (Exception ex)
  288. {
  289. error = ex.ToString();
  290. }
  291. }
  292. public void WeekOfferMadeAdmin()
  293. {
  294. }
  295. public void WeekLoadedAgent(TimeshareWeekDto week)
  296. {
  297. string body = _dbContext.Templates.Where(x => x.Name == "WeekLoaded-Agent").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
  298. var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "WeekLoaded-Agent").Where(y => y.IsDeleted == false).ToList();
  299. #region ResortFields
  300. body = body.Replace("[RESORTNAME]", " " + week.ResortName);
  301. body = body.Replace("[UNITNUMBER]", " " + week.UnitNumber);
  302. body = body.Replace("[MODULE]", " " + week.Module);
  303. body = body.Replace("[RESORTPRICE]", " " + week.SellPrice.ToString());
  304. body = body.Replace("[RESORTSEASON]", " " + week.Season);
  305. body = body.Replace("[RESORTREGION]", " " + week.Region.Display);
  306. body = body.Replace("[RESORTLEVY]", " " + week.LevyAmount.ToString());
  307. body = body.Replace("[OWNER]", " " + week.DisplayOwner);
  308. body = body.Replace("[SLEEPMAX]", " " + week.MaxSleep.ToString());
  309. body = body.Replace("[WEEK]", " " + week.WeekNumber);
  310. body = body.Replace("[BEDROOMS]", " " + week.Bedrooms);
  311. body = body.Replace("[ASKINGPRICE]", " " + week.AskingPrice.ToString());
  312. body = body.Replace("[ARRIVALDATE]", " " + week.ArrivalDate.ToString());
  313. body = body.Replace("[DEPARTUREDATE]", " " + week.DepartureDate.ToString());
  314. body = body.Replace("[AGENTREFER]", week.ReferedByAgent ? " Yes" : " No");
  315. body = body.Replace("[ALLLEVY]", week.LeviesPaidInFull ? " Yes" : " No");
  316. body = body.Replace("[WEEKPLACEDFORRENTAL]", week.WeekPlacedForRental ? " Yes" : " No");
  317. body = body.Replace("[ORIGINALPURCHASEDATE]", " " + week.OriginalPurchaseDate.ToString());
  318. body = body.Replace("[CUROCCUPATIONDATES]", " " + week.ArrivalDate.ToString() + " - " + week.DepartureDate.ToString());
  319. body = body.Replace("[ORIGINALPURCHASEPRICE]", " " + week.OriginalPurchasePrice.ToString());
  320. body = body.Replace("[AGENTCOMM]", " " + week.AgentCommision.ToString());
  321. #endregion
  322. #region UserFields
  323. body = body.Replace("[FULLNAME]", " " + week.DisplayOwner);
  324. body = body.Replace("[USEREMAIL]", " " + week.OwnerObject.EmailAddress);
  325. body = body.Replace("[USERCELLPHONE]", " " + week.OwnerObject.CellNumber);
  326. body = body.Replace("[USERTELEPHONE]", " " + week.OwnerObject.LandlineNumber);
  327. #endregion
  328. string toList = "";
  329. int emailCount = 0;
  330. foreach (var recipient in recipients)
  331. {
  332. toList += recipient.RecipientMail + ", ";
  333. emailCount++;
  334. }
  335. if (toList.Length > 0)
  336. {
  337. if (emailCount == 1)
  338. toList = toList.Substring(0, toList.Length - 2);
  339. else
  340. toList = toList.Substring(0, toList.Length - 2);
  341. }
  342. var host = _dbContext.Hosts.FirstOrDefault();
  343. using (SmtpClient smtp = new SmtpClient(host.Host))
  344. {
  345. MailMessage mail = new MailMessage();
  346. mail.To.Add(toList);
  347. mail.Subject = "Uni-Vate - Week Loaded by Agent";
  348. mail.Body = body;
  349. mail.IsBodyHtml = true;
  350. mail.BodyEncoding = Encoding.ASCII;
  351. mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
  352. mail.Sender = new MailAddress(host.User, "UniVate Properties");
  353. mail.From = mail.Sender;
  354. smtp.UseDefaultCredentials = host.NeedsAuthorize;
  355. smtp.Credentials = host.GetNetworkCredential();
  356. smtp.EnableSsl = host.UseSSL;
  357. smtp.Send(mail);
  358. }
  359. }
  360. public void WeekLoadedOwner(TimeshareWeekDto week)
  361. {
  362. string body = _dbContext.Templates.Where(x => x.Name == "WeekLoaded-Owner").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
  363. var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "WeekLoaded-Owner").Where(y => y.IsDeleted == false).ToList();
  364. #region ResortFields
  365. body = body.Replace("[RESORTNAME]", " " + week.ResortName);
  366. body = body.Replace("[UNITNUMBER]", " " + week.UnitNumber);
  367. body = body.Replace("[MODULE]", " " + week.Module);
  368. body = body.Replace("[RESORTPRICE]", " " + week.SellPrice.ToString());
  369. body = body.Replace("[RESORTSEASON]", " " + week.Season);
  370. body = body.Replace("[RESORTREGION]", " " + week.Region.Display);
  371. body = body.Replace("[RESORTLEVY]", " " + week.LevyAmount.ToString());
  372. body = body.Replace("[OWNER]", " " + week.DisplayOwner);
  373. body = body.Replace("[SLEEPMAX]", " " + week.MaxSleep.ToString());
  374. body = body.Replace("[WEEK]", " " + week.WeekNumber);
  375. body = body.Replace("[BEDROOMS]", " " + week.Bedrooms);
  376. body = body.Replace("[ASKINGPRICE]", " " + week.AskingPrice.ToString());
  377. body = body.Replace("[ARRIVALDATE]", " " + week.ArrivalDate.ToString());
  378. body = body.Replace("[DEPARTUREDATE]", " " + week.DepartureDate.ToString());
  379. body = body.Replace("[AGENTREFER]", week.ReferedByAgent ? " Yes" : " No");
  380. body = body.Replace("[ALLLEVY]", week.LeviesPaidInFull ? " Yes" : " No");
  381. body = body.Replace("[WEEKPLACEDFORRENTAL]", week.WeekPlacedForRental ? " Yes" : " No");
  382. body = body.Replace("[ORIGINALPURCHASEDATE]", " " + week.OriginalPurchaseDate.ToString());
  383. body = body.Replace("[CUROCCUPATIONDATES]", " " + week.ArrivalDate.ToString() + " - " + week.DepartureDate.ToString());
  384. body = body.Replace("[ORIGINALPURCHASEPRICE]", " " + week.OriginalPurchasePrice.ToString());
  385. body = body.Replace("[AGENTCOMM]", " " + week.AgentCommision.ToString());
  386. #endregion
  387. #region UserFields
  388. body = body.Replace("[FULLNAME]", " " + week.DisplayOwner );
  389. body = body.Replace("[USEREMAIL]", " " + week.OwnerObject.EmailAddress);
  390. body = body.Replace("[USERCELLPHONE]", " " + week.OwnerObject.CellNumber);
  391. body = body.Replace("[USERTELEPHONE]", " " + week.OwnerObject.LandlineNumber);
  392. #endregion
  393. string toList = "";
  394. int emailCount = 0;
  395. foreach (var recipient in recipients)
  396. {
  397. toList += recipient.RecipientMail + ", ";
  398. emailCount++;
  399. }
  400. if (toList.Length > 0)
  401. {
  402. if (emailCount == 1)
  403. toList = toList.Substring(0, toList.Length - 2);
  404. else
  405. toList = toList.Substring(0, toList.Length - 2);
  406. }
  407. var host = _dbContext.Hosts.FirstOrDefault();
  408. using (SmtpClient smtp = new SmtpClient(host.Host))
  409. {
  410. MailMessage mail = new MailMessage();
  411. mail.To.Add(toList);
  412. mail.Subject = "Uni-Vate - Week Loaded";
  413. mail.Body = body;
  414. mail.IsBodyHtml = true;
  415. mail.BodyEncoding = Encoding.ASCII;
  416. mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
  417. mail.Sender = new MailAddress(host.User, "UniVate Properties");
  418. mail.From = mail.Sender;
  419. smtp.UseDefaultCredentials = host.NeedsAuthorize;
  420. smtp.Credentials = host.GetNetworkCredential();
  421. smtp.EnableSsl = host.UseSSL;
  422. smtp.Send(mail);
  423. }
  424. }
  425. public void AddRecipient(MailRecipient rec)
  426. {
  427. if (MyCommon.IsValidEmail(rec.RecipientMail))
  428. {
  429. _dbContext.MailRecipients.Add(rec);
  430. _dbContext.SaveChanges();
  431. }
  432. else
  433. {
  434. throw new Exception();
  435. }
  436. }
  437. public List<MailRecipient> GetMailRecipients()
  438. {
  439. return _dbContext.MailRecipients.Where(x => x.IsDeleted == false).ToList();
  440. }
  441. public MailRecipient GetMailRecipientById(int id)
  442. {
  443. return _dbContext.MailRecipients.Where(x => x.Id == id).FirstOrDefault();
  444. }
  445. public void UpdateMailRecipient(MailRecipient rec)
  446. {
  447. var recipient = _dbContext.MailRecipients.Where(x => x.Id == rec.Id).FirstOrDefault();
  448. if (recipient.RecipientMail != rec.RecipientMail)
  449. {
  450. recipient.RecipientMail = rec.RecipientMail;
  451. }
  452. if (recipient.RecipientName != rec.RecipientName)
  453. {
  454. recipient.RecipientName = rec.RecipientName;
  455. }
  456. if (recipient.RecipientUsage != rec.RecipientUsage)
  457. {
  458. recipient.RecipientUsage = rec.RecipientUsage;
  459. }
  460. _dbContext.MailRecipients.Update(recipient);
  461. _dbContext.SaveChanges();
  462. }
  463. public void DeleteMailRecipient(int id)
  464. {
  465. var rec = _dbContext.MailRecipients.Where(x => x.Id == id).FirstOrDefault();
  466. _dbContext.MailRecipients.Remove(rec);
  467. _dbContext.SaveChanges();
  468. }
  469. public List<MailModel> GetContactUsLog()
  470. {
  471. return _dbContext.CommunicationLog.Include("MailSource").Where(x => x.ComType == "Contact Us").ToList();
  472. }
  473. public List<MailModel> GetEnquireNowLog()
  474. {
  475. return _dbContext.CommunicationLog.Where(x => x.ComType == "Enquire Now").ToList();
  476. }
  477. }
  478. }