Selaa lähdekoodia

Updated Communication and added logs for enquire

master
30117125 3 vuotta sitten
vanhempi
commit
98f3256de6

+ 1
- 0
UnivateProperties_API/Context/DataContext.cs Näytä tiedosto

@@ -51,6 +51,7 @@ namespace UnivateProperties_API.Context
51 51
         public virtual DbSet<Template> Templates { get; set; }
52 52
         public virtual DbSet<PlaceHolder> PlaceHolders { get; set; }
53 53
         public virtual DbSet<MailRecipient> MailRecipients { get; set; }
54
+        public virtual DbSet<MailModel> CommunicationLog { get; set; }
54 55
         #endregion Communication
55 56
 
56 57
         #region Property

+ 0
- 3
UnivateProperties_API/Controllers/Campaigns/CampaignController.cs Näytä tiedosto

@@ -1,15 +1,12 @@
1 1
 using Microsoft.AspNetCore.Http;
2 2
 using Microsoft.AspNetCore.Mvc;
3 3
 using System;
4
-using System.Collections.Generic;
5 4
 using System.IO;
6 5
 using System.Linq;
7 6
 using System.Net;
8 7
 using System.Threading.Tasks;
9 8
 using System.Transactions;
10
-using UnivateProperties_API.Containers.Campaigns;
11 9
 using UnivateProperties_API.Model.Campaigns;
12
-using UnivateProperties_API.Repository;
13 10
 using UnivateProperties_API.Repository.Campaigns;
14 11
 
15 12
 namespace UnivateProperties_API.Controllers.Campaigns

+ 14
- 0
UnivateProperties_API/Controllers/Communication/MailController.cs Näytä tiedosto

@@ -59,6 +59,20 @@ namespace UnivateProperties_API.Controllers.Communication
59 59
             return new OkObjectResult(recipients);
60 60
         }
61 61
 
62
+        [HttpGet("getContactLog")]
63
+        public IActionResult GetContactUsLog()
64
+        {
65
+            var recipients = _repo.GetContactUsLog();
66
+            return new OkObjectResult(recipients);
67
+        }
68
+
69
+        [HttpGet("getEnquireLog")]
70
+        public IActionResult GetEnquireNowLog()
71
+        {
72
+            var recipients = _repo.GetEnquireNowLog();
73
+            return new OkObjectResult(recipients);
74
+        }
75
+
62 76
         [HttpGet("mailrecipient/{id}")]
63 77
         public IActionResult GetRecipientById(int id)
64 78
         {

+ 1864
- 0
UnivateProperties_API/Migrations/20210420082156_CommunicationSystem.Designer.cs
File diff suppressed because it is too large
Näytä tiedosto


+ 43
- 0
UnivateProperties_API/Migrations/20210420082156_CommunicationSystem.cs Näytä tiedosto

@@ -0,0 +1,43 @@
1
+using System;
2
+using Microsoft.EntityFrameworkCore.Metadata;
3
+using Microsoft.EntityFrameworkCore.Migrations;
4
+
5
+namespace UnivateProperties_API.Migrations
6
+{
7
+    public partial class CommunicationSystem : Migration
8
+    {
9
+        protected override void Up(MigrationBuilder migrationBuilder)
10
+        {
11
+            migrationBuilder.CreateTable(
12
+                name: "MailModel",
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
+                    ToAddress = table.Column<string>(nullable: true),
22
+                    FromAddress = table.Column<string>(nullable: true),
23
+                    Name = table.Column<string>(nullable: true),
24
+                    Email = table.Column<string>(nullable: true),
25
+                    Phone = table.Column<string>(nullable: true),
26
+                    Property = table.Column<string>(nullable: true),
27
+                    Message = table.Column<string>(nullable: true),
28
+                    HeardFrom = table.Column<string>(nullable: true),
29
+                    Error = table.Column<string>(nullable: true)
30
+                },
31
+                constraints: table =>
32
+                {
33
+                    table.PrimaryKey("PK_MailModel", x => x.Id);
34
+                });
35
+        }
36
+
37
+        protected override void Down(MigrationBuilder migrationBuilder)
38
+        {
39
+            migrationBuilder.DropTable(
40
+                name: "MailModel");
41
+        }
42
+    }
43
+}

+ 1866
- 0
UnivateProperties_API/Migrations/20210420082718_CommunicationSystem1.Designer.cs
File diff suppressed because it is too large
Näytä tiedosto


+ 48
- 0
UnivateProperties_API/Migrations/20210420082718_CommunicationSystem1.cs Näytä tiedosto

@@ -0,0 +1,48 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class CommunicationSystem1 : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+            migrationBuilder.DropPrimaryKey(
10
+                name: "PK_MailModel",
11
+                table: "MailModel");
12
+
13
+            migrationBuilder.RenameTable(
14
+                name: "MailModel",
15
+                newName: "CommunicationLog");
16
+
17
+            migrationBuilder.AddColumn<string>(
18
+                name: "ComType",
19
+                table: "CommunicationLog",
20
+                nullable: true);
21
+
22
+            migrationBuilder.AddPrimaryKey(
23
+                name: "PK_CommunicationLog",
24
+                table: "CommunicationLog",
25
+                column: "Id");
26
+        }
27
+
28
+        protected override void Down(MigrationBuilder migrationBuilder)
29
+        {
30
+            migrationBuilder.DropPrimaryKey(
31
+                name: "PK_CommunicationLog",
32
+                table: "CommunicationLog");
33
+
34
+            migrationBuilder.DropColumn(
35
+                name: "ComType",
36
+                table: "CommunicationLog");
37
+
38
+            migrationBuilder.RenameTable(
39
+                name: "CommunicationLog",
40
+                newName: "MailModel");
41
+
42
+            migrationBuilder.AddPrimaryKey(
43
+                name: "PK_MailModel",
44
+                table: "MailModel",
45
+                column: "Id");
46
+        }
47
+    }
48
+}

+ 39
- 0
UnivateProperties_API/Migrations/DataContextModelSnapshot.cs Näytä tiedosto

@@ -296,6 +296,45 @@ namespace UnivateProperties_API.Migrations
296 296
                     b.ToTable("Emails");
297 297
                 });
298 298
 
299
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.MailModel", b =>
300
+                {
301
+                    b.Property<int>("Id")
302
+                        .ValueGeneratedOnAdd()
303
+                        .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
304
+
305
+                    b.Property<string>("ComType");
306
+
307
+                    b.Property<DateTime>("Created");
308
+
309
+                    b.Property<string>("Email");
310
+
311
+                    b.Property<string>("Error");
312
+
313
+                    b.Property<string>("FromAddress");
314
+
315
+                    b.Property<string>("HeardFrom");
316
+
317
+                    b.Property<bool>("IsDeleted");
318
+
319
+                    b.Property<string>("Message");
320
+
321
+                    b.Property<DateTime>("Modified");
322
+
323
+                    b.Property<string>("ModifiedBy");
324
+
325
+                    b.Property<string>("Name");
326
+
327
+                    b.Property<string>("Phone");
328
+
329
+                    b.Property<string>("Property");
330
+
331
+                    b.Property<string>("ToAddress");
332
+
333
+                    b.HasKey("Id");
334
+
335
+                    b.ToTable("CommunicationLog");
336
+                });
337
+
299 338
             modelBuilder.Entity("UnivateProperties_API.Model.Communication.MailRecipient", b =>
300 339
                 {
301 340
                     b.Property<int>("Id")

+ 7
- 8
UnivateProperties_API/Model/Communication/MailModel.cs Näytä tiedosto

@@ -1,13 +1,8 @@
1
-using System;
2
-using System.Collections.Generic;
3
-using System.ComponentModel.DataAnnotations;
4
-using System.Linq;
5
-using System.Threading.Tasks;
6
-
7
-namespace UnivateProperties_API.Model.Communication
1
+namespace UnivateProperties_API.Model.Communication
8 2
 {
9
-    public class MailModel
3
+    public class MailModel : BaseEntity
10 4
     {
5
+        public string ComType { get; set; }
11 6
         public string ToAddress { get; set; }
12 7
 
13 8
         public string FromAddress { get; set; }
@@ -21,5 +16,9 @@ namespace UnivateProperties_API.Model.Communication
21 16
         public string Property { get; set; }
22 17
 
23 18
         public string Message { get; set; }
19
+
20
+        public string HeardFrom { get; set; }
21
+
22
+        public string Error { get; set; }
24 23
     }
25 24
 }

+ 83
- 42
UnivateProperties_API/Repository/Communication/MailRepository.cs Näytä tiedosto

@@ -25,6 +25,9 @@ namespace UnivateProperties_API.Repository.Communication
25 25
         MailRecipient GetMailRecipientById(int id);
26 26
         void UpdateMailRecipient(MailRecipient rec);
27 27
         void DeleteMailRecipient(int id);
28
+
29
+        List<MailModel> GetEnquireNowLog();
30
+        List<MailModel> GetContactUsLog();
28 31
     }
29 32
 
30 33
     public class MailRepository : IMailRepository
@@ -41,9 +44,10 @@ namespace UnivateProperties_API.Repository.Communication
41 44
         }        
42 45
 
43 46
         public void ContactUs(MailModel mm)
44
-        {
47
+        {            
45 48
             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; 
49
+            string body = _dbContext.Templates.Where(x => x.Name == "ContactUs").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
50
+            string error = "";
47 51
 
48 52
             body = body.Replace("[FULLNAME]", mm.Name);
49 53
             body = body.Replace("[USEREMAIL]", mm.Email);
@@ -67,40 +71,54 @@ namespace UnivateProperties_API.Repository.Communication
67 71
                     toList = toList.Substring(0, toList.Length - 2);
68 72
             }
69 73
 
70
-            var host = _dbContext.Hosts.FirstOrDefault();
71
-            using (SmtpClient smtp = new SmtpClient(host.Host))
74
+            try
72 75
             {
73
-                MailMessage mail = new MailMessage();
74
-                mail.To.Add(toList);
75
-                mail.Subject = "Uni-Vate - New Contact Request";
76
-                mail.Body = body;
77
-                mail.IsBodyHtml = true;
78
-                mail.BodyEncoding = Encoding.ASCII;
79
-                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
80
-                mail.Sender = new MailAddress(host.User, "UniVate Properties");
81
-                mail.From = new MailAddress(mm.Email, mm.Name);
82
-
83
-                smtp.UseDefaultCredentials = host.NeedsAuthorize;
84
-                smtp.Credentials = host.GetNetworkCredential();
85
-                smtp.EnableSsl = host.UseSSL;
86
-                smtp.Send(mail);
87
-            }            
76
+                var host = _dbContext.Hosts.FirstOrDefault();
77
+                using (SmtpClient smtp = new SmtpClient(host.Host))
78
+                {
79
+                    MailMessage mail = new MailMessage();
80
+                    mail.To.Add(toList);
81
+                    mail.Subject = "Uni-Vate - New Contact Request";
82
+                    mail.Body = body;
83
+                    mail.IsBodyHtml = true;
84
+                    mail.BodyEncoding = Encoding.ASCII;
85
+                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
86
+                    mail.Sender = new MailAddress(host.User, "UniVate Properties");
87
+                    mail.From = new MailAddress(mm.Email, mm.Name);
88
+
89
+                    smtp.UseDefaultCredentials = host.NeedsAuthorize;
90
+                    smtp.Credentials = host.GetNetworkCredential();
91
+                    smtp.EnableSsl = host.UseSSL;
92
+                    smtp.Send(mail);
93
+                }
94
+                error = "None";
95
+            }
96
+            catch (Exception ex)
97
+            {
98
+                error = ex.ToString();
99
+            }
100
+            mm.ComType = "Contact Us";
101
+            mm.Error = error;
102
+            _dbContext.CommunicationLog.Add(mm);
103
+            _dbContext.SaveChanges();
88 104
         }
89 105
 
90 106
         public void EnquireNow(MailModel mm)
91
-        {
107
+        {            
92 108
             var recipients = _dbContext.MailRecipients.Where(x => x.RecipientUsage == "EnquireNow").Where(y => y.IsDeleted == false).ToList();
93 109
             string body = _dbContext.Templates.Where(x => x.Name == "EnquireNow").Where(y => y.IsDeleted == false).FirstOrDefault().Body;
94 110
             var property = _dbContext.Properties.Where(x => x.Id == Convert.ToInt32(mm.Property)).FirstOrDefault();
111
+            string error = "";
95 112
 
96
-            body = body.Replace("[FULLNAME]", mm.Name);
97
-            body = body.Replace("[USEREMAIL]", mm.Email);
98
-            body = body.Replace("[USERCELLPHONE]", mm.Phone);
99
-            body = body.Replace("[PROPERTYID]", mm.Property);
113
+            body = body.Replace("[FULLNAME]", " " + mm.Name);
114
+            body = body.Replace("[USEREMAIL]", " " + mm.Email);
115
+            body = body.Replace("[USERCELLPHONE]", " " + mm.Phone);
116
+            body = body.Replace("[PROPERTYID]", " " + mm.Property);
100 117
             body = body.Replace("[PROPERTYNAME]", property.PropertyName);
101 118
             body = body.Replace("[PROPERTYREF]", property.PropertyRef);
102 119
             body = body.Replace("[PROPERTYPRICE]", property.Price.ToString());
103
-            body = body.Replace("[USERMESSAGE]", mm.Message);
120
+            body = body.Replace("[USERMESSAGE]", " " + mm.Message);
121
+            body = body.Replace("[USERHEARDFROM]", " " + mm.HeardFrom);
104 122
 
105 123
             string toList = "";
106 124
             int emailCount = 0;
@@ -118,24 +136,36 @@ namespace UnivateProperties_API.Repository.Communication
118 136
                     toList = toList.Substring(0, toList.Length - 2);
119 137
             }
120 138
 
121
-            var host = _dbContext.Hosts.FirstOrDefault();
122
-            using (SmtpClient smtp = new SmtpClient(host.Host))
139
+            try
123 140
             {
124
-                MailMessage mail = new MailMessage();
125
-                mail.To.Add(toList);
126
-                mail.Subject = "Uni-Vate - Enquiry to view property";
127
-                mail.Body = body;
128
-                mail.IsBodyHtml = true;
129
-                mail.BodyEncoding = Encoding.ASCII;
130
-                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
131
-                mail.Sender = new MailAddress(host.User, "UniVate Properties");
132
-                mail.From = new MailAddress(mm.Email, mm.Name);
133
-
134
-                smtp.UseDefaultCredentials = host.NeedsAuthorize;
135
-                smtp.Credentials = host.GetNetworkCredential();
136
-                smtp.EnableSsl = host.UseSSL;
137
-                smtp.Send(mail);
138
-            }            
141
+                var host = _dbContext.Hosts.FirstOrDefault();
142
+                using (SmtpClient smtp = new SmtpClient(host.Host))
143
+                {
144
+                    MailMessage mail = new MailMessage();
145
+                    mail.To.Add(toList);
146
+                    mail.Subject = "Uni-Vate - Enquiry to view property";
147
+                    mail.Body = body;
148
+                    mail.IsBodyHtml = true;
149
+                    mail.BodyEncoding = Encoding.ASCII;
150
+                    mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
151
+                    mail.Sender = new MailAddress(host.User, "UniVate Properties");
152
+                    mail.From = new MailAddress(mm.Email, mm.Name);
153
+
154
+                    smtp.UseDefaultCredentials = host.NeedsAuthorize;
155
+                    smtp.Credentials = host.GetNetworkCredential();
156
+                    smtp.EnableSsl = host.UseSSL;
157
+                    smtp.Send(mail);
158
+                }
159
+                error = "None";
160
+            }
161
+            catch (Exception ex)
162
+            {
163
+                error = ex.ToString();
164
+            }
165
+            mm.ComType = "Enquire Now";
166
+            mm.Error = error;
167
+            _dbContext.CommunicationLog.Add(mm);
168
+            _dbContext.SaveChanges();
139 169
         }
140 170
 
141 171
         public void ForgotPassword(Individual toPerson, string link)
@@ -467,5 +497,16 @@ namespace UnivateProperties_API.Repository.Communication
467 497
             _dbContext.MailRecipients.Remove(rec);
468 498
             _dbContext.SaveChanges();
469 499
         }
500
+
501
+        public List<MailModel> GetContactUsLog()
502
+        {
503
+            return _dbContext.CommunicationLog.Where(x => x.ComType == "Contact Us").ToList();            
504
+        }
505
+
506
+        public List<MailModel> GetEnquireNowLog()
507
+        {
508
+            return _dbContext.CommunicationLog.Where(x => x.ComType == "Enquire Now").ToList();
509
+            
510
+        }
470 511
     }
471 512
 }

+ 1
- 1
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Näytä tiedosto

@@ -640,7 +640,7 @@ namespace UnivateProperties_API.Repository.Properties
640 640
                     case "FOR SALE":
641 641
                         if (item.PriceRedused)
642 642
                         {
643
-                            display.DisplayText = "Price Redused";
643
+                            display.DisplayText = "Price Reduced";
644 644
                             display.DisplayColor = "green";
645 645
                         }
646 646
                         else

Loading…
Peruuta
Tallenna