Parcourir la source

Added Province to Detailed Address and made changes to Individual

master
Lene Scholtz il y a 5 ans
Parent
révision
da8006c95a

+ 4
- 1
UnivateProperties_API/Containers/Timeshare/Detailed/DetailedAddress.cs Voir le fichier

@@ -9,13 +9,14 @@ namespace UnivateProperties_API.Containers.Timeshare.Detailed
9 9
 
10 10
         }
11 11
 
12
-        public DetailedAddress(int id, string streetNumber, string street, string suburb, string city, string postalCode)
12
+        public DetailedAddress(int id, string streetNumber, string street, string suburb, string city, string postalCode, string province)
13 13
         {
14 14
             Id = id;
15 15
             StreetNumber = streetNumber;
16 16
             Street = street;
17 17
             Suburb = suburb;
18 18
             City = city;
19
+            Province = province;
19 20
             PostalCode = postalCode;
20 21
         }
21 22
 
@@ -26,6 +27,7 @@ namespace UnivateProperties_API.Containers.Timeshare.Detailed
26 27
             Street = address.Street;
27 28
             Suburb = address.Suburb;
28 29
             City = address.City;
30
+            Province = address.Province;
29 31
             PostalCode = address.PostalCode;
30 32
         }
31 33
 
@@ -34,6 +36,7 @@ namespace UnivateProperties_API.Containers.Timeshare.Detailed
34 36
         public string Street { get; set; } = "";
35 37
         public string Suburb { get; set; } = "";
36 38
         public string City { get; set; } = "";
39
+        public string Province { get; set; } = "";
37 40
         public string PostalCode { get; set; } = "";
38 41
     }
39 42
 }

+ 5
- 5
UnivateProperties_API/Controllers/Users/IndividualController.cs Voir le fichier

@@ -1,5 +1,6 @@
1 1
 using System.Transactions;
2 2
 using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Containers.Timeshare.Detailed;
3 4
 using UnivateProperties_API.Model.Users;
4 5
 using UnivateProperties_API.Repository;
5 6
 using UnivateProperties_API.Repository.Users;
@@ -27,7 +28,7 @@ namespace User_API.Controllers
27 28
         //Gets data from DB by Id
28 29
         [HttpGet("{id}")]
29 30
         public IActionResult Get(int id)
30
-        {
31
+        {            
31 32
             return new OkObjectResult(_Repo.Get(x => x.Id == id));
32 33
         }
33 34
 
@@ -43,15 +44,14 @@ namespace User_API.Controllers
43 44
             return new OkObjectResult((_Repo as IndividualRepository).GetAllIndividuals());
44 45
         }
45 46
 
46
-        //Updates to DB
47 47
         [HttpPut()]
48
-        public IActionResult Put([FromBody] Individual individual)
48
+        public IActionResult Put([FromBody]DetailedOwner owner)
49 49
         {
50
-            if (individual != null)
50
+            if (owner != null)
51 51
             {
52 52
                 using (var scope = new TransactionScope())
53 53
                 {
54
-                    _Repo.Update(individual);
54
+                    (_Repo as IndividualRepository).Update(owner);
55 55
                     scope.Complete();
56 56
                     return new OkResult();
57 57
                 }

+ 1
- 0
UnivateProperties_API/Model/Misc/Address.cs Voir le fichier

@@ -10,6 +10,7 @@ namespace UnivateProperties_API.Model.Misc
10 10
         public string Suburb { get; set; }
11 11
         public string City { get; set; }
12 12
         public string PostalCode { get; set; }
13
+        public string Province { get; set; }
13 14
         [ForeignKey("Owner")]
14 15
         public int? OwnerId { get; set; }
15 16
 

+ 64
- 0
UnivateProperties_API/Model/Users/Individual.cs Voir le fichier

@@ -1,6 +1,7 @@
1 1
 using System.Collections.Generic;
2 2
 using System.ComponentModel.DataAnnotations;
3 3
 using System.ComponentModel.DataAnnotations.Schema;
4
+using UnivateProperties_API.Containers.Timeshare.Detailed;
4 5
 using UnivateProperties_API.Model.Banks;
5 6
 using UnivateProperties_API.Model.Misc;
6 7
 using UnivateProperties_API.Model.Properties;
@@ -14,6 +15,7 @@ namespace UnivateProperties_API.Model.Users
14 15
         {
15 16
 
16 17
         }
18
+
17 19
         #endregion Constructor
18 20
 
19 21
         #region Properties
@@ -29,5 +31,67 @@ namespace UnivateProperties_API.Model.Users
29 31
         public virtual BankAccount BankAccount { get; set; }
30 32
         public virtual ICollection<Property> Properties { get; set; }
31 33
         #endregion Properties
34
+
35
+        #region Methods
36
+        public void UpdateFromDetailedOwner(DetailedOwner owner)
37
+        {
38
+            if (owner.Id == Id)
39
+            {
40
+                Name = owner.Name;
41
+                Surname = owner.Surname;
42
+                IdNumber = owner.IdNumber;
43
+                CompanyRegNumber = owner.CompanyRegNumber;
44
+                MaritalStatus = owner.MaritalStatus;
45
+                Email = owner.EmailAddress;
46
+                CellNumber = owner.CellNumber;
47
+                Telephone = owner.LandlineNumber;
48
+
49
+                if (owner.Address != null)
50
+                {
51
+                    if (Address == null)
52
+                    {
53
+                        Address = new Address()
54
+                        {
55
+                            StreetNumber = owner.Address.StreetNumber,
56
+                            Street = owner.Address.Street,
57
+                            City = owner.Address.City,
58
+                            Suburb = owner.Address.Suburb,
59
+                            Province = owner.Address.Province,
60
+                            PostalCode = owner.Address.PostalCode
61
+                        };
62
+                    }
63
+                    else
64
+                    {
65
+                        Address.StreetNumber = owner.Address.StreetNumber;
66
+                        Address.Street = owner.Address.Street;
67
+                        Address.City = owner.Address.City;
68
+                        Address.Suburb = owner.Address.Suburb;
69
+                        Address.Province = owner.Address.Province;
70
+                        Address.PostalCode = owner.Address.PostalCode;
71
+                    }
72
+
73
+                }
74
+
75
+                if (owner.BankingDetails != null)
76
+                {
77
+                    if (BankAccount == null)
78
+                    {
79
+                        BankAccount = new BankAccount()
80
+                        {
81
+                            BankId = owner.BankingDetails.BankId,
82
+                            AccountNumber = owner.BankingDetails.AccountNumber,
83
+                            AccountHolder = owner.BankingDetails.AccountHolder
84
+                        };
85
+                    }
86
+                    else
87
+                    {
88
+                        BankAccount.BankId = owner.BankingDetails.BankId;
89
+                        BankAccount.AccountNumber = owner.BankingDetails.AccountNumber;
90
+                        BankAccount.AccountHolder = owner.BankingDetails.AccountHolder;
91
+                    }
92
+                }
93
+            }
94
+        }
95
+        #endregion Methods
32 96
     }
33 97
 }

+ 14
- 2
UnivateProperties_API/Repository/Users/IndividualRepository.cs Voir le fichier

@@ -25,7 +25,7 @@ namespace UnivateProperties_API.Repository.Users
25 25
 
26 26
         public List<Individual> GetAll()
27 27
         {
28
-            foreach(var item in _dbContext.Individuals.Include("User").ToList())
28
+            foreach(var item in _dbContext.Individuals.Include("User").Include("Address").Include("BankAccount").ToList())
29 29
             {
30 30
                 var list = MyCommon.GetVisibleColumns(item);
31 31
             }
@@ -58,7 +58,7 @@ namespace UnivateProperties_API.Repository.Users
58 58
 
59 59
         public DetailedOwner GetIndividual(int id)
60 60
         {
61
-            var item = _dbContext.Individuals.FirstOrDefault(x => x.UserId == id);
61
+            var item = _dbContext.Individuals.Include("Address").Include("BankAccount").FirstOrDefault(x => x.UserId == id);
62 62
             if(item != null)
63 63
             {
64 64
                 return new DetailedOwner(item);
@@ -124,6 +124,18 @@ namespace UnivateProperties_API.Repository.Users
124 124
             Save();
125 125
         }
126 126
 
127
+        public void Update(DetailedOwner item)
128
+        {
129
+            var individual = _dbContext.Individuals.Include("Address").Include("BankAccount").FirstOrDefault(x => x.Id == item.Id);
130
+            if (individual != null)
131
+            {
132
+                individual.UpdateFromDetailedOwner(item);
133
+            }
134
+            _dbContext.Entry(individual).State = EntityState.Modified;
135
+            Save();
136
+        }
137
+
138
+
127 139
         public void Save()
128 140
         {
129 141
             _dbContext.SaveChanges();

Chargement…
Annuler
Enregistrer