George Williams 4 lat temu
rodzic
commit
6a01d7bf8f

+ 42
- 0
UnivateProperties_API/Controllers/Communication/MailController.cs Wyświetl plik

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;
7
+using UnivateProperties_API.Model.Communication;
8
+using UnivateProperties_API.Repository.Communication;
9
+
10
+namespace UnivateProperties_API.Controllers.Communication
11
+{
12
+    [Route("api/[controller]")]
13
+    [ApiController]
14
+    public class MailController : ControllerBase
15
+    {
16
+        private readonly IMailRepository _repo;
17
+        public MailController(IMailRepository repo)
18
+        {
19
+            _repo = repo;
20
+        }
21
+
22
+        [HttpPost("{id}")]
23
+        public IActionResult Post(int id, [FromBody] MailModel mm)
24
+        {
25
+            try
26
+            {
27
+                switch (id)
28
+                {
29
+                    case 0:
30
+                        _repo.ContactUs(mm);
31
+                        break;
32
+                }
33
+                return new OkResult();
34
+            }
35
+            catch
36
+            {
37
+                return new BadRequestResult();
38
+            }
39
+
40
+        }
41
+    }
42
+}

+ 7
- 3
UnivateProperties_API/Controllers/Financial/PaymentController.cs Wyświetl plik

2
 using System.Transactions;
2
 using System.Transactions;
3
 using UnivateProperties_API.Model.Financial;
3
 using UnivateProperties_API.Model.Financial;
4
 using UnivateProperties_API.Repository;
4
 using UnivateProperties_API.Repository;
5
+using UnivateProperties_API.Repository.Financial;
5
 
6
 
6
 namespace UnivateProperties_API.Controllers.Financial
7
 namespace UnivateProperties_API.Controllers.Financial
7
 {
8
 {
10
     public class PaymentController : ControllerBase
11
     public class PaymentController : ControllerBase
11
     {
12
     {
12
         private readonly IRepository<Payment> _Repo;
13
         private readonly IRepository<Payment> _Repo;
14
+        private readonly IPaygateRepository _paygateRepo;
13
 
15
 
14
-        public PaymentController(IRepository<Payment> _repo)
16
+        public PaymentController(IRepository<Payment> _repo, IPaygateRepository paygateRepo)
15
         {
17
         {
16
             _Repo = _repo;
18
             _Repo = _repo;
19
+            _paygateRepo = paygateRepo;
17
         }
20
         }
18
         
21
         
19
         [HttpGet]
22
         [HttpGet]
33
         {
36
         {
34
             using (var scope = new TransactionScope())
37
             using (var scope = new TransactionScope())
35
             {
38
             {
36
-                _Repo.Insert(payment);
39
+                var paymentResult = _paygateRepo.GoToPaymentGateway(payment);
40
+                //_Repo.Insert(payment);
37
                 scope.Complete();
41
                 scope.Complete();
38
-                return CreatedAtAction(nameof(Get), new { id = payment.Id }, payment);
42
+                return new OkObjectResult(paymentResult);
39
             }
43
             }
40
         }
44
         }
41
         
45
         

+ 25
- 0
UnivateProperties_API/Model/Communication/MailModel.cs Wyświetl plik

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
8
+{
9
+    public class MailModel
10
+    {
11
+        public string ToAddress { get; set; }
12
+
13
+        public string FromAddress { get; set; }
14
+
15
+        public string Name { get; set; }
16
+
17
+        public string Email { get; set; }
18
+
19
+        public string Phone { get; set; }
20
+
21
+        public string Property { get; set; }
22
+
23
+        public string Message { get; set; }
24
+    }
25
+}

+ 59
- 0
UnivateProperties_API/Repository/Communication/MailRepository.cs Wyświetl plik

1
+using MailKit.Net.Smtp;
2
+using MimeKit;
3
+using UnivateProperties_API.Model.Communication;
4
+
5
+namespace UnivateProperties_API.Repository.Communication
6
+{
7
+    public interface IMailRepository
8
+    {
9
+        void ContactUs(MailModel mm);
10
+    }
11
+
12
+    public class MailRepository : IMailRepository
13
+    {
14
+        MimeMessage messageObj = new MimeMessage();
15
+        MailboxAddress from;
16
+        MailboxAddress to;
17
+        BodyBuilder bodyBuilder = new BodyBuilder();
18
+        SmtpClient client = new SmtpClient();
19
+
20
+        public void ContactUs(MailModel mm)
21
+        {
22
+            string property = mm.Property;
23
+            string phone = mm.Phone;
24
+            string name = mm.Name;
25
+            string email = mm.Email;
26
+            string message = mm.Message;
27
+
28
+            from = new MailboxAddress("Admin", mm.FromAddress);
29
+
30
+            to = new MailboxAddress("User", mm.ToAddress);
31
+
32
+            messageObj.From.Add(from);
33
+            messageObj.To.Add(to);
34
+
35
+            messageObj.Subject = "Uni-Vate - New Contact Request";
36
+
37
+            bodyBuilder.HtmlBody = "<div style=\"margin: 5px\">" +
38
+                "<h4>Contact from: "+  name +"!</h4>" +
39
+                "<h4>Email: "+ email +"</h4>" +
40
+                "<h4>Phone: " + phone + "</h4>" +
41
+                "<h4>Property: " + property + "</h4>" +
42
+                "<div>" +
43
+                "<h4>Message: </h4>" +
44
+                "<p>" + message + "</p>" +
45
+                "</div>" +
46
+                "</div>" +
47
+                "</div>";
48
+
49
+            messageObj.Body = bodyBuilder.ToMessageBody();
50
+
51
+            client.Connect("smtp.gmail.com", 465, true);
52
+            client.Authenticate("jlouw365@gmail.com", "setskohatxpsceqo");
53
+
54
+            client.Send(messageObj);
55
+            client.Disconnect(true);
56
+            client.Dispose();
57
+        }
58
+    }
59
+}

+ 85
- 0
UnivateProperties_API/Repository/Financial/PaygateRepository.cs Wyświetl plik

1
+using RestSharp;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using System.Security.Cryptography;
6
+using System.Text;
7
+using System.Threading.Tasks;
8
+using UnivateProperties_API.Model.Financial;
9
+
10
+namespace UnivateProperties_API.Repository.Financial
11
+{
12
+    public interface IPaygateRepository
13
+    {
14
+        string GoToPaymentGateway(Payment payment);
15
+    }
16
+
17
+    public class PaygateRepository: IPaygateRepository
18
+    {
19
+        public string GoToPaymentGateway(Payment payment)
20
+        {
21
+            string utcDate = DateTime.UtcNow.ToString("yyyy-MM-dd H:mm:ss");
22
+            var client = new RestClient("https://secure.paygate.co.za/payweb3/initiate.trans");
23
+            client.Timeout = -1;
24
+            var request = new RestRequest(Method.POST);
25
+            var total = payment.Amount;
26
+            string paygateId = "10011072130";
27
+            string reff = "";
28
+            if (payment.TimeshareWeekId != 0)
29
+            {
30
+                reff = payment.TimeshareWeekId.ToString();
31
+            }
32
+            else
33
+            {
34
+                reff = payment.PropertyId.ToString();
35
+            }
36
+
37
+            string amm = Math.Round((total * 100)).ToString();
38
+            string currenc = "ZAR";
39
+            string retUrl = "http://localhost:57260/api/values";
40
+            string transDate = utcDate;
41
+            string loc = "en-za";
42
+            string count = "ZAF";
43
+            string mail = "jlouw365@gmail.com";
44
+            request.AlwaysMultipartFormData = true;
45
+            request.AddParameter("PAYGATE_ID", paygateId);
46
+            request.AddParameter("REFERENCE", reff);
47
+            request.AddParameter("AMOUNT", amm);
48
+            request.AddParameter("CURRENCY", currenc);
49
+            request.AddParameter("RETURN_URL", retUrl);
50
+            request.AddParameter("TRANSACTION_DATE", transDate);
51
+            request.AddParameter("LOCALE", loc);
52
+            request.AddParameter("COUNTRY", count);
53
+            request.AddParameter("EMAIL", mail);
54
+            string checksum = Checksum(
55
+                paygateId +
56
+                reff +
57
+                amm +
58
+                currenc +
59
+                retUrl +
60
+                transDate +
61
+                loc +
62
+                count +
63
+                mail +
64
+                "secret");
65
+            request.AddParameter("CHECKSUM", checksum);
66
+            string gatewayReturn = client.Execute(request).Content.ToString();
67
+            List<string> vs = gatewayReturn.Split('&').ToList();
68
+            string payReqId = vs[1].Split('=')[1].ToString();
69
+            //var updatedOrder = _dbContext.Payments.OrderByDescending(x => x.Id).FirstOrDefault();
70
+            //updatedOrder.PaymentToken = payReqId;
71
+            //_dbContext.Payments.Update(updatedOrder);
72
+            //_dbContext.SaveChanges();
73
+            return client.Execute(request).Content.ToString();
74
+        }
75
+
76
+        private string Checksum(string data)
77
+        {
78
+            using (var md5 = MD5.Create())
79
+            {
80
+                return BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(data)))
81
+                    .Replace("-", string.Empty).ToLower();
82
+            }
83
+        }
84
+    }
85
+}

+ 3
- 0
UnivateProperties_API/Repository/Financial/PaymentRepository.cs Wyświetl plik

1
 using Microsoft.EntityFrameworkCore;
1
 using Microsoft.EntityFrameworkCore;
2
+using RestSharp;
2
 using System;
3
 using System;
3
 using System.Collections.Generic;
4
 using System.Collections.Generic;
4
 using System.Linq;
5
 using System.Linq;
6
+using System.Security.Cryptography;
7
+using System.Text;
5
 using UnivateProperties_API.Context;
8
 using UnivateProperties_API.Context;
6
 using UnivateProperties_API.Model.Financial;
9
 using UnivateProperties_API.Model.Financial;
7
 
10
 

+ 1
- 1
UnivateProperties_API/Repository/IRepository.cs Wyświetl plik

16
         void Remove(IEnumerable<TEntity> items);
16
         void Remove(IEnumerable<TEntity> items);
17
         void RemoveAtId(int item);
17
         void RemoveAtId(int item);
18
         void Update(TEntity item);
18
         void Update(TEntity item);
19
-        int NewId();
19
+        //int NewId();
20
         void Save();
20
         void Save();
21
     }
21
     }
22
 }
22
 }

+ 47
- 47
UnivateProperties_API/Repository/Users/RegisterRepository.cs Wyświetl plik

52
 
52
 
53
             user.PasswordHash = passwordHash;
53
             user.PasswordHash = passwordHash;
54
             user.PasswordSalt = passwordSalt;
54
             user.PasswordSalt = passwordSalt;
55
-            user.Id = NewUserId();
55
+            //user.Id = NewUserId();
56
             _dbContext.Users.Add(user);
56
             _dbContext.Users.Add(user);
57
             if (save)
57
             if (save)
58
             {
58
             {
77
                 EAABEFFCNumber = agency.EaabeffcNumber,
77
                 EAABEFFCNumber = agency.EaabeffcNumber,
78
                 CompanyRegNumber = agency.RegNo
78
                 CompanyRegNumber = agency.RegNo
79
             };
79
             };
80
-            a.Id = NewAgencyId();
80
+            //a.Id = NewAgencyId();
81
             _dbContext.Agencies.Add(a);
81
             _dbContext.Agencies.Add(a);
82
             CreatePerson(agency.User, PersonType.Agent, false, a);
82
             CreatePerson(agency.User, PersonType.Agent, false, a);
83
 
83
 
115
                     Telephone = individual.Telephone,
115
                     Telephone = individual.Telephone,
116
                     Agency = agency
116
                     Agency = agency
117
                 };
117
                 };
118
-                agent.Id = NewAgentId();
118
+                //agent.Id = NewAgentId();
119
                 agent.User.Role = Role.Agency;
119
                 agent.User.Role = Role.Agency;
120
                 p = agent;
120
                 p = agent;
121
                 _dbContext.Agents.Add(agent);
121
                 _dbContext.Agents.Add(agent);
131
                     CellNumber = individual.CellNumber,
131
                     CellNumber = individual.CellNumber,
132
                     Telephone = individual.Telephone
132
                     Telephone = individual.Telephone
133
                 };
133
                 };
134
-                i.Id = NewIndividualId();
134
+                //i.Id = NewIndividualId();
135
                 i.User.Role = Role.PrivateUser;
135
                 i.User.Role = Role.PrivateUser;
136
                 p = i;
136
                 p = i;
137
                 _dbContext.Individuals.Add(i);
137
                 _dbContext.Individuals.Add(i);
262
             _dbContext.SaveChanges();
262
             _dbContext.SaveChanges();
263
         }
263
         }
264
 
264
 
265
-        public int NewAgencyId()
266
-        {
267
-            int id = 0;
268
-            if (_dbContext.Agencies.Count() > 0)
269
-            {
270
-                id = _dbContext.Agencies.Max(x => x.Id);
271
-            }
272
-            id += 1;
273
-            return id;
274
-        }
275
-
276
-        public int NewAgentId()
277
-        {
278
-            int id = 0;
279
-            if (_dbContext.Agents.Count() > 0)
280
-            {
281
-                id = _dbContext.Agents.Max(x => x.Id);
282
-            }
283
-            id += 1;
284
-            return id;
285
-        }
286
-
287
-        public int NewIndividualId()
288
-        {
289
-            int id = 0;
290
-            if (_dbContext.Individuals.Count() > 0)
291
-            {
292
-                id = _dbContext.Individuals.Max(x => x.Id);
293
-            }
294
-            id += 1;
295
-            return id;
296
-        }
297
-
298
-        public int NewUserId()
299
-        {
300
-            int id = 0;
301
-            if (_dbContext.Users.Count() > 0)
302
-            {
303
-                id = _dbContext.Users.Max(x => x.Id);
304
-            }
305
-            id += 1;
306
-            return id;
307
-        }
265
+        //public int NewAgencyId()
266
+        //{
267
+        //    int id = 0;
268
+        //    if (_dbContext.Agencies.Count() > 0)
269
+        //    {
270
+        //        id = _dbContext.Agencies.Max(x => x.Id);
271
+        //    }
272
+        //    id += 1;
273
+        //    return id;
274
+        //}
275
+
276
+        //public int NewAgentId()
277
+        //{
278
+        //    int id = 0;
279
+        //    if (_dbContext.Agents.Count() > 0)
280
+        //    {
281
+        //        id = _dbContext.Agents.Max(x => x.Id);
282
+        //    }
283
+        //    id += 1;
284
+        //    return id;
285
+        //}
286
+
287
+        //public int NewIndividualId()
288
+        //{
289
+        //    int id = 0;
290
+        //    if (_dbContext.Individuals.Count() > 0)
291
+        //    {
292
+        //        id = _dbContext.Individuals.Max(x => x.Id);
293
+        //    }
294
+        //    id += 1;
295
+        //    return id;
296
+        //}
297
+
298
+        //public int NewUserId()
299
+        //{
300
+        //    int id = 0;
301
+        //    if (_dbContext.Users.Count() > 0)
302
+        //    {
303
+        //        id = _dbContext.Users.Max(x => x.Id);
304
+        //    }
305
+        //    id += 1;
306
+        //    return id;
307
+        //}
308
 
308
 
309
         public SimplePersonDto UserDetails(int userId)
309
         public SimplePersonDto UserDetails(int userId)
310
         {
310
         {

+ 18
- 18
UnivateProperties_API/Repository/Users/UserRepository.cs Wyświetl plik

42
 
42
 
43
         public void Insert(User item)
43
         public void Insert(User item)
44
         {
44
         {
45
-            item.Id = NewId();
45
+            //item.Id = NewId();
46
             _dbContext.Add(item);
46
             _dbContext.Add(item);
47
             Save();
47
             Save();
48
         }
48
         }
49
 
49
 
50
         public void Insert(IEnumerable<User> item)
50
         public void Insert(IEnumerable<User> item)
51
         {
51
         {
52
-            int id = NewId();
53
-            foreach (var i in item)
54
-            {
55
-                i.Id = id;
56
-                _dbContext.Add(i);
57
-                id += 1;
58
-            }
52
+            //int id = NewId();
53
+            //foreach (var i in item)
54
+            //{
55
+            //    i.Id = id;
56
+                _dbContext.Add(item);
57
+            //    id += 1;
58
+            //}
59
             Save();
59
             Save();
60
         }
60
         }
61
 
61
 
135
             throw new NotImplementedException();
135
             throw new NotImplementedException();
136
         }
136
         }
137
 
137
 
138
-        public int NewId()
139
-        {
140
-            int id = 0;
141
-            if (_dbContext.Users.Count() > 0)
142
-            {
143
-                id = _dbContext.Users.Max(x => x.Id);
144
-            }
145
-            id += 1;
146
-            return id;
147
-        }
138
+        //public int NewId()
139
+        //{
140
+        //    int id = 0;
141
+        //    if (_dbContext.Users.Count() > 0)
142
+        //    {
143
+        //        id = _dbContext.Users.Max(x => x.Id);
144
+        //    }
145
+        //    id += 1;
146
+        //    return id;
147
+        //}
148
     }
148
     }
149
 }
149
 }

+ 4
- 0
UnivateProperties_API/Startup.cs Wyświetl plik

152
             services.AddTransient<IRepository<Email>, EmailRepository>();
152
             services.AddTransient<IRepository<Email>, EmailRepository>();
153
             services.AddTransient<IRepository<SMTPAccount>, SMTPAccountRepository>();
153
             services.AddTransient<IRepository<SMTPAccount>, SMTPAccountRepository>();
154
             services.AddTransient<IRepository<SMTPHost>, SMTPHostRepository>();
154
             services.AddTransient<IRepository<SMTPHost>, SMTPHostRepository>();
155
+            services.AddTransient<IMailRepository, MailRepository>();
155
             #endregion Communication
156
             #endregion Communication
156
             #region Logs 
157
             #region Logs 
157
             services.AddTransient<ISearchLogRepository, SearchLogRepository>();
158
             services.AddTransient<ISearchLogRepository, SearchLogRepository>();
158
             #endregion
159
             #endregion
160
+            #region Financial 
161
+            services.AddTransient<IPaygateRepository, PaygateRepository>();
162
+            #endregion
159
             #region Misc
163
             #region Misc
160
             services.AddTransient<ICarouselRepository, CarouselRepository>();
164
             services.AddTransient<ICarouselRepository, CarouselRepository>();
161
             services.AddTransient<IRepository<PlaceHolderFormat>, PlaceHolderFormatRepository>();            
165
             services.AddTransient<IRepository<PlaceHolderFormat>, PlaceHolderFormatRepository>();            

+ 4
- 1
UnivateProperties_API/UnivateProperties_API.csproj Wyświetl plik

14
     <PackageReference Include="Abp.AutoMapper" Version="4.8.1" />
14
     <PackageReference Include="Abp.AutoMapper" Version="4.8.1" />
15
     <PackageReference Include="AutoMapper" Version="9.0.0" />
15
     <PackageReference Include="AutoMapper" Version="9.0.0" />
16
     <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.0.0" />
16
     <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.0.0" />
17
+    <PackageReference Include="MailKit" Version="2.8.0" />
17
     <PackageReference Include="Microsoft.AspNet.WebApi.Cors" Version="5.2.7" />
18
     <PackageReference Include="Microsoft.AspNet.WebApi.Cors" Version="5.2.7" />
18
     <PackageReference Include="Microsoft.AspNetCore.App" />
19
     <PackageReference Include="Microsoft.AspNetCore.App" />
19
     <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
20
     <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
20
     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
21
     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
21
-    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
22
+    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.4" />
23
+    <PackageReference Include="MimeKit" Version="2.9.1" />
22
     <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0" />
24
     <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0" />
25
+    <PackageReference Include="RestSharp" Version="106.11.4" />
23
     <PackageReference Include="System.Drawing.Common" Version="4.6.0" />
26
     <PackageReference Include="System.Drawing.Common" Version="4.6.0" />
24
   </ItemGroup>
27
   </ItemGroup>
25
 
28
 

+ 1
- 1
UnivateProperties_API/appsettings.json Wyświetl plik

9
   },
9
   },
10
   "AllowedHosts": "*",
10
   "AllowedHosts": "*",
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=192.168.0.219;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_test.sch&CLUB=LPA&RESORT=ALL&SUMMARY=N&HEAD=N"
13
     "TenderConnection": "http://www.unipoint-consoft.co.za/nph-srep.exe?cluvavail_test.sch&CLUB=LPA&RESORT=ALL&SUMMARY=N&HEAD=N"
14
   }
14
   }
15
 }
15
 }

Ładowanie…
Anuluj
Zapisz