瀏覽代碼

Add Consent to Timeshare Buy and Sell and ContactUs

master
Brian Conway 2 年之前
父節點
當前提交
65f10302f1
共有 25 個檔案被更改,包括 9899 行新增53 行删除
  1. 1
    0
      UnivateProperties_API/Containers/ProcessFlow/BidItemDisplay.cs
  2. 2
    0
      UnivateProperties_API/Containers/Timeshare/WeekDto.cs
  3. 4
    1
      UnivateProperties_API/Context/DataContext.cs
  4. 64
    0
      UnivateProperties_API/Controllers/Communication/MailSourceController.cs
  5. 4
    5
      UnivateProperties_API/Migrations/20220720084941_MailModel.Designer.cs
  6. 3
    4
      UnivateProperties_API/Migrations/20220720084941_MailModel.cs
  7. 1898
    0
      UnivateProperties_API/Migrations/20220721092254_MailSources.Designer.cs
  8. 63
    0
      UnivateProperties_API/Migrations/20220721092254_MailSources.cs
  9. 1898
    0
      UnivateProperties_API/Migrations/20220804103536_ContactUsMailSourceDescription.Designer.cs
  10. 17
    0
      UnivateProperties_API/Migrations/20220804103536_ContactUsMailSourceDescription.cs
  11. 1900
    0
      UnivateProperties_API/Migrations/20220829091410_addConsentCommunicationAndWeeks.Designer.cs
  12. 23
    0
      UnivateProperties_API/Migrations/20220829091410_addConsentCommunicationAndWeeks.cs
  13. 1902
    0
      UnivateProperties_API/Migrations/20220829091928_AddConsentTimeshareWeek.Designer.cs
  14. 23
    0
      UnivateProperties_API/Migrations/20220829091928_AddConsentTimeshareWeek.cs
  15. 1904
    0
      UnivateProperties_API/Migrations/20220830051240_BidItemAddConsent.Designer.cs
  16. 23
    0
      UnivateProperties_API/Migrations/20220830051240_BidItemAddConsent.cs
  17. 10
    5
      UnivateProperties_API/Migrations/DataContextModelSnapshot.cs
  18. 2
    1
      UnivateProperties_API/Model/Communication/MailModel.cs
  19. 1
    1
      UnivateProperties_API/Model/Communication/MailSource.cs
  20. 2
    0
      UnivateProperties_API/Model/ProcessFlow/BidItem.cs
  21. 1
    0
      UnivateProperties_API/Model/Timeshare/TimeshareWeek.cs
  22. 56
    35
      UnivateProperties_API/Repository/Communication/MailRepository.cs
  23. 96
    0
      UnivateProperties_API/Repository/Communication/MailSourceRepository.cs
  24. 1
    1
      UnivateProperties_API/Startup.cs
  25. 1
    0
      UnivateProperties_API/appsettings.json

+ 1
- 0
UnivateProperties_API/Containers/ProcessFlow/BidItemDisplay.cs 查看文件

@@ -20,6 +20,7 @@ namespace UnivateProperties_API.Containers.ProcessFlow
20 20
         public string MadeBy { get; set; }
21 21
         public DateTime Date { get; set; }
22 22
         public string Comment { get; set; }
23
+        public bool Consent { get; set; }
23 24
         public string DeclineReason { get; set; }
24 25
         public decimal SellPrice { get; set; }
25 26
         #endregion 

+ 2
- 0
UnivateProperties_API/Containers/Timeshare/WeekDto.cs 查看文件

@@ -139,6 +139,7 @@ namespace UnivateProperties_API.Containers.Timeshare
139 139
             Publish = week.Publish;
140 140
             PulbishedDate = week.PulbishedDate;
141 141
             CustomOwner = week.CustomOwner;
142
+            Consent = week.Consent;
142 143
         }
143 144
 
144 145
         public int Id { get; set; }
@@ -175,5 +176,6 @@ namespace UnivateProperties_API.Containers.Timeshare
175 176
         public bool Publish { get; set; }
176 177
         public DateTime PulbishedDate { get; set; }
177 178
         public bool CustomOwner {get; set;}
179
+        public bool Consent { get; set; }
178 180
     }
179 181
 }

+ 4
- 1
UnivateProperties_API/Context/DataContext.cs 查看文件

@@ -19,6 +19,8 @@ namespace UnivateProperties_API.Context
19 19
     public class DataContext : DbContext
20 20
     {
21 21
         private string connectionString = "";
22
+        internal object BidItem;
23
+
22 24
         public DataContext(DbContextOptions<DataContext> options) : base(options)
23 25
         {
24 26
             foreach (var extention in options.Extensions)
@@ -59,7 +61,7 @@ namespace UnivateProperties_API.Context
59 61
         public virtual DbSet<PlaceHolder> PlaceHolders { get; set; }
60 62
         public virtual DbSet<MailRecipient> MailRecipients { get; set; }
61 63
         public virtual DbSet<MailModel> CommunicationLog { get; set; }
62
-        public virtual DbSet<MailSource> MailSource { get; set; }
64
+        public virtual DbSet<MailSource> MailSources { get; set; }
63 65
         #endregion Communication
64 66
 
65 67
         #region Property
@@ -220,6 +222,7 @@ namespace UnivateProperties_API.Context
220 222
             modelBuilder.Entity<CampaignItemPlaceHolder>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
221 223
             modelBuilder.Entity<CampaignPlaceHolder>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
222 224
             modelBuilder.Entity<PlaceHolderFormat>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
225
+            modelBuilder.Entity<MailSource>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
223 226
         }
224 227
 
225 228
 

+ 64
- 0
UnivateProperties_API/Controllers/Communication/MailSourceController.cs 查看文件

@@ -0,0 +1,64 @@
1
+using System.Transactions;
2
+using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Model.Communication;
4
+using UnivateProperties_API.Repository;
5
+
6
+namespace UnivateProperties_API.Controllers.Communication
7
+{
8
+    [Route("api/[controller]")]
9
+    [ApiController]
10
+    public class MailSourceController : ControllerBase
11
+    {
12
+        private readonly IRepository<MailSource> _Repo;
13
+
14
+        public MailSourceController(IRepository<MailSource> repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            return new OkObjectResult(_Repo.GetAll());
23
+        }
24
+
25
+        [HttpGet("{id}")]
26
+        public IActionResult Get(int id)
27
+        {
28
+            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
29
+        }
30
+
31
+        [HttpPost]
32
+        public IActionResult Post([FromBody] MailSource mailSource)
33
+        {
34
+            using (var scope = new TransactionScope())
35
+            {
36
+                _Repo.Insert(mailSource);
37
+                scope.Complete();
38
+                return CreatedAtAction(nameof(Get), new { id = mailSource.Id }, mailSource);
39
+            }
40
+        }
41
+
42
+        [HttpPut]
43
+        public IActionResult Put([FromBody] MailSource mailSource)
44
+        {
45
+            if (mailSource != null)
46
+            {
47
+                using (var scope = new TransactionScope())
48
+                {
49
+                    _Repo.Update(mailSource);
50
+                    scope.Complete();
51
+                    return new OkResult();
52
+                }
53
+            }
54
+            return new NoContentResult();
55
+        }
56
+
57
+        [HttpDelete("{id}")]
58
+        public IActionResult Delete(int id)
59
+        {
60
+            _Repo.RemoveAtId(id);
61
+            return new OkResult();
62
+        }
63
+    }
64
+}

UnivateProperties_API/Migrations/20220714125536_MailSource-MailModel.Designer.cs → UnivateProperties_API/Migrations/20220720084941_MailModel.Designer.cs 查看文件

@@ -10,8 +10,8 @@ using UnivateProperties_API.Context;
10 10
 namespace UnivateProperties_API.Migrations
11 11
 {
12 12
     [DbContext(typeof(DataContext))]
13
-    [Migration("20220714125536_MailSource-MailModel")]
14
-    partial class MailSourceMailModel
13
+    [Migration("20220720084941_MailModel")]
14
+    partial class MailModel
15 15
     {
16 16
         protected override void BuildTargetModel(ModelBuilder modelBuilder)
17 17
         {
@@ -318,7 +318,7 @@ namespace UnivateProperties_API.Migrations
318 318
 
319 319
                     b.Property<bool>("IsDeleted");
320 320
 
321
-                    b.Property<int>("MailSourceId");
321
+                    b.Property<int?>("MailSourceId");
322 322
 
323 323
                     b.Property<string>("Message");
324 324
 
@@ -1670,8 +1670,7 @@ namespace UnivateProperties_API.Migrations
1670 1670
                 {
1671 1671
                     b.HasOne("UnivateProperties_API.Model.Communication.MailSource", "MailSource")
1672 1672
                         .WithMany("MailModels")
1673
-                        .HasForeignKey("MailSourceId")
1674
-                        .OnDelete(DeleteBehavior.Cascade);
1673
+                        .HasForeignKey("MailSourceId");
1675 1674
                 });
1676 1675
 
1677 1676
             modelBuilder.Entity("UnivateProperties_API.Model.Communication.PlaceHolder", b =>

UnivateProperties_API/Migrations/20220714125536_MailSource-MailModel.cs → UnivateProperties_API/Migrations/20220720084941_MailModel.cs 查看文件

@@ -2,15 +2,14 @@
2 2
 
3 3
 namespace UnivateProperties_API.Migrations
4 4
 {
5
-    public partial class MailSourceMailModel : Migration
5
+    public partial class MailModel : Migration
6 6
     {
7 7
         protected override void Up(MigrationBuilder migrationBuilder)
8 8
         {
9 9
             migrationBuilder.AddColumn<int>(
10 10
                 name: "MailSourceId",
11 11
                 table: "CommunicationLog",
12
-                nullable: false,
13
-                defaultValue: 0);
12
+                nullable: true);
14 13
 
15 14
             migrationBuilder.CreateIndex(
16 15
                 name: "IX_CommunicationLog_MailSourceId",
@@ -23,7 +22,7 @@ namespace UnivateProperties_API.Migrations
23 22
                 column: "MailSourceId",
24 23
                 principalTable: "MailSource",
25 24
                 principalColumn: "Id",
26
-                onDelete: ReferentialAction.Cascade);
25
+                onDelete: ReferentialAction.Restrict);
27 26
         }
28 27
 
29 28
         protected override void Down(MigrationBuilder migrationBuilder)

+ 1898
- 0
UnivateProperties_API/Migrations/20220721092254_MailSources.Designer.cs
文件差異過大導致無法顯示
查看文件


+ 63
- 0
UnivateProperties_API/Migrations/20220721092254_MailSources.cs 查看文件

@@ -0,0 +1,63 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class MailSources : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+            migrationBuilder.DropForeignKey(
10
+                name: "FK_CommunicationLog_MailSource_MailSourceId",
11
+                table: "CommunicationLog");
12
+
13
+            migrationBuilder.DropPrimaryKey(
14
+                name: "PK_MailSource",
15
+                table: "MailSource");
16
+
17
+            migrationBuilder.RenameTable(
18
+                name: "MailSource",
19
+                newName: "MailSources");
20
+
21
+            migrationBuilder.AddPrimaryKey(
22
+                name: "PK_MailSources",
23
+                table: "MailSources",
24
+                column: "Id");
25
+
26
+            migrationBuilder.AddForeignKey(
27
+                name: "FK_CommunicationLog_MailSources_MailSourceId",
28
+                table: "CommunicationLog",
29
+                column: "MailSourceId",
30
+                principalTable: "MailSources",
31
+                principalColumn: "Id",
32
+                onDelete: ReferentialAction.Restrict);
33
+        }
34
+
35
+        protected override void Down(MigrationBuilder migrationBuilder)
36
+        {
37
+            migrationBuilder.DropForeignKey(
38
+                name: "FK_CommunicationLog_MailSources_MailSourceId",
39
+                table: "CommunicationLog");
40
+
41
+            migrationBuilder.DropPrimaryKey(
42
+                name: "PK_MailSources",
43
+                table: "MailSources");
44
+
45
+            migrationBuilder.RenameTable(
46
+                name: "MailSources",
47
+                newName: "MailSource");
48
+
49
+            migrationBuilder.AddPrimaryKey(
50
+                name: "PK_MailSource",
51
+                table: "MailSource",
52
+                column: "Id");
53
+
54
+            migrationBuilder.AddForeignKey(
55
+                name: "FK_CommunicationLog_MailSource_MailSourceId",
56
+                table: "CommunicationLog",
57
+                column: "MailSourceId",
58
+                principalTable: "MailSource",
59
+                principalColumn: "Id",
60
+                onDelete: ReferentialAction.Restrict);
61
+        }
62
+    }
63
+}

+ 1898
- 0
UnivateProperties_API/Migrations/20220804103536_ContactUsMailSourceDescription.Designer.cs
文件差異過大導致無法顯示
查看文件


+ 17
- 0
UnivateProperties_API/Migrations/20220804103536_ContactUsMailSourceDescription.cs 查看文件

@@ -0,0 +1,17 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class ContactUsMailSourceDescription : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+
10
+        }
11
+
12
+        protected override void Down(MigrationBuilder migrationBuilder)
13
+        {
14
+
15
+        }
16
+    }
17
+}

+ 1900
- 0
UnivateProperties_API/Migrations/20220829091410_addConsentCommunicationAndWeeks.Designer.cs
文件差異過大導致無法顯示
查看文件


+ 23
- 0
UnivateProperties_API/Migrations/20220829091410_addConsentCommunicationAndWeeks.cs 查看文件

@@ -0,0 +1,23 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class addConsentCommunicationAndWeeks : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+            migrationBuilder.AddColumn<bool>(
10
+                name: "Consent",
11
+                table: "CommunicationLog",
12
+                nullable: false,
13
+                defaultValue: false);
14
+        }
15
+
16
+        protected override void Down(MigrationBuilder migrationBuilder)
17
+        {
18
+            migrationBuilder.DropColumn(
19
+                name: "Consent",
20
+                table: "CommunicationLog");
21
+        }
22
+    }
23
+}

+ 1902
- 0
UnivateProperties_API/Migrations/20220829091928_AddConsentTimeshareWeek.Designer.cs
文件差異過大導致無法顯示
查看文件


+ 23
- 0
UnivateProperties_API/Migrations/20220829091928_AddConsentTimeshareWeek.cs 查看文件

@@ -0,0 +1,23 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class AddConsentTimeshareWeek : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+            migrationBuilder.AddColumn<bool>(
10
+                name: "Consent",
11
+                table: "Weeks",
12
+                nullable: false,
13
+                defaultValue: false);
14
+        }
15
+
16
+        protected override void Down(MigrationBuilder migrationBuilder)
17
+        {
18
+            migrationBuilder.DropColumn(
19
+                name: "Consent",
20
+                table: "Weeks");
21
+        }
22
+    }
23
+}

+ 1904
- 0
UnivateProperties_API/Migrations/20220830051240_BidItemAddConsent.Designer.cs
文件差異過大導致無法顯示
查看文件


+ 23
- 0
UnivateProperties_API/Migrations/20220830051240_BidItemAddConsent.cs 查看文件

@@ -0,0 +1,23 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class BidItemAddConsent : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+            migrationBuilder.AddColumn<bool>(
10
+                name: "Consent",
11
+                table: "BidItems",
12
+                nullable: false,
13
+                defaultValue: false);
14
+        }
15
+
16
+        protected override void Down(MigrationBuilder migrationBuilder)
17
+        {
18
+            migrationBuilder.DropColumn(
19
+                name: "Consent",
20
+                table: "BidItems");
21
+        }
22
+    }
23
+}

+ 10
- 5
UnivateProperties_API/Migrations/DataContextModelSnapshot.cs 查看文件

@@ -304,6 +304,8 @@ namespace UnivateProperties_API.Migrations
304 304
 
305 305
                     b.Property<string>("ComType");
306 306
 
307
+                    b.Property<bool>("Consent");
308
+
307 309
                     b.Property<DateTime>("Created");
308 310
 
309 311
                     b.Property<string>("Email");
@@ -316,7 +318,7 @@ namespace UnivateProperties_API.Migrations
316 318
 
317 319
                     b.Property<bool>("IsDeleted");
318 320
 
319
-                    b.Property<int>("MailSourceId");
321
+                    b.Property<int?>("MailSourceId");
320 322
 
321 323
                     b.Property<string>("Message");
322 324
 
@@ -382,7 +384,7 @@ namespace UnivateProperties_API.Migrations
382 384
 
383 385
                     b.HasKey("Id");
384 386
 
385
-                    b.ToTable("MailSource");
387
+                    b.ToTable("MailSources");
386 388
                 });
387 389
 
388 390
             modelBuilder.Entity("UnivateProperties_API.Model.Communication.PlaceHolder", b =>
@@ -747,6 +749,8 @@ namespace UnivateProperties_API.Migrations
747 749
 
748 750
                     b.Property<string>("Comment");
749 751
 
752
+                    b.Property<bool>("Consent");
753
+
750 754
                     b.Property<DateTime>("Created");
751 755
 
752 756
                     b.Property<string>("DeclinedReason");
@@ -1180,6 +1184,8 @@ namespace UnivateProperties_API.Migrations
1180 1184
 
1181 1185
                     b.Property<string>("Bedrooms");
1182 1186
 
1187
+                    b.Property<bool>("Consent");
1188
+
1183 1189
                     b.Property<DateTime>("Created");
1184 1190
 
1185 1191
                     b.Property<bool>("CurrentYearBanked");
@@ -1667,9 +1673,8 @@ namespace UnivateProperties_API.Migrations
1667 1673
             modelBuilder.Entity("UnivateProperties_API.Model.Communication.MailModel", b =>
1668 1674
                 {
1669 1675
                     b.HasOne("UnivateProperties_API.Model.Communication.MailSource", "MailSource")
1670
-                        .WithMany("MailModels")
1671
-                        .HasForeignKey("MailSourceId")
1672
-                        .OnDelete(DeleteBehavior.Cascade);
1676
+                        .WithMany()
1677
+                        .HasForeignKey("MailSourceId");
1673 1678
                 });
1674 1679
 
1675 1680
             modelBuilder.Entity("UnivateProperties_API.Model.Communication.PlaceHolder", b =>

+ 2
- 1
UnivateProperties_API/Model/Communication/MailModel.cs 查看文件

@@ -14,8 +14,9 @@ namespace UnivateProperties_API.Model.Communication
14 14
         public string Message { get; set; }
15 15
         public string HeardFrom { get; set; }
16 16
         [ForeignKey("MailSource")]
17
-        public int MailSourceId { get; set; }
17
+        public int? MailSourceId { get; set; }
18 18
         public virtual MailSource MailSource { get; set; }
19 19
         public string Error { get; set; }
20
+        public bool Consent { get; set; }
20 21
     }
21 22
 }

+ 1
- 1
UnivateProperties_API/Model/Communication/MailSource.cs 查看文件

@@ -8,6 +8,6 @@ namespace UnivateProperties_API.Model.Communication
8 8
     public class MailSource : BaseEntity
9 9
     {
10 10
         public string Description { get; set; }
11
-        public ICollection<MailModel> MailModels { get; set; }
11
+        public override string Display => Description;
12 12
     }
13 13
 }

+ 2
- 0
UnivateProperties_API/Model/ProcessFlow/BidItem.cs 查看文件

@@ -14,11 +14,13 @@ namespace UnivateProperties_API.Model.ProcessFlow
14 14
         public int? PropertyId { get; set; }
15 15
         public string Comment { get; set; }
16 16
         public string DeclinedReason { get; set; }
17
+        public bool Consent { get; set; }
17 18
 
18 19
         public virtual Status Status { get; set; }
19 20
         public virtual Individual BidMaker { get; set; }
20 21
         public virtual TimeshareWeek TimeshareWeek {get;set;}
21 22
         public virtual Property Property { get; set; }
23
+
22 24
         #endregion
23 25
     }
24 26
 }

+ 1
- 0
UnivateProperties_API/Model/Timeshare/TimeshareWeek.cs 查看文件

@@ -107,6 +107,7 @@ namespace UnivateProperties_API.Model.Timeshare
107 107
         public string WeekStatus { get; set; }
108 108
         public bool Publish { get; set; }
109 109
         public DateTime PulbishedDate { get; set; }
110
+        public bool Consent { get; set; }
110 111
         #endregion
111 112
 
112 113
         #region Navigation

+ 56
- 35
UnivateProperties_API/Repository/Communication/MailRepository.cs 查看文件

@@ -1,7 +1,9 @@
1 1
 using Abp.Specifications;
2
+using Microsoft.EntityFrameworkCore;
2 3
 using MimeKit;
3 4
 using System;
4 5
 using System.Collections.Generic;
6
+using System.Dynamic;
5 7
 using System.Linq;
6 8
 using System.Linq.Dynamic.Core;
7 9
 using System.Net.Mail;
@@ -33,7 +35,7 @@ namespace UnivateProperties_API.Repository.Communication
33 35
     public class MailRepository : IMailRepository
34 36
     {
35 37
         private readonly DataContext _dbContext;
36
-
38
+        string error;
37 39
         public MailRepository(DataContext db)
38 40
         {
39 41
             _dbContext = db;              
@@ -47,13 +49,17 @@ namespace UnivateProperties_API.Repository.Communication
47 49
         {            
48 50
             var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "ContactUs").Where(y => y.IsDeleted == false).ToList();            
49 51
             string body = _dbContext.Templates.Where(x => x.Name == "ContactUs").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
50
-            string error = "";
52
+            var source = _dbContext.MailSources.Where(x => x.Id == Convert.ToInt32(mm.MailSourceId)).FirstOrDefault();
53
+
51 54
 
52 55
             body = body.Replace("[FULLNAME]", mm.Name);
53 56
             body = body.Replace("[USEREMAIL]", mm.Email);
54 57
             body = body.Replace("[USERCELLPHONE]", mm.Phone);
55 58
             body = body.Replace("[PROPERTYREF]", mm.Property);
59
+            body = body.Replace("[SOURCE]", source.Description);
56 60
             body = body.Replace("[USERMESSAGE]", mm.Message);
61
+            body = body.Replace("[USERCONSENT]", mm.Consent.ToString());
62
+
57 63
 
58 64
             string toList = "";
59 65
             int emailCount = 0;
@@ -226,6 +232,7 @@ namespace UnivateProperties_API.Repository.Communication
226 232
             body = body.Replace("[USERCELLPHONE]", bid.BidMaker.CellNumber);
227 233
             body = body.Replace("[USERTELEPHONE]", bid.BidMaker.Telephone);
228 234
             body = body.Replace("[USERCOMMENT]", bid.Comment);
235
+            body = body.Replace("[USERCONSENT]", bid.Consent.ToString());
229 236
 
230 237
             string toList = "";
231 238
             int emailCount = 0;
@@ -243,23 +250,30 @@ namespace UnivateProperties_API.Repository.Communication
243 250
                     toList = toList.Substring(0, toList.Length - 2);
244 251
             }
245 252
 
246
-            var host = _dbContext.Hosts.FirstOrDefault();
247
-            using (SmtpClient smtp = new SmtpClient(host.Host))
253
+            try
248 254
             {
249
-                MailMessage mail = new MailMessage();
250
-                mail.To.Add(toList);
251
-                mail.Subject = "Uni-Vate - New Contact Request";
252
-                mail.Body = body;
253
-                mail.IsBodyHtml = true;
254
-                mail.BodyEncoding = Encoding.ASCII;
255
-                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
256
-                mail.Sender = new MailAddress(host.User, "UniVate Properties");
257
-                mail.From = mail.Sender;
255
+                var host = _dbContext.Hosts.FirstOrDefault();
256
+                using (SmtpClient smtp = new SmtpClient(host.Host))
257
+                {
258
+                    MailMessage mail = new MailMessage();
259
+                    mail.To.Add(toList);
260
+                    mail.Subject = "Uni-Vate - New Contact Request";
261
+                    mail.Body = body;
262
+                    mail.IsBodyHtml = true;
263
+                    mail.BodyEncoding = Encoding.ASCII;
264
+                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
265
+                    mail.Sender = new MailAddress(host.User, "UniVate Properties");
266
+                    mail.From = mail.Sender;
258 267
 
259
-                smtp.UseDefaultCredentials = host.NeedsAuthorize;
260
-                smtp.Credentials = host.GetNetworkCredential();
261
-                smtp.EnableSsl = host.UseSSL;
262
-                smtp.Send(mail);
268
+                    smtp.UseDefaultCredentials = host.NeedsAuthorize;
269
+                    smtp.Credentials = host.GetNetworkCredential();
270
+                    smtp.EnableSsl = host.UseSSL;
271
+                    smtp.Send(mail);
272
+                }
273
+            }
274
+            catch (Exception ex)
275
+            {
276
+                error = ex.ToString();
263 277
             }
264 278
         }
265 279
 
@@ -279,26 +293,33 @@ namespace UnivateProperties_API.Repository.Communication
279 293
             body = body.Replace("[USERCELLPHONE]", bid.BidMaker.CellNumber);
280 294
             body = body.Replace("[USERTELEPHONE]", bid.BidMaker.Telephone);
281 295
             body = body.Replace("[USERCOMMENT]", bid.Comment);
296
+            body = body.Replace("[USERCONSENT]", bid.Consent.ToString());
282 297
 
283
-
284
-
285
-            var host = _dbContext.Hosts.FirstOrDefault();
286
-            using (SmtpClient smtp = new SmtpClient(host.Host))
298
+            try
287 299
             {
288
-                MailMessage mail = new MailMessage();
289
-                mail.To.Add(bid.BidMaker.Email);
290
-                mail.Subject = "Uni-Vate - New Contact Request";
291
-                mail.Body = body;
292
-                mail.IsBodyHtml = true;
293
-                mail.BodyEncoding = Encoding.ASCII;
294
-                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
295
-                mail.Sender = new MailAddress(host.User, "UniVate Properties");
296
-                mail.From = mail.Sender;
300
+                var host = _dbContext.Hosts.FirstOrDefault();
301
+                using (SmtpClient smtp = new SmtpClient(host.Host))
302
+                {
303
+                    MailMessage mail = new MailMessage();
304
+                    mail.To.Add(bid.BidMaker.Email);
305
+                    mail.Subject = "Uni-Vate - New Contact Request";
306
+                    mail.Body = body;
307
+                    mail.IsBodyHtml = true;
308
+                    mail.BodyEncoding = Encoding.ASCII;
309
+                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
310
+                    mail.Sender = new MailAddress(host.User, "UniVate Properties");
311
+                    mail.From = mail.Sender;
297 312
 
298
-                smtp.UseDefaultCredentials = host.NeedsAuthorize;
299
-                smtp.Credentials = host.GetNetworkCredential();
300
-                smtp.EnableSsl = host.UseSSL;
301
-                smtp.Send(mail);
313
+                    smtp.UseDefaultCredentials = host.NeedsAuthorize;
314
+                    smtp.Credentials = host.GetNetworkCredential();
315
+                    smtp.EnableSsl = host.UseSSL;
316
+                    smtp.Send(mail);
317
+                }
318
+                error = "None";
319
+            }
320
+            catch (Exception ex)
321
+            {
322
+                error = ex.ToString();
302 323
             }
303 324
         }
304 325
 
@@ -508,7 +529,7 @@ namespace UnivateProperties_API.Repository.Communication
508 529
 
509 530
         public List<MailModel> GetContactUsLog()
510 531
         {
511
-            return _dbContext.CommunicationLog.Where(x => x.ComType == "Contact Us").ToList();            
532
+            return _dbContext.CommunicationLog.Include("MailSource").Where(x => x.ComType == "Contact Us").ToList();
512 533
         }
513 534
 
514 535
         public List<MailModel> GetEnquireNowLog()

+ 96
- 0
UnivateProperties_API/Repository/Communication/MailSourceRepository.cs 查看文件

@@ -0,0 +1,96 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using System.Linq.Dynamic.Core;
6
+using UnivateProperties_API.Context;
7
+using UnivateProperties_API.Model.Communication;
8
+
9
+namespace UnivateProperties_API.Repository.Communication
10
+{
11
+    public class MailSourceRepository : IRepository<MailSource>
12
+    {
13
+        private readonly DataContext dBContext;
14
+
15
+        public MailSourceRepository(DataContext _dBContext)
16
+        {
17
+            dBContext = _dBContext;
18
+        }
19
+
20
+        public List<MailSource> Get(Func<MailSource, bool> where)
21
+        {
22
+            return dBContext.MailSources.Where(where).ToList();
23
+        }
24
+
25
+        public List<MailSource> GetAll()
26
+        {
27
+            return dBContext.MailSources.OrderBy(p => p.Description).ToList();
28
+        }
29
+
30
+        public MailSource GetDetailed(Func<MailSource, bool> first)
31
+        {
32
+            return dBContext.MailSources.FirstOrDefault(first);
33
+        }
34
+
35
+        public List<MailSource> GetDetailedAll()
36
+        {
37
+            return dBContext.MailSources.ToList();
38
+        }
39
+
40
+        public void Insert(MailSource item)
41
+        {
42
+            dBContext.MailSources.Add(item);
43
+            Save();
44
+        }
45
+
46
+        public void Insert(IEnumerable<MailSource> items)
47
+        {
48
+            foreach (var item in items)
49
+            {
50
+                dBContext.MailSources.Add(item);
51
+                Save();
52
+            }
53
+        }
54
+
55
+        public void Remove(MailSource item)
56
+        {
57
+            dBContext.MailSources.Remove(item);
58
+            Save();
59
+        }
60
+
61
+        public void Remove(IEnumerable<MailSource> items)
62
+        {
63
+            foreach (var item in items)
64
+            {
65
+                dBContext.MailSources.Remove(item);
66
+            }
67
+            Save();
68
+        }
69
+
70
+        public void RemoveAtId(int item)
71
+        {
72
+            var mailSource = Get(x => x.Id == item).FirstOrDefault();
73
+            if (mailSource != null)
74
+            {
75
+                dBContext.MailSources.Remove(mailSource);
76
+                Save();
77
+            }
78
+        }
79
+
80
+        public void Save()
81
+        {
82
+            dBContext.SaveChanges();
83
+        }
84
+
85
+        public void Update(MailSource item)
86
+        {
87
+            dBContext.Entry(item).State = EntityState.Modified;
88
+            Save();
89
+        }
90
+
91
+        public int NewId()
92
+        {
93
+            return 0;
94
+        }
95
+    }
96
+}

+ 1
- 1
UnivateProperties_API/Startup.cs 查看文件

@@ -154,7 +154,7 @@ namespace UnivateProperties_API
154 154
             services.AddTransient<IRepository<SMTPAccount>, SMTPAccountRepository>();
155 155
             services.AddTransient<IRepository<SMTPHost>, SMTPHostRepository>();
156 156
             services.AddTransient<IMailRepository, MailRepository>();
157
-
157
+            services.AddTransient<IRepository<MailSource>, MailSourceRepository>();
158 158
             #endregion Communication
159 159
             #region Logs 
160 160
             services.AddTransient<ISearchLogRepository, SearchLogRepository>();

+ 1
- 0
UnivateProperties_API/appsettings.json 查看文件

@@ -11,6 +11,7 @@
11 11
   "ConnectionStrings": {
12 12
     "DefaultConnection": "Data Source=localhost;Initial Catalog=UniVate;Integrated Security=true;Pooling=false;",
13 13
     //"DefaultConnection": "Data Source=localhost;Initial Catalog=UniVateDemo;Persist Security Info=True;User Id=sa;Password=What123!;Pooling=false;",
14
+    //"DefaultConnection": "Data Source=192.168.0.219;Initial Catalog=UniVateDemo;Persist Security Info=True;User Id=sa;Password=What123!;Pooling=false;",
14 15
     //"DefaultConnection": "Data Source=localhost;Initial Catalog=UniVate;Persist Security Info=True;User Id=Provision;Password=J%Xvk8xGeT;Pooling=false;",
15 16
     //"DefaultConnection": "Data Source=192.168.0.101;Initial Catalog=UniVate;Persist Security Info=True;User Id=Provision;Password=J%Xvk8xGeT;Pooling=false;",
16 17
     "TenderConnection": "http://www.unipoint-consoft.co.za/nph-srep.exe?cluvavail.sch&CLUB=LPA&RESORT=ALL&SUMMARY=N&HEAD=N",

Loading…
取消
儲存