Преглед изворни кода

Updated paygate functions

master
30117125 пре 4 година
родитељ
комит
02509ca375

+ 5
- 1
UnivateProperties_API/Containers/Timeshare/WeekDto.cs Прегледај датотеку

@@ -103,7 +103,9 @@ namespace UnivateProperties_API.Containers.Timeshare
103 103
             OtherResort = week.OtherResort;
104 104
             Agency = week.Agency?.AgencyName;
105 105
             Agent = $"{week.Agent?.Name} {week.Agent?.Surname}";
106
-            Owner = $"{week.Owner?.Name} {week.Owner?.Surname}";
106
+            Owner = week.DisplayOwner;
107
+            OwnerId = week.Owner.Id;
108
+            UserId = week.Owner.UserId;
107 109
             Resort = new ResortDto(week.ResortCode, week.ResortName);
108 110
             Region = new RegionDto(week.Region != null ? week.Region.Id : 0, week.Region?.Code, week.Region?.Description);
109 111
             Season = week.Season;
@@ -138,6 +140,8 @@ namespace UnivateProperties_API.Containers.Timeshare
138 140
         public string Agency { get; set; }
139 141
         public string Agent { get; set; }
140 142
         public string Owner { get; set; }
143
+        public int OwnerId { get; set; }
144
+        public int? UserId { get; set; }
141 145
         public bool AgentAsRep { get; set; }
142 146
         public bool OtherResort { get; set; }
143 147
         public int Bedrooms { get; set; }

+ 3
- 3
UnivateProperties_API/Controllers/Financial/PaymentController.cs Прегледај датотеку

@@ -26,11 +26,11 @@ namespace UnivateProperties_API.Controllers.Financial
26 26
         }
27 27
 
28 28
         [HttpGet("{id}")]
29
-        public IActionResult Get(int id)
29
+        public IActionResult Get(string id)
30 30
         {
31
-            return new OkObjectResult(_Repo.Get(x => x.Id == id));
31
+            return new OkObjectResult(_Repo.Get(x => x.PayRequestId == id));
32 32
         }
33
-        
33
+
34 34
         [HttpPost]
35 35
         public IActionResult Post([FromBody] Payment payment)
36 36
         {

+ 33
- 1
UnivateProperties_API/Controllers/Financial/RedirectController.cs Прегледај датотеку

@@ -1,5 +1,10 @@
1 1
 using Microsoft.AspNetCore.Mvc;
2
+using System;
3
+using System.Linq;
2 4
 using UnivateProperties_API.Model.Financial;
5
+using UnivateProperties_API.Model.Timeshare;
6
+using UnivateProperties_API.Repository;
7
+using UnivateProperties_API.Repository.Financial;
3 8
 
4 9
 namespace UnivateProperties_API.Controllers.Financial
5 10
 {
@@ -7,19 +12,46 @@ namespace UnivateProperties_API.Controllers.Financial
7 12
     [ApiController]
8 13
     public class RedirectController : ControllerBase
9 14
     {
15
+        private readonly IRepository<Payment> _repo;
16
+        private readonly IPaygateRepository _paygateRepo;
17
+        private readonly IRepository<TimeshareWeek> _timeshareRepo;
18
+
19
+        public RedirectController(IRepository<Payment> rp, IPaygateRepository pgr, IRepository<TimeshareWeek> timeshare)
20
+        {
21
+            _repo = rp;
22
+            _paygateRepo = pgr;
23
+            _timeshareRepo = timeshare;
24
+        }
10 25
 
11 26
         // POST: api/Redirect
12 27
         [HttpPost]
13 28
         [Consumes("application/x-www-form-urlencoded")]
14 29
         public RedirectResult PostRedirect([FromForm] ReturnToMerchant context)
15 30
         {
31
+            string paygateId = "10011072130";
32
+            var payment = _repo.Get(x => x.PayRequestId == context.PAY_REQUEST_ID).FirstOrDefault();
33
+            var timeshareWeek = _timeshareRepo.Get(x => x.Id == Convert.ToInt32(payment.PaymentToken)).FirstOrDefault();
34
+            if (context.TRANSACTION_STATUS == 0)
35
+            {
36
+                string queryResult = _paygateRepo.PaymentQuery(paygateId, payment);
37
+                
38
+                timeshareWeek.StatusId = 32;
39
+                _timeshareRepo.Update(timeshareWeek);
40
+                return Redirect("http://training.provision-sa.com:122/#/payments/error/" + context.PAY_REQUEST_ID);
41
+            }
16 42
             if (context.TRANSACTION_STATUS == 1)
17 43
             {
44
+                string queryResult = _paygateRepo.PaymentQuery(paygateId, payment);
45
+                timeshareWeek.StatusId = 22;
46
+                _timeshareRepo.Update(timeshareWeek);
18 47
                 return Redirect("http://training.provision-sa.com:122/#/payments/success");
19 48
             }
20 49
             else if (context.TRANSACTION_STATUS == 2)
21 50
             {
22
-                return Redirect("http://training.provision-sa.com:122/#/paymentError");
51
+                string queryResult = _paygateRepo.PaymentQuery(paygateId, payment);
52
+                timeshareWeek.StatusId = 32;
53
+                _timeshareRepo.Update(timeshareWeek);
54
+                return Redirect("http://training.provision-sa.com:122/#/payments/error/" + context.PAY_REQUEST_ID);
23 55
             }
24 56
             else
25 57
             {

+ 1
- 1
UnivateProperties_API/Controllers/Timeshare/StatusController.cs Прегледај датотеку

@@ -41,7 +41,7 @@ namespace UnivateProperties_API.Controllers.Timeshare
41 41
             }
42 42
         }
43 43
 
44
-        [HttpPut("{id}")]
44
+        [HttpPut]
45 45
         public IActionResult Put([FromBody] Status item)
46 46
         {
47 47
             if (item != null)

+ 15
- 0
UnivateProperties_API/Controllers/Timeshare/TimeshareWeekController.cs Прегледај датотеку

@@ -117,6 +117,21 @@ namespace UnivateProperties_API.Controllers.Timeshare
117 117
             return new NoContentResult();
118 118
         }
119 119
 
120
+        [HttpPut("publishOnly")]
121
+        public IActionResult PublishOnly([FromBody] WeekDto item)
122
+        {
123
+            if (item != null)
124
+            {
125
+                using (var scope = new TransactionScope())
126
+                {
127
+                    _Repo.PublishOnly(item);
128
+                    scope.Complete();
129
+                    return new OkResult();
130
+                }
131
+            }
132
+            return new NoContentResult();
133
+        }
134
+
120 135
         [HttpDelete("{id}")]
121 136
         public IActionResult Delete(int id)
122 137
         {

+ 1689
- 0
UnivateProperties_API/Migrations/20201027111708_TimeshareWeekDisplayOwner.Designer.cs
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 22
- 0
UnivateProperties_API/Migrations/20201027111708_TimeshareWeekDisplayOwner.cs Прегледај датотеку

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

+ 1693
- 0
UnivateProperties_API/Migrations/20201030063947_addFieldsToPayments.Designer.cs
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 31
- 0
UnivateProperties_API/Migrations/20201030063947_addFieldsToPayments.cs Прегледај датотеку

@@ -0,0 +1,31 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class addFieldsToPayments : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+            migrationBuilder.AddColumn<string>(
10
+                name: "Checksum",
11
+                table: "Payments",
12
+                nullable: true);
13
+
14
+            migrationBuilder.AddColumn<string>(
15
+                name: "PayRequestId",
16
+                table: "Payments",
17
+                nullable: true);
18
+        }
19
+
20
+        protected override void Down(MigrationBuilder migrationBuilder)
21
+        {
22
+            migrationBuilder.DropColumn(
23
+                name: "Checksum",
24
+                table: "Payments");
25
+
26
+            migrationBuilder.DropColumn(
27
+                name: "PayRequestId",
28
+                table: "Payments");
29
+        }
30
+    }
31
+}

+ 1692
- 0
UnivateProperties_API/Migrations/20201030070202_addFieldsToPayments1.Designer.cs
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 50
- 0
UnivateProperties_API/Migrations/20201030070202_addFieldsToPayments1.cs Прегледај датотеку

@@ -0,0 +1,50 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class addFieldsToPayments1 : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+            migrationBuilder.DropForeignKey(
10
+                name: "FK_Payments_Users_CreatedById",
11
+                table: "Payments");
12
+
13
+            migrationBuilder.AlterColumn<int>(
14
+                name: "CreatedById",
15
+                table: "Payments",
16
+                nullable: true,
17
+                oldClrType: typeof(int));
18
+
19
+            migrationBuilder.AddForeignKey(
20
+                name: "FK_Payments_Users_CreatedById",
21
+                table: "Payments",
22
+                column: "CreatedById",
23
+                principalTable: "Users",
24
+                principalColumn: "Id",
25
+                onDelete: ReferentialAction.Restrict);
26
+        }
27
+
28
+        protected override void Down(MigrationBuilder migrationBuilder)
29
+        {
30
+            migrationBuilder.DropForeignKey(
31
+                name: "FK_Payments_Users_CreatedById",
32
+                table: "Payments");
33
+
34
+            migrationBuilder.AlterColumn<int>(
35
+                name: "CreatedById",
36
+                table: "Payments",
37
+                nullable: false,
38
+                oldClrType: typeof(int),
39
+                oldNullable: true);
40
+
41
+            migrationBuilder.AddForeignKey(
42
+                name: "FK_Payments_Users_CreatedById",
43
+                table: "Payments",
44
+                column: "CreatedById",
45
+                principalTable: "Users",
46
+                principalColumn: "Id",
47
+                onDelete: ReferentialAction.Cascade);
48
+        }
49
+    }
50
+}

+ 8
- 3
UnivateProperties_API/Migrations/DataContextModelSnapshot.cs Прегледај датотеку

@@ -408,9 +408,11 @@ namespace UnivateProperties_API.Migrations
408 408
 
409 409
                     b.Property<decimal>("Amount");
410 410
 
411
+                    b.Property<string>("Checksum");
412
+
411 413
                     b.Property<DateTime>("Created");
412 414
 
413
-                    b.Property<int>("CreatedById");
415
+                    b.Property<int?>("CreatedById");
414 416
 
415 417
                     b.Property<bool>("IsDeleted");
416 418
 
@@ -418,6 +420,8 @@ namespace UnivateProperties_API.Migrations
418 420
 
419 421
                     b.Property<string>("ModifiedBy");
420 422
 
423
+                    b.Property<string>("PayRequestId");
424
+
421 425
                     b.Property<string>("PaymentStatus");
422 426
 
423 427
                     b.Property<string>("PaymentToken");
@@ -1056,6 +1060,8 @@ namespace UnivateProperties_API.Migrations
1056 1060
 
1057 1061
                     b.Property<DateTime>("DepartureDate");
1058 1062
 
1063
+                    b.Property<string>("DisplayOwner");
1064
+
1059 1065
                     b.Property<bool>("IsDeleted");
1060 1066
 
1061 1067
                     b.Property<bool>("LeviesPaidInFull");
@@ -1486,8 +1492,7 @@ namespace UnivateProperties_API.Migrations
1486 1492
                 {
1487 1493
                     b.HasOne("UnivateProperties_API.Model.Users.User", "CreatedBy")
1488 1494
                         .WithMany()
1489
-                        .HasForeignKey("CreatedById")
1490
-                        .OnDelete(DeleteBehavior.Cascade);
1495
+                        .HasForeignKey("CreatedById");
1491 1496
 
1492 1497
                     b.HasOne("UnivateProperties_API.Model.Properties.Property", "Property")
1493 1498
                         .WithMany()

+ 2
- 3
UnivateProperties_API/Model/Financial/Payment.cs Прегледај датотеку

@@ -12,12 +12,11 @@ namespace UnivateProperties_API.Model.Financial
12 12
         public int? TimeshareWeekId { get; set; }
13 13
         [ForeignKey("Property")]
14 14
         public int? PropertyId { get; set; }
15
-        [ForeignKey("CreatedBy")]
16
-        public int CreatedById { get; set; }
17 15
         public decimal Amount { get; set; }
18 16
         public string PaymentStatus { get; set; }
19 17
         public string PaymentToken { get; set; }
20
-
18
+        public string Checksum { get; set; }
19
+        public string PayRequestId { get; set; }
21 20
 
22 21
         public virtual TimeshareWeek TimeshareWeek { get; set; }
23 22
         public virtual Property Property { get; set; }

+ 0
- 2
UnivateProperties_API/Model/Financial/ReturnToMerchant.cs Прегледај датотеку

@@ -7,7 +7,5 @@
7 7
         public int TRANSACTION_STATUS { get; set; }
8 8
 
9 9
         public string RESULT_CODE { get; set; }
10
-
11
-        public string CHECKSUM { get; set; }
12 10
     }
13 11
 }

+ 3
- 2
UnivateProperties_API/Model/Timeshare/TimeshareWeek.cs Прегледај датотеку

@@ -14,7 +14,7 @@ namespace UnivateProperties_API.Model.Timeshare
14 14
         {
15 15
         }
16 16
 
17
-        public TimeshareWeek(bool referedByAgent, int? agentId, int? agencyId, int ownerId, bool agentAsRep, bool otherResort, string otherResortName, string resortCode, string resortName, int regionId, string season, string module, int bedrooms, int maxSleep, string unitNumber, string weekNumber, double levyAmount, bool currentYearBanked, string bankedWith, bool leviesPaidInFull, bool weekPlacedForRental, double originalPurchasePrice, DateTime originalPurchaseDate, DateTime arrivalDate, DateTime departureDate, double sellPrice, double askingPrice, double agentCommision, bool mandate, int statusId, Status status, Province region, Individual owner, Agent agent, Agency agency, ICollection<BidItem> bidItems, ICollection<ProcessFlow.ProcessFlow> processFlows, string weekStatus, DateTime datePublished, bool published)
17
+        public TimeshareWeek(bool referedByAgent, int? agentId, int? agencyId, int ownerId, bool agentAsRep, bool otherResort, string otherResortName, string resortCode, string resortName, int regionId, string season, string module, int bedrooms, int maxSleep, string unitNumber, string weekNumber, double levyAmount, bool currentYearBanked, string bankedWith, bool leviesPaidInFull, bool weekPlacedForRental, double originalPurchasePrice, DateTime originalPurchaseDate, DateTime arrivalDate, DateTime departureDate, double sellPrice, double askingPrice, double agentCommision, bool mandate, int statusId, Status status, Province region, Individual owner, Agent agent, Agency agency, ICollection<BidItem> bidItems, ICollection<ProcessFlow.ProcessFlow> processFlows, string weekStatus, DateTime datePublished, bool published, string displayOwner)
18 18
         {
19 19
             ReferedByAgent = referedByAgent;
20 20
             AgentId = agentId;
@@ -56,6 +56,7 @@ namespace UnivateProperties_API.Model.Timeshare
56 56
             WeekStatus = weekStatus;
57 57
             Publish = published;
58 58
             PulbishedDate = datePublished;
59
+            DisplayOwner = displayOwner;
59 60
         }
60 61
 
61 62
         #region Properties
@@ -81,7 +82,7 @@ namespace UnivateProperties_API.Model.Timeshare
81 82
         public string UnitNumber { get; set; }
82 83
         public string WeekNumber { get; set; }
83 84
         public double LevyAmount { get; set; }
84
-
85
+        public string DisplayOwner { get; set; }
85 86
         public bool CurrentYearBanked { get; set; }
86 87
         public string BankedWith { get; set; }
87 88
 

+ 153
- 5
UnivateProperties_API/Repository/Financial/PaygateRepository.cs Прегледај датотеку

@@ -5,6 +5,7 @@ using System.Linq;
5 5
 using System.Security.Cryptography;
6 6
 using System.Text;
7 7
 using System.Threading.Tasks;
8
+using UnivateProperties_API.Context;
8 9
 using UnivateProperties_API.Model.Financial;
9 10
 
10 11
 namespace UnivateProperties_API.Repository.Financial
@@ -12,10 +13,18 @@ namespace UnivateProperties_API.Repository.Financial
12 13
     public interface IPaygateRepository
13 14
     {
14 15
         string GoToPaymentGateway(Payment payment);
16
+        string PaymentQuery(string id, Payment payment);
15 17
     }
16 18
 
17 19
     public class PaygateRepository: IPaygateRepository
18 20
     {
21
+        private readonly DataContext _dbContext;
22
+
23
+        public PaygateRepository(DataContext db)
24
+        {
25
+            _dbContext = db;
26
+        }
27
+
19 28
         public string GoToPaymentGateway(Payment payment)
20 29
         {
21 30
             string utcDate = DateTime.UtcNow.ToString("yyyy-MM-dd H:mm:ss");
@@ -25,13 +34,16 @@ namespace UnivateProperties_API.Repository.Financial
25 34
             var total = payment.Amount;
26 35
             string paygateId = "10011072130";
27 36
             string reff = "";
37
+            Payment paymentObj = new Payment();
28 38
             if (payment.TimeshareWeekId != 0)
29 39
             {
30 40
                 reff = payment.TimeshareWeekId.ToString();
41
+                paymentObj.TimeshareWeekId = payment.TimeshareWeekId;
31 42
             }
32 43
             else
33 44
             {
34 45
                 reff = payment.PropertyId.ToString();
46
+                paymentObj.PropertyId = payment.PropertyId;
35 47
             }
36 48
 
37 49
             string amm = Math.Round((total * 100)).ToString();
@@ -66,11 +78,147 @@ namespace UnivateProperties_API.Repository.Financial
66 78
             string gatewayReturn = client.Execute(request).Content.ToString();
67 79
             List<string> vs = gatewayReturn.Split('&').ToList();
68 80
             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();
81
+            string resultString = client.Execute(request).Content.ToString();
82
+            var resultArr = resultString.Split('&');
83
+            List<string> valueArr = new List<string>();
84
+            foreach (var item in resultArr)
85
+            {
86
+                valueArr.Add(item.Split('=')[1]);
87
+            }
88
+
89
+            paymentObj.Amount = total;
90
+            paymentObj.PayRequestId = valueArr[1];
91
+            paymentObj.PaymentToken = valueArr[2];
92
+            paymentObj.Checksum = valueArr[3];
93
+
94
+            //PaymentQuery(paygateId, paymentObj);
95
+           
96
+
97
+            _dbContext.Payments.Add(paymentObj);
98
+            _dbContext.SaveChanges();
99
+
100
+            return resultString;
101
+        }
102
+
103
+        public string PaymentQuery(string paygateId, Payment payment)
104
+        {
105
+            var client = new RestClient("https://secure.paygate.co.za/payweb3/query.trans");
106
+            client.Timeout = -1;
107
+            var request = new RestRequest(Method.POST);
108
+            request.AddParameter("PAYGATE_ID", paygateId);
109
+            request.AddParameter("PAY_REQUEST_ID", payment.PayRequestId);
110
+            request.AddParameter("REFERENCE", payment.PaymentToken);
111
+            string checksum = Checksum(
112
+                paygateId +
113
+                payment.PayRequestId +
114
+                payment.PaymentToken +
115
+                "secret");
116
+            request.AddParameter("CHECKSUM", checksum);
117
+            string resultString = client.Execute(request).Content.ToString();
118
+            var resultArr = resultString.Split('&');
119
+            List<string> valueArr = new List<string>();
120
+            string transactionResult = "";
121
+            foreach (var item in resultArr)
122
+            {
123
+                valueArr.Add(item.Split('=')[1]);
124
+            }
125
+
126
+            switch (valueArr[4])
127
+            {
128
+                case "900001":
129
+                    transactionResult = "Call for Approval";
130
+                    break;
131
+                case "900002":
132
+                    transactionResult = "Card Expired";
133
+                    break;
134
+                case "900003":
135
+                    transactionResult = "Insufficient Funds";
136
+                    break;
137
+                case "900004":
138
+                    transactionResult = "Invalid Card Number";
139
+                    break;
140
+                case "900005": //Indicates a communications failure between the banks systems.
141
+                    transactionResult = "Bank Interface Timeout";
142
+                    break;
143
+                case "900006":
144
+                    transactionResult = "Invalid Card";
145
+                    break;
146
+                case "900007":
147
+                    transactionResult = "Declined";
148
+                    break;
149
+                case "900009":
150
+                    transactionResult = "Lost Card";
151
+                    break;
152
+                case "900010":
153
+                    transactionResult = "Invalid Card Length";
154
+                    break;
155
+                case "900011":
156
+                    transactionResult = "Suspected Fraud";
157
+                    break;
158
+                case "900012":
159
+                    transactionResult = "Card Reported as Stolen";
160
+                    break;
161
+                case "900013":
162
+                    transactionResult = "Restricted Card";
163
+                    break;
164
+                case "900014":
165
+                    transactionResult = "Excessive Card Usage";
166
+                    break;
167
+                case "900015":
168
+                    transactionResult = "Card Blacklisted";
169
+                    break;
170
+                case "990017":
171
+                    transactionResult = "Auth Done";
172
+                    break;
173
+                case "900207": //Indicates the cardholder did not enter their MasterCard SecureCode / Verified by Visa password correctly.
174
+                    transactionResult = "Declined; authentication failed";
175
+                    break;
176
+                case "990020":
177
+                    transactionResult = "Auth Declined";
178
+                    break;
179
+                case "900210": //Indicates that the MasterCard SecureCode / Verified-by-Visa transaction has already been completed. Most likely caused by a customer clicking the refresh button.
180
+                    transactionResult = "3D Secure Lookup Timeout";
181
+                    break;
182
+                case "991001":
183
+                    transactionResult = "Invalid expiry date";
184
+                    break;
185
+                case "991002":
186
+                    transactionResult = "Invalid Amount";
187
+                    break;
188
+                case "900205":
189
+                    transactionResult = "Unexpected authentication result (phase 1)";
190
+                    break;
191
+                case "900206":
192
+                    transactionResult = "Unexpected authentication result (phase 2)";
193
+                    break;
194
+                case "990001":
195
+                    transactionResult = "Could not insert into Database";
196
+                    break;
197
+                case "990022":
198
+                    transactionResult = "Bank not available";
199
+                    break;
200
+                case "990053":
201
+                    transactionResult = "Error processing transaction";
202
+                    break;
203
+                case "900209": //Indicates the verification data returned from MasterCard SecureCode / Verified-by-Visa has been altered.
204
+                    transactionResult = "Transaction verification failed (phase 2)";
205
+                    break;
206
+                case "900019":
207
+                    transactionResult = "Invalid PayVault Scope";
208
+                    break;
209
+                case "990024":
210
+                    transactionResult = "Duplicate Transaction Detected. Please check before submitting";
211
+                    break;
212
+                case "990028": //Customer clicks the ‘Cancel’ button on the payment page.
213
+                    transactionResult = "Transaction cancelled";
214
+                    break;
215
+            }
216
+
217
+            payment.PaymentStatus = transactionResult;
218
+            _dbContext.Payments.Update(payment);
219
+            _dbContext.SaveChanges();
220
+
221
+            return resultString;
74 222
         }
75 223
 
76 224
         private string Checksum(string data)

+ 2
- 2
UnivateProperties_API/Repository/Timeshare/StatusRepository.cs Прегледај датотеку

@@ -39,8 +39,8 @@ namespace UnivateProperties_API.Repository.Timeshare
39 39
 
40 40
         public void Insert(Status item)
41 41
         {
42
-            item.Id = NewId();
43
-            _dbContext.Add(item);
42
+            
43
+            _dbContext.Status.Add(item);
44 44
             Save();
45 45
         }
46 46
 

+ 45
- 5
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs Прегледај датотеку

@@ -27,6 +27,7 @@ namespace UnivateProperties_API.Repository.Timeshare
27 27
     public interface IWeekRepository : IRepository<TimeshareWeek>
28 28
     {
29 29
         int SaveNewWeek(TimeshareWeekDto sellItem);
30
+        void PublishOnly(WeekDto week);
30 31
         List<WeekDto> GetAllByResortCode(string resortCode);
31 32
     }
32 33
 
@@ -46,7 +47,7 @@ namespace UnivateProperties_API.Repository.Timeshare
46 47
 
47 48
         public List<TimeshareWeek> GetAll()
48 49
         {
49
-            return _dbContext.Weeks.ToList();
50
+            return _dbContext.Weeks.Include("Owner").ToList();
50 51
         }
51 52
 
52 53
         public TimeshareWeek GetDetailed(Func<TimeshareWeek, bool> first)
@@ -238,6 +239,8 @@ namespace UnivateProperties_API.Repository.Timeshare
238 239
             {
239 240
                 IndividualRepository individual = new IndividualRepository(_dbContext);
240 241
                 week.Owner = individual.Get(x => x.Id == week.OwnerId).FirstOrDefault();
242
+                //week.DisplayOwner = week.Owner.Name + " " + week.Owner.Surname;
243
+                
241 244
             }
242 245
             return week;
243 246
         }
@@ -324,6 +327,24 @@ namespace UnivateProperties_API.Repository.Timeshare
324 327
             _dbContext.SaveChanges();
325 328
         }
326 329
 
330
+        public void PublishOnly(WeekDto week)
331
+        {
332
+            var saved = _dbContext.Weeks.Where(w => w.Id == week.Id).FirstOrDefault();
333
+
334
+            if(saved.StatusId != week.Status.Id)
335
+            {
336
+                saved.StatusId = week.Status.Id;
337
+            }
338
+
339
+            if (saved.Publish != week.Publish)
340
+            {
341
+                saved.Publish = week.Publish;
342
+            }
343
+
344
+            _dbContext.Update(saved);
345
+            Save();
346
+        }
347
+
327 348
         public void Update(TimeshareWeek item)
328 349
         {
329 350
             var saved = _dbContext.Weeks.Where(w => w.Id == item.Id).FirstOrDefault();
@@ -389,7 +410,13 @@ namespace UnivateProperties_API.Repository.Timeshare
389 410
                 saved.BankedWith = item.BankedWith;
390 411
             }
391 412
 
392
-            var owner = _dbContext.Individuals.Where(x => x.Id == item.Owner.Id).FirstOrDefault();
413
+
414
+            if (saved.DisplayOwner != item.DisplayOwner)
415
+            {
416
+                saved.DisplayOwner = item.Owner.Name + " " + item.Owner.Surname;
417
+            }
418
+
419
+            /*var owner = _dbContext.Individuals.Where(x => x.Id == item.OwnerId).FirstOrDefault();
393 420
 
394 421
             if (owner.Name != item.Owner.Name)
395 422
             {
@@ -418,7 +445,7 @@ namespace UnivateProperties_API.Repository.Timeshare
418 445
             if (owner.Telephone != item.Owner.Telephone)
419 446
             {
420 447
                 owner.Telephone = item.Owner.Telephone;
421
-            }
448
+            }*/
422 449
 
423 450
 
424 451
             if (saved.Mandate != item.Mandate)
@@ -426,10 +453,22 @@ namespace UnivateProperties_API.Repository.Timeshare
426 453
                 if (item.Mandate)
427 454
                     saved.DateMandated = DateTime.Now;
428 455
             }
429
-            if (saved.WeekStatus != item.WeekStatus)
456
+
457
+            if (item.Status != null)
458
+            {
459
+                if (saved.StatusId != item.Status.Id)
460
+                {
461
+                    saved.StatusId = item.Status.Id;
462
+                }
463
+            }
464
+            else
430 465
             {
431
-                saved.WeekStatus = item.WeekStatus;
466
+                var status = _dbContext.Status.Where(x => x.Id == item.StatusId).FirstOrDefault();
467
+                saved.Status = status;
468
+                saved.StatusId = item.StatusId;
432 469
             }
470
+            
471
+
433 472
             if (saved.Publish != item.Publish)
434 473
             {
435 474
                 saved.Publish = item.Publish;
@@ -709,6 +748,7 @@ namespace UnivateProperties_API.Repository.Timeshare
709 748
             owner.Email = sellItem.OwnerObject.EmailAddress;
710 749
             owner.CellNumber = sellItem.OwnerObject.CellNumber;
711 750
             owner.Telephone = sellItem.OwnerObject.LandlineNumber;
751
+            sellItem.DisplayOwner = owner.Name + " " +  owner.Surname;
712 752
 
713 753
             switch (sellItem.OwnerObject.MaritalStatus.ToUpper())
714 754
             {

Loading…
Откажи
Сачувај