Selaa lähdekoodia

Fixes to the to sell page.

master
George Williams 4 vuotta sitten
vanhempi
commit
6692533d32

+ 2
- 0
UnivateProperties_API/Containers/Timeshare/Detailed/DetailedBankDetails.cs Näytä tiedosto

@@ -23,11 +23,13 @@ namespace UnivateProperties_API.Containers.Timeshare.Detailed
23 23
             BankId = bankAccount.BankId;
24 24
             AccountHolder = bankAccount.AccountHolder;
25 25
             AccountNumber = bankAccount.AccountNumber;
26
+            Bank = bankAccount.Bank;
26 27
         }
27 28
 
28 29
         public int Id { get; set; }
29 30
         public int? BankId { get; set; }
30 31
         public string AccountHolder { get; set; } = "";
31 32
         public string AccountNumber { get; set; } = "";
33
+        public Bank Bank { get; set; }
32 34
     }
33 35
 }

+ 1
- 1
UnivateProperties_API/Containers/Timeshare/Detailed/DetailedOwner.cs Näytä tiedosto

@@ -26,7 +26,7 @@ namespace UnivateProperties_API.Containers.Timeshare.Detailed
26 26
                 Address = individual.Address != null ? new DetailedAddress(individual.Address) : new DetailedAddress();
27 27
             }
28 28
             else Address = new DetailedAddress();
29
-            if (BankingDetails != null)
29
+            if (individual.BankAccount != null)
30 30
             {
31 31
                 BankingDetails = individual.BankAccount != null ? new DetailedBankDetails(individual.BankAccount) : new DetailedBankDetails();
32 32
             }

+ 57
- 0
UnivateProperties_API/Containers/Timeshare/TimeshareWeekDto.cs Näytä tiedosto

@@ -0,0 +1,57 @@
1
+using JetBrains.Annotations;
2
+using Org.BouncyCastle.Asn1.Mozilla;
3
+using System;
4
+using System.Collections.Generic;
5
+using System.Linq;
6
+using System.Threading.Tasks;
7
+using UnivateProperties_API.Model.Misc;
8
+using UnivateProperties_API.Model.Timeshare;
9
+
10
+namespace UnivateProperties_API.Containers.Timeshare
11
+{
12
+    public class TimeshareWeekDto : TimeshareWeek
13
+    {
14
+        public OwnerObject OwnerObject { get; set; }
15
+    }
16
+
17
+    public class OwnerObject
18
+    {
19
+        public int Id { get; set; }
20
+        public string Name { get; set; }
21
+        public string Surname { get; set; }
22
+        public string IdNumber { get; set; }
23
+        public string CompanyRegNumber { get; set; }
24
+        public string MaritalStatus { get; set; }
25
+        public string EmailAddress { get; set; }
26
+        public string CellNumber { get; set; }
27
+        public string LandlineNumber { get; set; }
28
+        public OwnerAddress Address { get; set; }
29
+        public OnwerBankingDetails BankingDetails { get; set; }
30
+    }
31
+
32
+    public class OwnerAddress
33
+    {
34
+        public int Id { get; set; }
35
+        public string StreetNumber { get; set; }
36
+        public string Street { get; set; }
37
+        public string Suburb { get; set; }
38
+        public string City { get; set; }
39
+        public string Province { get; set; }
40
+        public string PostalCode { get; set; }
41
+    }
42
+
43
+    public class OnwerBankingDetails
44
+    {
45
+        public int Id { get; set; }
46
+        public string AccountNumber { get; set; }
47
+        public string AccountHolder { get; set; }
48
+        public OwnerBank Bank { get; set; }
49
+    }
50
+
51
+    public class OwnerBank
52
+    {
53
+        public string Name { get; set;  }
54
+        public string UniversalBranchCode { get; set; }
55
+        public int Id { get; set; }        
56
+    }
57
+}

+ 14
- 6
UnivateProperties_API/Controllers/Timeshare/TimeshareWeekController.cs Näytä tiedosto

@@ -1,4 +1,5 @@
1 1
 using Microsoft.AspNetCore.Mvc;
2
+using System.Linq;
2 3
 using System.Transactions;
3 4
 using UnivateProperties_API.Containers.Timeshare;
4 5
 using UnivateProperties_API.Model.Timeshare;
@@ -11,9 +12,9 @@ namespace UnivateProperties_API.Controllers.Timeshare
11 12
     [ApiController]
12 13
     public class TimeshareWeekController : ControllerBase
13 14
     {
14
-        private readonly IRepository<TimeshareWeek> _Repo;
15
+        private readonly IWeekRepository _Repo;
15 16
 
16
-        public TimeshareWeekController(IRepository<TimeshareWeek> repo)
17
+        public TimeshareWeekController(IWeekRepository repo)
17 18
         {
18 19
             _Repo = repo;
19 20
         }
@@ -25,6 +26,12 @@ namespace UnivateProperties_API.Controllers.Timeshare
25 26
             return new OkObjectResult(items);
26 27
         }
27 28
 
29
+        [HttpGet("GetTemplate")]
30
+        public IActionResult GetTemplate()
31
+        {
32
+            return new OkObjectResult(new TimeshareWeekDto());
33
+        }
34
+
28 35
         [HttpGet("{id}")]
29 36
         public IActionResult Get(int id)
30 37
         {
@@ -71,15 +78,16 @@ namespace UnivateProperties_API.Controllers.Timeshare
71 78
             var item = (_Repo as WeekRepository).GetBy(week);
72 79
             return new OkObjectResult(item);
73 80
         }
74
-        
81
+
75 82
         [HttpPost]
76
-        public IActionResult Post([FromBody] TimeshareWeek item)
83
+        public IActionResult Post([FromBody] TimeshareWeekDto item)
77 84
         {
78 85
             using (var scope = new TransactionScope())
79 86
             {
80
-                _Repo.Insert(item);
87
+                var id = _Repo.SaveNewWeek(item);                
88
+                var savedItem = _Repo.Get(x => x.Id == id).FirstOrDefault();
81 89
                 scope.Complete();
82
-                return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
90
+                return new OkObjectResult(savedItem);
83 91
             }
84 92
         }
85 93
 

+ 20
- 0
UnivateProperties_API/Helpers/TenderWeeksHelper.cs Näytä tiedosto

@@ -27,6 +27,26 @@ namespace UnivateProperties_API.Helpers
27 27
             else
28 28
                 return Code;
29 29
         }
30
+
31
+        public static string GetResortCode(string Name)
32
+        {
33
+            if (UniResorts.Count == 0)
34
+            {
35
+                var client = new RestClient("https://www.tradeunipoint.com/unibackend/seam/resource/rest/products/resorts/list/")
36
+                {
37
+                    Timeout = -1
38
+                };
39
+                var request = new RestRequest(Method.GET);
40
+                IRestResponse response = client.Execute(request);
41
+                UniResorts = JsonConvert.DeserializeObject<List<UniPointResorts>>(response.Content);
42
+            }
43
+
44
+            var resort = UniResorts.Find(x => x.ResortName == Name);
45
+            if (resort != null)
46
+                return resort.ResortCode;
47
+            else
48
+                return "";
49
+        }
30 50
     }
31 51
 
32 52
     public class UniPointResorts

+ 119
- 2
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs Näytä tiedosto

@@ -1,4 +1,5 @@
1
-using Microsoft.EntityFrameworkCore;
1
+using Abp.Domain.Entities;
2
+using Microsoft.EntityFrameworkCore;
2 3
 using System;
3 4
 using System.Collections.Generic;
4 5
 using System.Configuration;
@@ -21,7 +22,12 @@ using UnivateProperties_API.Repository.Users;
21 22
 
22 23
 namespace UnivateProperties_API.Repository.Timeshare
23 24
 {
24
-    public class WeekRepository : IRepository<TimeshareWeek>
25
+    public interface IWeekRepository : IRepository<TimeshareWeek>
26
+    {
27
+        int SaveNewWeek(TimeshareWeekDto sellItem);        
28
+    }
29
+
30
+    public class WeekRepository : IWeekRepository
25 31
     {
26 32
         private readonly DataContext _dbContext;
27 33
 
@@ -434,5 +440,116 @@ namespace UnivateProperties_API.Repository.Timeshare
434 440
                 Update(week);
435 441
             }
436 442
         }
443
+
444
+        public int SaveNewWeek(TimeshareWeekDto sellItem)
445
+        {
446
+            var owner = _dbContext.Individuals.Where(x => x.Id == sellItem.OwnerObject.Id).FirstOrDefault();
447
+            var address = _dbContext.Addresses.Where(a => a.Id == sellItem.OwnerObject.Address.Id).FirstOrDefault();
448
+            var banking = _dbContext.BankAccounts.Where(b => b.Id == sellItem.OwnerObject.BankingDetails.Id).FirstOrDefault();
449
+            var status = _dbContext.Status.Where(s => s.Code == "A1" && s.StatusType == StatusType.Timeshare).FirstOrDefault();
450
+
451
+            #region Address
452
+            if (sellItem.OwnerObject.Address.PostalCode != "")
453
+            {
454
+                if (address == null)
455
+                {
456
+                    address = new Model.Misc.Address();
457
+                }
458
+                address.StreetNumber = sellItem.OwnerObject.Address.StreetNumber;
459
+                address.Street = sellItem.OwnerObject.Address.Street;
460
+                address.Suburb = sellItem.OwnerObject.Address.Suburb;
461
+                address.City = sellItem.OwnerObject.Address.City;
462
+                address.Province = sellItem.OwnerObject.Address.Province;
463
+                address.PostalCode = sellItem.OwnerObject.Address.PostalCode;
464
+
465
+                if (address.Id == 0)
466
+                {
467
+                    _dbContext.Add(address);
468
+                    Save();
469
+                }
470
+                else
471
+                {
472
+                    _dbContext.Entry(address).State = EntityState.Modified;
473
+                    Save();
474
+                }
475
+            }
476
+            #endregion
477
+
478
+            #region Banking
479
+            if (sellItem.OwnerObject.BankingDetails.AccountHolder != "")
480
+            {
481
+                if (banking == null)
482
+                {
483
+                    banking = new Model.Banks.BankAccount();
484
+                }
485
+                banking.AccountHolder = sellItem.OwnerObject.BankingDetails.AccountHolder;
486
+                banking.AccountNumber = sellItem.OwnerObject.BankingDetails.AccountNumber;
487
+                banking.BankId = sellItem.OwnerObject.BankingDetails.Bank.Id;
488
+
489
+                if (banking.Id == 0)
490
+                {
491
+                    _dbContext.Add(banking);
492
+                    Save();
493
+                }
494
+                else
495
+                {
496
+                    _dbContext.Entry(banking).State = EntityState.Modified;
497
+                    Save();
498
+                }
499
+            }
500
+            #endregion
501
+
502
+            #region Owner
503
+            if (owner == null)
504
+            {
505
+                owner = new Model.Users.Individual();
506
+            }
507
+            if (address != null)
508
+            {
509
+                owner.AddressId = address.Id;
510
+                owner.Address = address;
511
+            }
512
+            if (banking != null)
513
+            {
514
+                owner.BankAccount = banking;
515
+                owner.BankAccountId = banking.Id;
516
+            }
517
+            owner.Name = sellItem.OwnerObject.Name;
518
+            owner.Surname = sellItem.OwnerObject.Surname;
519
+            owner.IdNumber = sellItem.OwnerObject.IdNumber;
520
+            owner.CompanyRegNumber = sellItem.OwnerObject.CompanyRegNumber;
521
+            owner.MaritalStatus = sellItem.OwnerObject.MaritalStatus;
522
+            owner.Email = sellItem.OwnerObject.EmailAddress;
523
+            owner.CellNumber = sellItem.OwnerObject.CellNumber;
524
+            owner.Telephone = sellItem.OwnerObject.LandlineNumber;
525
+
526
+            if (owner.Id == 0)
527
+            {
528
+                _dbContext.Add(owner);
529
+                Save();
530
+            }
531
+            else
532
+            {
533
+                _dbContext.Entry(owner).State = EntityState.Modified;
534
+                Save();
535
+            }
536
+            #endregion
537
+
538
+            var week = new TimeshareWeek();
539
+            foreach(string prop in week.GetAllProperties())
540
+            {
541
+                if (prop != "Item" && prop != "Display")
542
+                    week[prop] = sellItem[prop];
543
+            }
544
+            week.Region = null;
545
+            week.RegionId = sellItem.Region.Id;
546
+            week.OwnerId = owner.Id;
547
+
548
+            week.StatusId = status.Id;
549
+            _dbContext.Add(week);
550
+            Save();
551
+
552
+            return week.Id;
553
+        }
437 554
     }
438 555
 }

+ 4
- 0
UnivateProperties_API/Repository/Users/IndividualRepository.cs Näytä tiedosto

@@ -61,6 +61,10 @@ namespace UnivateProperties_API.Repository.Users
61 61
             var item = _dbContext.Individuals.Include("Address").Include("BankAccount").FirstOrDefault(x => x.UserId == id);
62 62
             if(item != null)
63 63
             {
64
+                if (item.BankAccount != null && item.BankAccount.BankId > 0)
65
+                {
66
+                    item.BankAccount.Bank = _dbContext.Banks.Where(b => b.Id == item.BankAccount.BankId).FirstOrDefault();
67
+                }
64 68
                 return new DetailedOwner(item);
65 69
             }
66 70
             else

+ 1
- 1
UnivateProperties_API/Startup.cs Näytä tiedosto

@@ -135,7 +135,7 @@ namespace UnivateProperties_API
135 135
             services.AddTransient<IRepository<Season>, SeasonRepository>();
136 136
             services.AddTransient<IRepository<UnitConfiguration>, UnitConfigurationRepository>();
137 137
             services.AddTransient<IRepository<TimeshareWeek>, WeekRepository>();
138
-            services.AddTransient<IRepository<TimeshareWeek>, WeekRepository>();
138
+            services.AddTransient<IWeekRepository, WeekRepository>();
139 139
             services.AddTransient<IRepository<Bank>, BankAccountRepository>();
140 140
             services.AddTransient<IRepository<BankAccount>, BankAccountRepository>();
141 141
             #endregion Timeshare

Loading…
Peruuta
Tallenna