瀏覽代碼

Email Recipients

master
30117125 4 年之前
父節點
當前提交
e0a9d848f3

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

45
         public virtual DbSet<SMTPHost> Hosts { get; set; }
45
         public virtual DbSet<SMTPHost> Hosts { get; set; }
46
         public virtual DbSet<Template> Templates { get; set; }
46
         public virtual DbSet<Template> Templates { get; set; }
47
         public virtual DbSet<PlaceHolder> PlaceHolders { get; set; }
47
         public virtual DbSet<PlaceHolder> PlaceHolders { get; set; }
48
+        public virtual DbSet<MailRecipient> MailRecipients { get; set; }
48
         #endregion Communication
49
         #endregion Communication
49
 
50
 
50
         #region Property
51
         #region Property

+ 45
- 6
UnivateProperties_API/Controllers/Communication/MailController.cs 查看文件

1
-using System;
2
-using System.Collections.Generic;
3
-using System.Linq;
4
-using System.Threading.Tasks;
5
-using Microsoft.AspNetCore.Http;
6
-using Microsoft.AspNetCore.Mvc;
1
+using Microsoft.AspNetCore.Mvc;
2
+using RestSharp;
7
 using UnivateProperties_API.Model.Communication;
3
 using UnivateProperties_API.Model.Communication;
8
 using UnivateProperties_API.Repository.Communication;
4
 using UnivateProperties_API.Repository.Communication;
9
 
5
 
40
                 return new BadRequestResult();
36
                 return new BadRequestResult();
41
             }
37
             }
42
         }
38
         }
39
+
40
+        [HttpPost("mailrecipient")]
41
+        public IActionResult AddMailRecipient([FromBody] MailRecipient rec)
42
+        {
43
+            try
44
+            {
45
+                _repo.AddRecipient(rec);
46
+                return new OkResult();
47
+            }
48
+            catch
49
+            {
50
+                return new BadRequestResult();
51
+            }
52
+
53
+        }
54
+
55
+        [HttpGet("mailrecipients")]
56
+        public IActionResult GetMailRecipients()
57
+        {
58
+            var recipients = _repo.GetMailRecipients();
59
+            return new OkObjectResult(recipients);
60
+        }
61
+
62
+        [HttpGet("mailrecipient/{id}")]
63
+        public IActionResult GetRecipientById(int id)
64
+        {
65
+            var recipient = _repo.GetMailRecipientById(id);
66
+            return new OkObjectResult(recipient);
67
+        }
68
+
69
+        [HttpPut("mailrecipients")]
70
+        public IActionResult UpdateRecipient([FromBody] MailRecipient rec)
71
+        {
72
+            _repo.UpdateMailRecipient(rec);
73
+            return new OkResult();
74
+        }
75
+
76
+        [HttpDelete("mailrecipient/{id}")]
77
+        public IActionResult DeleteRecipient(int id)
78
+        {
79
+            _repo.DeleteMailRecipient(id);
80
+            return new OkResult();
81
+        }
43
     }
82
     }
44
 }
83
 }

+ 1687
- 0
UnivateProperties_API/Migrations/20201026073628_EmailRecipient.Designer.cs
文件差異過大導致無法顯示
查看文件


+ 37
- 0
UnivateProperties_API/Migrations/20201026073628_EmailRecipient.cs 查看文件

1
+using System;
2
+using Microsoft.EntityFrameworkCore.Metadata;
3
+using Microsoft.EntityFrameworkCore.Migrations;
4
+
5
+namespace UnivateProperties_API.Migrations
6
+{
7
+    public partial class EmailRecipient : Migration
8
+    {
9
+        protected override void Up(MigrationBuilder migrationBuilder)
10
+        {
11
+            migrationBuilder.CreateTable(
12
+                name: "MailRecipients",
13
+                columns: table => new
14
+                {
15
+                    Id = table.Column<int>(nullable: false)
16
+                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
17
+                    Created = table.Column<DateTime>(nullable: false),
18
+                    Modified = table.Column<DateTime>(nullable: false),
19
+                    ModifiedBy = table.Column<string>(nullable: true),
20
+                    IsDeleted = table.Column<bool>(nullable: false),
21
+                    RecipientName = table.Column<string>(nullable: true),
22
+                    RecipientMail = table.Column<string>(nullable: true),
23
+                    RecipientUsage = table.Column<string>(nullable: true)
24
+                },
25
+                constraints: table =>
26
+                {
27
+                    table.PrimaryKey("PK_MailRecipients", x => x.Id);
28
+                });
29
+        }
30
+
31
+        protected override void Down(MigrationBuilder migrationBuilder)
32
+        {
33
+            migrationBuilder.DropTable(
34
+                name: "MailRecipients");
35
+        }
36
+    }
37
+}

+ 25
- 0
UnivateProperties_API/Migrations/DataContextModelSnapshot.cs 查看文件

234
                     b.ToTable("Emails");
234
                     b.ToTable("Emails");
235
                 });
235
                 });
236
 
236
 
237
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.MailRecipient", b =>
238
+                {
239
+                    b.Property<int>("Id")
240
+                        .ValueGeneratedOnAdd()
241
+                        .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
242
+
243
+                    b.Property<DateTime>("Created");
244
+
245
+                    b.Property<bool>("IsDeleted");
246
+
247
+                    b.Property<DateTime>("Modified");
248
+
249
+                    b.Property<string>("ModifiedBy");
250
+
251
+                    b.Property<string>("RecipientMail");
252
+
253
+                    b.Property<string>("RecipientName");
254
+
255
+                    b.Property<string>("RecipientUsage");
256
+
257
+                    b.HasKey("Id");
258
+
259
+                    b.ToTable("MailRecipients");
260
+                });
261
+
237
             modelBuilder.Entity("UnivateProperties_API.Model.Communication.PlaceHolder", b =>
262
             modelBuilder.Entity("UnivateProperties_API.Model.Communication.PlaceHolder", b =>
238
                 {
263
                 {
239
                     b.Property<int>("Id")
264
                     b.Property<int>("Id")

+ 9
- 0
UnivateProperties_API/Model/Communication/MailRecipient.cs 查看文件

1
+namespace UnivateProperties_API.Model.Communication
2
+{
3
+    public class MailRecipient : BaseEntity
4
+    {
5
+        public string RecipientName { get; set; }
6
+        public string RecipientMail { get; set; }
7
+        public string RecipientUsage { get; set; }
8
+    }
9
+}

+ 85
- 6
UnivateProperties_API/Repository/Communication/MailRepository.cs 查看文件

1
 using MailKit.Net.Smtp;
1
 using MailKit.Net.Smtp;
2
 using MimeKit;
2
 using MimeKit;
3
 using System;
3
 using System;
4
+using System.Collections.Generic;
4
 using System.Linq;
5
 using System.Linq;
5
 using System.Linq.Dynamic.Core;
6
 using System.Linq.Dynamic.Core;
6
 using UnivateProperties_API.Context;
7
 using UnivateProperties_API.Context;
8
+using UnivateProperties_API.Helpers;
7
 using UnivateProperties_API.Model.Communication;
9
 using UnivateProperties_API.Model.Communication;
8
 
10
 
9
 namespace UnivateProperties_API.Repository.Communication
11
 namespace UnivateProperties_API.Repository.Communication
12
     {
14
     {
13
         void ContactUs(MailModel mm);
15
         void ContactUs(MailModel mm);
14
         void EnquireNow(MailModel mm);
16
         void EnquireNow(MailModel mm);
17
+        void AddRecipient(MailRecipient rec);
18
+        List<MailRecipient> GetMailRecipients();
19
+        MailRecipient GetMailRecipientById(int id);
20
+        void UpdateMailRecipient(MailRecipient rec);
21
+        void DeleteMailRecipient(int id);
15
     }
22
     }
16
 
23
 
17
     public class MailRepository : IMailRepository
24
     public class MailRepository : IMailRepository
40
             string name = mm.Name;
47
             string name = mm.Name;
41
             string email = mm.Email;
48
             string email = mm.Email;
42
             string message = mm.Message;
49
             string message = mm.Message;
50
+            var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "ContactUs").ToList();
43
 
51
 
44
             from = new MailboxAddress("Admin", mm.FromAddress);
52
             from = new MailboxAddress("Admin", mm.FromAddress);
45
 
53
 
46
-            to = new MailboxAddress("User", mm.ToAddress);
54
+            InternetAddressList list = new InternetAddressList();
55
+            foreach (var recipient in recipients)
56
+            {
57
+                list.Add(new MailboxAddress(recipient.RecipientName, recipient.RecipientMail));
58
+            }
59
+            //to = new MailboxAddress("User", mm.ToAddress);
47
 
60
 
48
             messageObj.From.Add(from);
61
             messageObj.From.Add(from);
49
-            messageObj.To.Add(to);
62
+            messageObj.To.AddRange(list);
50
 
63
 
51
             messageObj.Subject = "Uni-Vate - New Contact Request";
64
             messageObj.Subject = "Uni-Vate - New Contact Request";
52
 
65
 
80
             string message = mm.Message;
93
             string message = mm.Message;
81
             var props = _dbContext.Properties.ToList();
94
             var props = _dbContext.Properties.ToList();
82
             var prop = props.Where(x => x.Id == Convert.ToInt32(mm.Property)).FirstOrDefault();
95
             var prop = props.Where(x => x.Id == Convert.ToInt32(mm.Property)).FirstOrDefault();
96
+            var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "EnquireNow").ToList();
97
+
83
             
98
             
84
             from = new MailboxAddress("Admin", mm.FromAddress);
99
             from = new MailboxAddress("Admin", mm.FromAddress);
85
 
100
 
86
-            to = new MailboxAddress("User", mm.ToAddress);
101
+            InternetAddressList list = new InternetAddressList();
102
+            foreach (var recipient in recipients)
103
+            {
104
+                list.Add(new MailboxAddress(recipient.RecipientName, recipient.RecipientMail));
105
+            }
106
+            //to = new MailboxAddress("User", mm.ToAddress);
87
 
107
 
88
             messageObj.From.Add(from);
108
             messageObj.From.Add(from);
89
-            messageObj.To.Add(to);
109
+            messageObj.To.AddRange(list);
90
 
110
 
91
             messageObj.Subject = "Uni-Vate - Enquiry to view property";
111
             messageObj.Subject = "Uni-Vate - Enquiry to view property";
92
 
112
 
130
 
150
 
131
             bodyBuilder.HtmlBody = "<div style=\"margin: 5px\">" +
151
             bodyBuilder.HtmlBody = "<div style=\"margin: 5px\">" +
132
                 "<h4>Request to reset password</h4>" +
152
                 "<h4>Request to reset password</h4>" +
133
-                "<h4>Dear " + name + " there has been a request  to reset your password. If this is incorrect please send an email to info@univateproperties.co.za</h4>" +
153
+                "<h4>Dear " + name + ", </h4>" +
154
+                "<h4>There has been a request to reset your password. If this is incorrect please send an email to info@univateproperties.co.za</h4>" +
134
                 "<div>" +
155
                 "<div>" +
156
+                "<h5>Please follow the link below to reset your password:</h5>" +
135
                 "<h3>"+ link + "</h3>" +
157
                 "<h3>"+ link + "</h3>" +
136
-
158
+                "<br />"+
159
+                "<h4>Thank You</h4>" +
160
+                "<h4>Team Uni-Vate</h4>" +
137
                 "</div>" +
161
                 "</div>" +
138
                 "</div>" +
162
                 "</div>" +
139
                 "</div>";
163
                 "</div>";
147
             client.Disconnect(true);
171
             client.Disconnect(true);
148
             client.Dispose();
172
             client.Dispose();
149
         }
173
         }
174
+
175
+        public void AddRecipient(MailRecipient rec)
176
+        {
177
+            if (MyCommon.IsValidEmail(rec.RecipientMail))
178
+            {
179
+                _dbContext.MailRecipients.Add(rec);
180
+                _dbContext.SaveChanges();
181
+            }
182
+            else
183
+            {
184
+                throw new Exception();
185
+            }
186
+            
187
+        }
188
+
189
+        public List<MailRecipient> GetMailRecipients()
190
+        {
191
+            return _dbContext.MailRecipients.Where(x => x.IsDeleted == false).ToList();
192
+        }
193
+
194
+        public MailRecipient GetMailRecipientById(int id)
195
+        {
196
+            return _dbContext.MailRecipients.Where(x => x.Id == id).FirstOrDefault(); 
197
+        }
198
+
199
+        public void UpdateMailRecipient(MailRecipient rec)
200
+        {
201
+            var recipient = _dbContext.MailRecipients.Where(x => x.Id == rec.Id).FirstOrDefault();
202
+
203
+            if (recipient.RecipientMail != rec.RecipientMail)
204
+            {
205
+                recipient.RecipientMail = rec.RecipientMail;
206
+            }
207
+
208
+            if (recipient.RecipientName != rec.RecipientName)
209
+            {
210
+                recipient.RecipientName = rec.RecipientName;
211
+            }
212
+
213
+            if (recipient.RecipientUsage != rec.RecipientUsage)
214
+            {
215
+                recipient.RecipientUsage = rec.RecipientUsage;
216
+            }
217
+
218
+
219
+            _dbContext.MailRecipients.Update(recipient);
220
+            _dbContext.SaveChanges();
221
+        }
222
+
223
+        public void DeleteMailRecipient(int id)
224
+        {
225
+            var rec = _dbContext.MailRecipients.Where(x => x.Id == id).FirstOrDefault();        
226
+            _dbContext.MailRecipients.Remove(rec);
227
+            _dbContext.SaveChanges();
228
+        }
150
     }
229
     }
151
 }
230
 }

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

156
             services.AddTransient<IRepository<SMTPAccount>, SMTPAccountRepository>();
156
             services.AddTransient<IRepository<SMTPAccount>, SMTPAccountRepository>();
157
             services.AddTransient<IRepository<SMTPHost>, SMTPHostRepository>();
157
             services.AddTransient<IRepository<SMTPHost>, SMTPHostRepository>();
158
             services.AddTransient<IMailRepository, MailRepository>();
158
             services.AddTransient<IMailRepository, MailRepository>();
159
+
159
             #endregion Communication
160
             #endregion Communication
160
             #region Logs 
161
             #region Logs 
161
             services.AddTransient<ISearchLogRepository, SearchLogRepository>();
162
             services.AddTransient<ISearchLogRepository, SearchLogRepository>();

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

11
   "ConnectionStrings": {
11
   "ConnectionStrings": {
12
     "DefaultConnection": "Data Source=localhost;Initial Catalog=UniVateDemo;Persist Security Info=True;User Id=Provision;Password=What123!;Pooling=false;",
12
     "DefaultConnection": "Data Source=localhost;Initial Catalog=UniVateDemo;Persist Security Info=True;User Id=Provision;Password=What123!;Pooling=false;",
13
     "TenderConnection": "http://www.unipoint-consoft.co.za/nph-srep.exe?cluvavail.sch&CLUB=LPA&RESORT=ALL&SUMMARY=N&HEAD=N",
13
     "TenderConnection": "http://www.unipoint-consoft.co.za/nph-srep.exe?cluvavail.sch&CLUB=LPA&RESORT=ALL&SUMMARY=N&HEAD=N",
14
-    "ReservationsURL": "http://training.provision-sa.com:84/ReservationsWebService.asmx", //Please note that ReservationsWebService must be in this case. 
14
+    "ReservationsURL": "https://www.pvsl.co.za:85/ReservationsWebService.asmx", //Please note that ReservationsWebService must be in this case. 
15
     "ReservationsUserCode": "UniInt",
15
     "ReservationsUserCode": "UniInt",
16
     "ReservationsPassword": "Un11nt"
16
     "ReservationsPassword": "Un11nt"
17
   }
17
   }

Loading…
取消
儲存