瀏覽代碼

Added fields and bank entity

master
Kobus 5 年之前
父節點
當前提交
066e9a055b
共有 43 個文件被更改,包括 306 次插入107 次删除
  1. 1
    0
      UnivateProperties_API/Containers/Property/GroupFields.cs
  2. 5
    1
      UnivateProperties_API/Containers/Property/PropertyDisplay.cs
  3. 15
    0
      UnivateProperties_API/Containers/Property/PropertyList.cs
  4. 14
    0
      UnivateProperties_API/Containers/Users/AgentDto.cs
  5. 3
    1
      UnivateProperties_API/Context/DataContext.cs
  6. 12
    4
      UnivateProperties_API/Controllers/Properties/PropertyController.cs
  7. 7
    1
      UnivateProperties_API/Controllers/Properties/PropertyFieldsController.cs
  8. 2
    2
      UnivateProperties_API/Controllers/Properties/PropertyImageController.cs
  9. 2
    2
      UnivateProperties_API/Controllers/Properties/PropertyTypeController.cs
  10. 8
    2
      UnivateProperties_API/Controllers/Properties/PropertyUserFieldController.cs
  11. 2
    2
      UnivateProperties_API/Controllers/Properties/UserDefinedFieldController.cs
  12. 2
    2
      UnivateProperties_API/Controllers/Properties/UserDefinedGroupController.cs
  13. 1
    1
      UnivateProperties_API/Controllers/Region/CityController.cs
  14. 1
    1
      UnivateProperties_API/Controllers/Region/ProvinceController.cs
  15. 1
    1
      UnivateProperties_API/Controllers/Region/SuburbController.cs
  16. 10
    4
      UnivateProperties_API/Controllers/Users/AgentController.cs
  17. 6
    2
      UnivateProperties_API/Controllers/Users/RegisterController.cs
  18. 33
    1
      UnivateProperties_API/Helpers/MyCommon.cs
  19. 16
    0
      UnivateProperties_API/Model/Misc/Address.cs
  20. 21
    0
      UnivateProperties_API/Model/ProcessFlow/ProcessFlow.cs
  21. 11
    1
      UnivateProperties_API/Model/Properties/Property.cs
  22. 1
    1
      UnivateProperties_API/Model/Properties/PropertyImage.cs
  23. 1
    1
      UnivateProperties_API/Model/Properties/PropertyType.cs
  24. 1
    1
      UnivateProperties_API/Model/Properties/PropertyUserField.cs
  25. 1
    1
      UnivateProperties_API/Model/Properties/UserDefinedField.cs
  26. 1
    1
      UnivateProperties_API/Model/Properties/UserDefinedGroup.cs
  27. 3
    1
      UnivateProperties_API/Model/Users/Agency.cs
  28. 4
    1
      UnivateProperties_API/Model/Users/Agent.cs
  29. 10
    1
      UnivateProperties_API/Model/Users/Individual.cs
  30. 1
    1
      UnivateProperties_API/Model/Users/Person.cs
  31. 17
    1
      UnivateProperties_API/Model/Users/User.cs
  32. 1
    1
      UnivateProperties_API/Repository/Properties/IPropertyImageRepository.cs
  33. 2
    1
      UnivateProperties_API/Repository/Properties/IPropertyRepository.cs
  34. 3
    1
      UnivateProperties_API/Repository/Properties/IUserDefinedGroupRepository.cs
  35. 1
    1
      UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs
  36. 44
    5
      UnivateProperties_API/Repository/Properties/PropertyRepository.cs
  37. 1
    1
      UnivateProperties_API/Repository/Properties/PropertyTypeRepository.cs
  38. 1
    1
      UnivateProperties_API/Repository/Properties/PropertyUserFieldRepository.cs
  39. 3
    3
      UnivateProperties_API/Repository/Properties/UserDefinedFieldRepository.cs
  40. 25
    3
      UnivateProperties_API/Repository/Properties/UserDefinedGroupRepository.cs
  41. 2
    5
      UnivateProperties_API/Repository/Users/AgentRepository.cs
  42. 9
    46
      UnivateProperties_API/Repository/Users/RegisterRepository.cs
  43. 1
    1
      UnivateProperties_API/Startup.cs

+ 1
- 0
UnivateProperties_API/Containers/Property/GroupFields.cs 查看文件

@@ -6,6 +6,7 @@
6 6
         public int ID { get; set; }
7 7
         public string Name { get; set; }
8 8
         public string Type { get; set; }
9
+        public string Value { get; set; }
9 10
         #endregion
10 11
     }
11 12
 }

+ 5
- 1
UnivateProperties_API/Containers/Property/PropertyDisplay.cs 查看文件

@@ -1,4 +1,6 @@
1
-namespace UnivateProperties_API.Containers.Property
1
+using System;
2
+
3
+namespace UnivateProperties_API.Containers.Property
2 4
 {
3 5
     public class PropertyDisplay
4 6
     {
@@ -27,6 +29,8 @@
27 29
         public string City { get; set; }
28 30
         public string Suburb { get; set; }
29 31
         public string DisplayImage { get; set; }
32
+        public decimal Price { get; set; }
33
+        public DateTime DateCreated { get; set; }
30 34
         #endregion 
31 35
     }
32 36
 }

+ 15
- 0
UnivateProperties_API/Containers/Property/PropertyList.cs 查看文件

@@ -0,0 +1,15 @@
1
+namespace UnivateProperties_API.Containers.Property
2
+{
3
+    public class PropertyList
4
+    {
5
+        #region Properties
6
+        public string Name { get; set; }
7
+        public int Id { get; set; }
8
+        public string Size { get; set; }
9
+        public string Price { get; set; }
10
+        public string Type { get; set; }
11
+        public string Publish { get; set; }
12
+        public string Status { get; set; }
13
+        #endregion
14
+    }
15
+}

+ 14
- 0
UnivateProperties_API/Containers/Users/AgentDto.cs 查看文件

@@ -0,0 +1,14 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+using UnivateProperties_API.Model.Users;
6
+
7
+namespace UnivateProperties_API.Containers.Users
8
+{
9
+    public class AgentDto
10
+    {
11
+        public Agent Agent { get; set; }
12
+        public string Password { get; set; }
13
+    }
14
+}

+ 3
- 1
UnivateProperties_API/Context/DataContext.cs 查看文件

@@ -1,12 +1,13 @@
1 1
 using Microsoft.EntityFrameworkCore;
2 2
 using UnivateProperties_API.Model.Communication;
3 3
 using UnivateProperties_API.Model.Users;
4
-using UnivateProperties_API.Model.Property;
4
+using UnivateProperties_API.Model.Properties;
5 5
 using UnivateProperties_API.Model.Region;
6 6
 using UnivateProperties_API.Model.Timeshare;
7 7
 using System.Linq;
8 8
 using UnivateProperties_API.Model;
9 9
 using UnivateProperties_API.Model.Bank;
10
+using UnivateProperties_API.Model.Misc;
10 11
 
11 12
 namespace UnivateProperties_API.Context
12 13
 {
@@ -22,6 +23,7 @@ namespace UnivateProperties_API.Context
22 23
         public virtual DbSet<Agent> Agents { get; set; }
23 24
         public virtual DbSet<User> Users { get; set; }
24 25
         public virtual DbSet<Individual> Individuals { get; set; }
26
+        public virtual DbSet<Address> Addresses { get; set; }
25 27
         #endregion User
26 28
 
27 29
         #region Communication

+ 12
- 4
UnivateProperties_API/Controllers/Properties/PropertyController.cs 查看文件

@@ -2,12 +2,12 @@
2 2
 using System.Collections.Generic;
3 3
 using System.Linq;
4 4
 using System.Transactions;
5
-using UnivateProperties_API.Model.Property;
5
+using UnivateProperties_API.Model.Properties;
6 6
 using UnivateProperties_API.Repository.Properties;
7 7
 
8 8
 namespace UnivateProperties_API.Controllers.Properties
9 9
 {
10
-    [Route("Property/[controller]")]
10
+    [Route("api/[controller]")]
11 11
     [ApiController]
12 12
     public class PropertyController : ControllerBase
13 13
     {
@@ -18,6 +18,7 @@ namespace UnivateProperties_API.Controllers.Properties
18 18
             _Repo = repo;
19 19
         }
20 20
 
21
+        #region Get Methods
21 22
         [HttpGet]
22 23
         public IActionResult Get()
23 24
         {
@@ -69,17 +70,24 @@ namespace UnivateProperties_API.Controllers.Properties
69 70
 
70 71
                 if (string.IsNullOrEmpty(by) || by.ToUpper() == "ALL")
71 72
                 {
72
-                    return new OkObjectResult(_Repo.Get(x => proptypeIds.Contains(x.PropertyTypeId)));
73
+                    return new OkObjectResult(_Repo.GetPropertyList(x => proptypeIds.Contains(x.PropertyTypeId)));
73 74
                 }
74 75
                 else
75 76
                 {
76
-                    return new OkObjectResult(_Repo.Get(x => proptypeIds.Contains(x.PropertyTypeId) && x.CreatedBy == by));
77
+                    return new OkObjectResult(_Repo.GetPropertyList(x => proptypeIds.Contains(x.PropertyTypeId) && x.CreatedBy == by));
77 78
                 }
78 79
             }
79 80
             else
80 81
                 return new NoContentResult();
81 82
         }
82 83
 
84
+        [HttpGet("GetEditDisplay/{id}")]
85
+        public IActionResult GetEditDisplay(int id)
86
+        {
87
+            return new OkObjectResult(_Repo.GetPropertyList(x => x.Id == id));
88
+        }
89
+        #endregion
90
+
83 91
         [HttpPost]
84 92
         public IActionResult Post([FromBody] Property property)
85 93
         {

+ 7
- 1
UnivateProperties_API/Controllers/Properties/PropertyFieldsController.cs 查看文件

@@ -3,7 +3,7 @@ using UnivateProperties_API.Repository.Properties;
3 3
 
4 4
 namespace UnivateProperties_API.Controllers.Properties
5 5
 {
6
-    [Route("Property/[controller]")]
6
+    [Route("api/[controller]")]
7 7
     [ApiController]
8 8
     public class PropertyFieldsController : ControllerBase
9 9
     {
@@ -31,6 +31,12 @@ namespace UnivateProperties_API.Controllers.Properties
31 31
         {
32 32
             return new OkObjectResult(_Repo.GetFieldListByPropType(type));
33 33
         }
34
+
35
+        [HttpGet("GetSavedValues/{propertyType}/{name}/{id}")]
36
+        public IActionResult GetSavedValues(string propertyType, string name, int id)
37
+        {
38
+            return new OkObjectResult(_Repo.GetFieldList(propertyType, name, id));
39
+        }
34 40
     }
35 41
 
36 42
 

+ 2
- 2
UnivateProperties_API/Controllers/Properties/PropertyImageController.cs 查看文件

@@ -1,11 +1,11 @@
1 1
 using System.Transactions;
2 2
 using Microsoft.AspNetCore.Mvc;
3
-using UnivateProperties_API.Model.Property;
3
+using UnivateProperties_API.Model.Properties;
4 4
 using UnivateProperties_API.Repository.Properties;
5 5
 
6 6
 namespace UnivateProperties_API.Controllers.Properties
7 7
 {
8
-    [Route("Property/[controller]")]
8
+    [Route("api/[controller]")]
9 9
     [ApiController]
10 10
     public class PropertyImageController : ControllerBase
11 11
     {

+ 2
- 2
UnivateProperties_API/Controllers/Properties/PropertyTypeController.cs 查看文件

@@ -1,11 +1,11 @@
1 1
 using System.Transactions;
2 2
 using Microsoft.AspNetCore.Mvc;
3
-using UnivateProperties_API.Model.Property;
3
+using UnivateProperties_API.Model.Properties;
4 4
 using UnivateProperties_API.Repository;
5 5
 
6 6
 namespace UnivateProperties_API.Controllers.Properties
7 7
 {
8
-    [Route("Property/[controller]")]
8
+    [Route("api/[controller]")]
9 9
     [ApiController]
10 10
     public class PropertyTypeController : ControllerBase
11 11
     {

+ 8
- 2
UnivateProperties_API/Controllers/Properties/PropertyUserFieldController.cs 查看文件

@@ -1,11 +1,11 @@
1 1
 using System.Transactions;
2 2
 using Microsoft.AspNetCore.Mvc;
3
-using UnivateProperties_API.Model.Property;
3
+using UnivateProperties_API.Model.Properties;
4 4
 using UnivateProperties_API.Repository;
5 5
 
6 6
 namespace UnivateProperties_API.Controllers.Properties
7 7
 {
8
-    [Route("Property/[controller]")]
8
+    [Route("api/[controller]")]
9 9
     [ApiController]
10 10
     public class PropertyUserFieldController : ControllerBase
11 11
     {
@@ -28,6 +28,12 @@ namespace UnivateProperties_API.Controllers.Properties
28 28
             return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
29 29
         }
30 30
 
31
+        [HttpGet("PropertyFields/{id}")]
32
+        public IActionResult GetPropertyFields(int id)
33
+        {
34
+            return new OkObjectResult(_Repo.Get(x => x.PropertyId == id));
35
+        }
36
+
31 37
         [HttpPost]
32 38
         public IActionResult Post([FromBody] PropertyUserField propertyUserField)
33 39
         {

+ 2
- 2
UnivateProperties_API/Controllers/Properties/UserDefinedFieldController.cs 查看文件

@@ -1,11 +1,11 @@
1 1
 using System.Transactions;
2 2
 using Microsoft.AspNetCore.Mvc;
3
-using UnivateProperties_API.Model.Property;
3
+using UnivateProperties_API.Model.Properties;
4 4
 using UnivateProperties_API.Repository;
5 5
 
6 6
 namespace UnivateProperties_API.Controllers.Properties
7 7
 {
8
-    [Route("Property/[controller]")]
8
+    [Route("api/[controller]")]
9 9
     [ApiController]
10 10
     public class UserDefinedFieldController : ControllerBase
11 11
     {

+ 2
- 2
UnivateProperties_API/Controllers/Properties/UserDefinedGroupController.cs 查看文件

@@ -1,11 +1,11 @@
1 1
 using System.Transactions;
2 2
 using Microsoft.AspNetCore.Mvc;
3
-using UnivateProperties_API.Model.Property;
3
+using UnivateProperties_API.Model.Properties;
4 4
 using UnivateProperties_API.Repository.Properties;
5 5
 
6 6
 namespace UnivateProperties_API.Controllers.Properties
7 7
 {
8
-    [Route("Property/[controller]")]
8
+    [Route("api/[controller]")]
9 9
     [ApiController]
10 10
     public class UserDefinedGroupController : ControllerBase
11 11
     {

+ 1
- 1
UnivateProperties_API/Controllers/Region/CityController.cs 查看文件

@@ -5,7 +5,7 @@ using UnivateProperties_API.Repository.Region;
5 5
 
6 6
 namespace UnivateProperties_API.Controllers.Region
7 7
 {
8
-    [Route("Region/[controller]")]
8
+    [Route("api/[controller]")]
9 9
     [ApiController]
10 10
     public class CityController : ControllerBase
11 11
     {

+ 1
- 1
UnivateProperties_API/Controllers/Region/ProvinceController.cs 查看文件

@@ -5,7 +5,7 @@ using UnivateProperties_API.Repository;
5 5
 
6 6
 namespace UnivateProperties_API.Controllers.Region
7 7
 {
8
-    [Route("Region/[controller]")]
8
+    [Route("api/[controller]")]
9 9
     [ApiController]
10 10
     public class ProvinceController : ControllerBase
11 11
     {

+ 1
- 1
UnivateProperties_API/Controllers/Region/SuburbController.cs 查看文件

@@ -5,7 +5,7 @@ using UnivateProperties_API.Repository.Region;
5 5
 
6 6
 namespace UnivateProperties_API.Controllers.Region
7 7
 {
8
-    [Route("Region/[controller]")]
8
+    [Route("api/[controller]")]
9 9
     [ApiController]
10 10
     public class SuburbController : ControllerBase
11 11
     {

+ 10
- 4
UnivateProperties_API/Controllers/Users/AgentController.cs 查看文件

@@ -1,8 +1,9 @@
1 1
 using System.Transactions;
2 2
 using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Containers.Users;
4
+using UnivateProperties_API.Helpers;
3 5
 using UnivateProperties_API.Model.Users;
4 6
 using UnivateProperties_API.Repository;
5
-using UnivateProperties_API.Repository.Users;
6 7
 
7 8
 namespace User_API.Controllers
8 9
 {
@@ -30,14 +31,19 @@ namespace User_API.Controllers
30 31
         }
31 32
 
32 33
         [HttpPost()]
33
-        public IActionResult Post([FromBody] Agent agent)
34
+        public IActionResult Post([FromBody] AgentDto agentDto)
34 35
         {
35 36
             using (var scope = new TransactionScope())
36 37
             {
37
-                
38
+                Agent agent = agentDto.Agent;
39
+                byte[] passwordHash, passwordSalt;
40
+                MyCommon.CreatePasswordHash(agentDto.Password, out passwordHash, out passwordSalt);
41
+
42
+                agent.User.PasswordHash = passwordHash;
43
+                agent.User.PasswordSalt = passwordSalt;
38 44
                 _Repo.Insert(agent);
39 45
                 scope.Complete();
40
-                return CreatedAtAction(nameof(Get), new { id = agent.Id }, agent);
46
+                return CreatedAtAction(nameof(Get), new { id = agentDto.Agent.Id }, agentDto.Agent);
41 47
             }
42 48
         }
43 49
 

+ 6
- 2
UnivateProperties_API/Controllers/Users/RegisterController.cs 查看文件

@@ -15,6 +15,9 @@ using UnivateProperties_API.Helpers;
15 15
 using UnivateProperties_API.Model.Users;
16 16
 using UnivateProperties_API.Repository;
17 17
 using UnivateProperties_API.Repository.Users;
18
+using System.Net.Http;
19
+using System.Net;
20
+using System.Web.Http;
18 21
 
19 22
 namespace UnivateProperties_API.Controllers.Users
20 23
 {
@@ -40,6 +43,8 @@ namespace UnivateProperties_API.Controllers.Users
40 43
         {
41 44
             var user = _Repo.Authenticate(userDto.Username, userDto.Password);
42 45
 
46
+            //HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Unauthorized, "value");
47
+
43 48
             if (user == null)
44 49
                 return BadRequest(new { message = "Username or password is incorrect" });
45 50
 
@@ -56,8 +61,7 @@ namespace UnivateProperties_API.Controllers.Users
56 61
                 SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
57 62
             };
58 63
             var token = tokenHandler.CreateToken(tokenDescriptor);
59
-            var tokenString = tokenHandler.WriteToken(token); 
60
-
64
+            var tokenString = tokenHandler.WriteToken(token);
61 65
             // return basic user info (without password) and token to store client side
62 66
             return Ok(new
63 67
             {

+ 33
- 1
UnivateProperties_API/Helpers/MyCommon.cs 查看文件

@@ -1,4 +1,5 @@
1
-using System.Text.RegularExpressions;
1
+using System;
2
+using System.Text.RegularExpressions;
2 3
 
3 4
 namespace UnivateProperties_API.Helpers
4 5
 {
@@ -14,5 +15,36 @@ namespace UnivateProperties_API.Helpers
14 15
             }
15 16
             else return false;
16 17
         }
18
+
19
+        public static void CreatePasswordHash(string password, out byte[] passwordHash, out byte[] passwordSalt)
20
+        {
21
+            if (password == null) throw new ArgumentNullException("password");
22
+            if (string.IsNullOrWhiteSpace(password)) throw new ArgumentException("Value cannot be empty or whitespace only string.", "password");
23
+
24
+            using (var hmac = new System.Security.Cryptography.HMACSHA512())
25
+            {
26
+                passwordSalt = hmac.Key;
27
+                passwordHash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
28
+            }
29
+        }
30
+
31
+        public static bool VerifyPasswordHash(string password, byte[] storedHash, byte[] storedSalt)
32
+        {
33
+            if (password == null) throw new ArgumentNullException("password");
34
+            if (string.IsNullOrWhiteSpace(password)) throw new ArgumentException("Value cannot be empty or whitespace only string.", "password");
35
+            if (storedHash.Length != 64) throw new ArgumentException("Invalid length of password hash (64 bytes expected).", "passwordHash");
36
+            if (storedSalt.Length != 128) throw new ArgumentException("Invalid length of password salt (128 bytes expected).", "passwordHash");
37
+
38
+            using (var hmac = new System.Security.Cryptography.HMACSHA512(storedSalt))
39
+            {
40
+                var computedHash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
41
+                for (int i = 0; i < computedHash.Length; i++)
42
+                {
43
+                    if (computedHash[i] != storedHash[i]) return false;
44
+                }
45
+            }
46
+
47
+            return true;
48
+        }
17 49
     }
18 50
 }

+ 16
- 0
UnivateProperties_API/Model/Misc/Address.cs 查看文件

@@ -0,0 +1,16 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+
6
+namespace UnivateProperties_API.Model.Misc
7
+{
8
+    public class Address : BaseEntity
9
+    {
10
+        public string StreetNumber { get; set; }
11
+        public string Street { get; set; }
12
+        public string Suburb { get; set; }
13
+        public string City { get; set; }
14
+        public string PostalCode { get; set; }
15
+    }
16
+}

+ 21
- 0
UnivateProperties_API/Model/ProcessFlow/ProcessFlow.cs 查看文件

@@ -0,0 +1,21 @@
1
+using UnivateProperties_API.Model.Timeshare;
2
+
3
+namespace UnivateProperties_API.Model.ProcessFlow
4
+{
5
+    public class ProcessFlow : BaseEntity
6
+    {
7
+        public int? TimeshareID { get; set; }
8
+        public int? PropertyID { get; set; }
9
+        public int StatusID { get; set; }
10
+
11
+
12
+        public virtual TimeshareWeek Timeshare { get; set; }
13
+        public virtual Properties.Property Property { get; set; }
14
+        public virtual Status Status { get; set; }
15
+
16
+        public override string ToString()
17
+        {
18
+            return $"{(TimeshareID ?? PropertyID).Value} - {Status?.Code}";
19
+        }
20
+    }
21
+}

UnivateProperties_API/Model/Property/Property.cs → UnivateProperties_API/Model/Properties/Property.cs 查看文件

@@ -2,8 +2,10 @@
2 2
 using System.ComponentModel.DataAnnotations.Schema;
3 3
 using UnivateProperties_API.Containers.Property;
4 4
 using UnivateProperties_API.Model.Region;
5
+using UnivateProperties_API.Model.Timeshare;
6
+using UnivateProperties_API.Model.Users;
5 7
 
6
-namespace UnivateProperties_API.Model.Property
8
+namespace UnivateProperties_API.Model.Properties
7 9
 {
8 10
     public class Property : BaseEntity
9 11
     {
@@ -26,11 +28,19 @@ namespace UnivateProperties_API.Model.Property
26 28
         public int CityId { get; set; }
27 29
         public int ProvinceId { get; set; }
28 30
         public bool Published { get; set; }
31
+        public int? StatusId { get; set; }
32
+        public int? OwnerId { get; set; }
33
+        public int? AgentId { get; set; }
34
+        public int? AgencyId { get; set; }
29 35
 
30 36
         public virtual PropertyType PropertyType { get; set; }
31 37
         public virtual Province Province { get; set; }
32 38
         public virtual City City { get; set; }
33 39
         public virtual Suburb Suburb { get; set; }
40
+        public virtual Status Status { get; set; }
41
+        public virtual Individual Owner { get; set; }
42
+        public virtual Agent Agent { get; set; }
43
+        public virtual Agency Agency { get; set; }
34 44
 
35 45
         public ICollection<PropertyUserField> PropertyUserFields { get; set; }
36 46
         public ICollection<PropertyImage> PropertyImages { get; set; }

UnivateProperties_API/Model/Property/PropertyImage.cs → UnivateProperties_API/Model/Properties/PropertyImage.cs 查看文件

@@ -1,6 +1,6 @@
1 1
 using System.ComponentModel.DataAnnotations.Schema;
2 2
 
3
-namespace UnivateProperties_API.Model.Property
3
+namespace UnivateProperties_API.Model.Properties
4 4
 {
5 5
     public class PropertyImage : BaseEntity
6 6
     {

UnivateProperties_API/Model/Property/PropertyType.cs → UnivateProperties_API/Model/Properties/PropertyType.cs 查看文件

@@ -1,4 +1,4 @@
1
-namespace UnivateProperties_API.Model.Property
1
+namespace UnivateProperties_API.Model.Properties
2 2
 {
3 3
     public class PropertyType : BaseEntity
4 4
     {

UnivateProperties_API/Model/Property/PropertyUserField.cs → UnivateProperties_API/Model/Properties/PropertyUserField.cs 查看文件

@@ -1,6 +1,6 @@
1 1
 using System.ComponentModel.DataAnnotations.Schema;
2 2
 
3
-namespace UnivateProperties_API.Model.Property
3
+namespace UnivateProperties_API.Model.Properties
4 4
 {
5 5
     public class PropertyUserField : BaseEntity
6 6
     {

UnivateProperties_API/Model/Property/UserDefinedField.cs → UnivateProperties_API/Model/Properties/UserDefinedField.cs 查看文件

@@ -1,6 +1,6 @@
1 1
 using System.ComponentModel.DataAnnotations.Schema;
2 2
 
3
-namespace UnivateProperties_API.Model.Property
3
+namespace UnivateProperties_API.Model.Properties
4 4
 {
5 5
     public class UserDefinedField : BaseEntity
6 6
     {

UnivateProperties_API/Model/Property/UserDefinedGroup.cs → UnivateProperties_API/Model/Properties/UserDefinedGroup.cs 查看文件

@@ -1,6 +1,6 @@
1 1
 using System.Collections.Generic;
2 2
 
3
-namespace UnivateProperties_API.Model.Property
3
+namespace UnivateProperties_API.Model.Properties
4 4
 {
5 5
     public class UserDefinedGroup : BaseEntity
6 6
     {

+ 3
- 1
UnivateProperties_API/Model/Users/Agency.cs 查看文件

@@ -1,4 +1,5 @@
1
-using System.Collections.Generic;
1
+using Castle.MicroKernel.Registration;
2
+using System.Collections.Generic;
2 3
 
3 4
 namespace UnivateProperties_API.Model.Users
4 5
 {
@@ -17,6 +18,7 @@ namespace UnivateProperties_API.Model.Users
17 18
         public string CompanyRegNumber { get; set; }
18 19
 
19 20
         public virtual ICollection<Agent> Agents { get; set; }
21
+        public virtual ICollection<Property> Properties { get; set; }
20 22
         #endregion Properties
21 23
     }
22 24
 }

+ 4
- 1
UnivateProperties_API/Model/Users/Agent.cs 查看文件

@@ -1,4 +1,5 @@
1
-using System.Collections.Generic;
1
+using Castle.MicroKernel.Registration;
2
+using System.Collections.Generic;
2 3
 using System.ComponentModel.DataAnnotations.Schema;
3 4
 
4 5
 namespace UnivateProperties_API.Model.Users
@@ -16,6 +17,8 @@ namespace UnivateProperties_API.Model.Users
16 17
         [ForeignKey("Agency")]
17 18
         public int? AgencyId { get; set; }
18 19
         public virtual Agency Agency { get; set; }
20
+
21
+        public virtual ICollection<Property> Properties { get; set; }
19 22
         #endregion Properties
20 23
     }
21 24
 }

+ 10
- 1
UnivateProperties_API/Model/Users/Individual.cs 查看文件

@@ -1,6 +1,8 @@
1 1
 using System.Collections.Generic;
2 2
 using System.ComponentModel.DataAnnotations;
3 3
 using System.ComponentModel.DataAnnotations.Schema;
4
+using UnivateProperties_API.Model.Misc;
5
+using UnivateProperties_API.Model.Properties;
4 6
 
5 7
 namespace UnivateProperties_API.Model.Users
6 8
 {
@@ -14,7 +16,14 @@ namespace UnivateProperties_API.Model.Users
14 16
         #endregion Constructor
15 17
 
16 18
         #region Properties
17
-        
19
+        public string IdNumber { get; set; }
20
+        public string CompanyRegNumber { get; set; }
21
+        public string MaritalStatus { get; set; }
22
+        public int? AddressId { get; set; }
23
+        public string IncomeTaxNumber { get; set; }
24
+        public virtual Address Address { get; set; }
25
+
26
+        public virtual ICollection<Property> Properties { get; set; }
18 27
         #endregion Properties
19 28
     }
20 29
 }

+ 1
- 1
UnivateProperties_API/Model/Users/Person.cs 查看文件

@@ -14,7 +14,7 @@ namespace UnivateProperties_API.Model.Users
14 14
 
15 15
         #region Properties
16 16
         [ForeignKey("User")]
17
-        public int UserId { get; set; }
17
+        public int? UserId { get; set; }
18 18
         public string Name { get; set; }
19 19
         public string Surname { get; set; }
20 20
         public string Email { get; set; }

+ 17
- 1
UnivateProperties_API/Model/Users/User.cs 查看文件

@@ -1,8 +1,24 @@
1
-namespace UnivateProperties_API.Model.Users
1
+using UnivateProperties_API.Helpers;
2
+
3
+namespace UnivateProperties_API.Model.Users
2 4
 {
3 5
     public class User : BaseEntity
4 6
     {
5 7
         #region Constructor
8
+        public User(string username, string password)
9
+        {
10
+            Username = username;
11
+
12
+            byte[] passwordHash, passwordSalt;
13
+            MyCommon.CreatePasswordHash(password, out passwordHash, out passwordSalt);
14
+
15
+            PasswordHash = passwordHash;
16
+            PasswordSalt = passwordSalt;
17
+        }
18
+
19
+        /// <summary>
20
+        /// Do not use when creating new user
21
+        /// </summary>
6 22
         public User()
7 23
         {
8 24
 

+ 1
- 1
UnivateProperties_API/Repository/Properties/IPropertyImageRepository.cs 查看文件

@@ -1,5 +1,5 @@
1 1
 using System.Collections.Generic;
2
-using UnivateProperties_API.Model.Property;
2
+using UnivateProperties_API.Model.Properties;
3 3
 
4 4
 namespace UnivateProperties_API.Repository.Properties
5 5
 {

+ 2
- 1
UnivateProperties_API/Repository/Properties/IPropertyRepository.cs 查看文件

@@ -1,7 +1,7 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3 3
 using UnivateProperties_API.Containers.Property;
4
-using UnivateProperties_API.Model.Property;
4
+using UnivateProperties_API.Model.Properties;
5 5
 
6 6
 namespace UnivateProperties_API.Repository.Properties
7 7
 {
@@ -13,5 +13,6 @@ namespace UnivateProperties_API.Repository.Properties
13 13
         List<PropertyDisplay> GetDisplay(string type, string propertyType, string province, string city, string suburb, string propType);
14 14
         List<PropertyDisplay> GetLatestDisplay();
15 15
         List<PropertyType> GetPropertyTypes(Func<PropertyType, bool> where);
16
+        List<PropertyList> GetPropertyList(Func<Property, bool> where);
16 17
     }
17 18
 }

+ 3
- 1
UnivateProperties_API/Repository/Properties/IUserDefinedGroupRepository.cs 查看文件

@@ -1,6 +1,6 @@
1 1
 using System.Collections.Generic;
2 2
 using UnivateProperties_API.Containers.Property;
3
-using UnivateProperties_API.Model.Property;
3
+using UnivateProperties_API.Model.Properties;
4 4
 
5 5
 namespace UnivateProperties_API.Repository.Properties
6 6
 {
@@ -8,6 +8,8 @@ namespace UnivateProperties_API.Repository.Properties
8 8
     {
9 9
         List<Group> GetFieldList(string name);
10 10
 
11
+        List<Group> GetFieldList(string propertyType, string name, int propertyID);
12
+
11 13
         List<Group> GetFieldListByPropType(string propertyType);
12 14
     }
13 15
 }

+ 1
- 1
UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs 查看文件

@@ -3,7 +3,7 @@ using System;
3 3
 using System.Collections.Generic;
4 4
 using System.Linq;
5 5
 using UnivateProperties_API.Context;
6
-using UnivateProperties_API.Model.Property;
6
+using UnivateProperties_API.Model.Properties;
7 7
 
8 8
 namespace UnivateProperties_API.Repository.Properties
9 9
 {

+ 44
- 5
UnivateProperties_API/Repository/Properties/PropertyRepository.cs 查看文件

@@ -4,7 +4,7 @@ using System.Collections.Generic;
4 4
 using System.Linq;
5 5
 using UnivateProperties_API.Containers.Property;
6 6
 using UnivateProperties_API.Context;
7
-using UnivateProperties_API.Model.Property;
7
+using UnivateProperties_API.Model.Properties;
8 8
 
9 9
 namespace UnivateProperties_API.Repository.Properties
10 10
 {
@@ -121,10 +121,10 @@ namespace UnivateProperties_API.Repository.Properties
121 121
             {
122 122
                 if (pt.UsageType == PropertyUsageType.Residential)
123 123
                 {
124
+                    string type = dBContext.PropertyTypes.Find(item.PropertyTypeId).Description;
124 125
                     if (item.PropertyUserFields.Count > 0)
125 126
                     {
126
-                        string shortDesc = "{0} {1} {2}";
127
-                        string type = dBContext.PropertyTypes.Find(item.PropertyTypeId).Description;
127
+                        string shortDesc = "{0} {1} {2}";                        
128 128
                         UserDefinedField bedrooms = dBContext.UserDefinedFields.Where(u => u.FieldName == "Bedrooms").FirstOrDefault();
129 129
                         var udValue = item.PropertyUserFields.Where(u => u.UserDefinedFieldId == bedrooms.Id).FirstOrDefault();
130 130
                         if (udValue != null)
@@ -132,6 +132,10 @@ namespace UnivateProperties_API.Repository.Properties
132 132
                         else
133 133
                             item.ShortDescription = string.Format(shortDesc, "", "", pt.Description).Trim();
134 134
                     }
135
+                    else
136
+                    {
137
+                        item.ShortDescription = type;
138
+                    }
135 139
                 }
136 140
                 else
137 141
                 {
@@ -327,8 +331,9 @@ namespace UnivateProperties_API.Repository.Properties
327 331
                             select c.Description).FirstOrDefault(),
328 332
                     Suburb = (from s in dBContext.Suburbs
329 333
                               where s.Id == item.SuburbId
330
-                              select s.Description).FirstOrDefault()
331
-
334
+                              select s.Description).FirstOrDefault(),
335
+                    Price = item.Price,
336
+                    DateCreated = item.Created
332 337
                 };
333 338
 
334 339
                 if (!string.IsNullOrEmpty(display.Area) && display.Area.EndsWith("2"))
@@ -358,5 +363,39 @@ namespace UnivateProperties_API.Repository.Properties
358 363
             List<Property> props = GetAll().OrderBy(x => x.Created).Take(3).ToList();
359 364
             return GetDisplayDetails(props);
360 365
         }
366
+
367
+        public List<PropertyList> GetPropertyList(Func<Property, bool> where)
368
+        {
369
+            var properties = Get(where);
370
+
371
+            List<PropertyList> list = new List<PropertyList>();
372
+
373
+            foreach (Property p in properties)
374
+            {
375
+                var prop = new PropertyList()
376
+                {
377
+                    Id = p.Id,
378
+                    Name = string.IsNullOrEmpty(p.PropertyName) ? p.ShortDescription : p.PropertyName,
379
+                    Price = string.Format("R {0:n}", p.Price),
380
+                    Publish = p.Published.ToString(),
381
+                    Type = dBContext.PropertyTypes.Find(p.PropertyTypeId)?.Description
382
+                };
383
+
384
+                prop.Size = (from u in dBContext.PropertyUserFields
385
+                             join f in dBContext.UserDefinedFields on u.UserDefinedFieldId equals f.Id
386
+                             where u.PropertyId == p.Id
387
+                             && f.FieldName == "Floor Size"
388
+                             select u.Value).FirstOrDefault();
389
+
390
+                if (!string.IsNullOrEmpty(prop.Size) && prop.Size.EndsWith("2"))
391
+                {
392
+                    prop.Size = prop.Size.Substring(0, prop.Size.Length - 1) + "<sup>" + prop.Size.Last() + "</sup>";
393
+                }
394
+
395
+                list.Add(prop);
396
+            }
397
+                
398
+            return list;
399
+        }
361 400
     }
362 401
 }

+ 1
- 1
UnivateProperties_API/Repository/Properties/PropertyTypeRepository.cs 查看文件

@@ -3,7 +3,7 @@ using System;
3 3
 using System.Collections.Generic;
4 4
 using System.Linq;
5 5
 using UnivateProperties_API.Context;
6
-using UnivateProperties_API.Model.Property;
6
+using UnivateProperties_API.Model.Properties;
7 7
 
8 8
 namespace UnivateProperties_API.Repository.Properties
9 9
 {

+ 1
- 1
UnivateProperties_API/Repository/Properties/PropertyUserFieldRepository.cs 查看文件

@@ -3,7 +3,7 @@ using System;
3 3
 using System.Collections.Generic;
4 4
 using System.Linq;
5 5
 using UnivateProperties_API.Context;
6
-using UnivateProperties_API.Model.Property;
6
+using UnivateProperties_API.Model.Properties;
7 7
 
8 8
 namespace UnivateProperties_API.Repository.Properties
9 9
 {

+ 3
- 3
UnivateProperties_API/Repository/Properties/UserDefinedFieldRepository.cs 查看文件

@@ -3,7 +3,7 @@ using System;
3 3
 using System.Collections.Generic;
4 4
 using System.Linq;
5 5
 using UnivateProperties_API.Context;
6
-using UnivateProperties_API.Model.Property;
6
+using UnivateProperties_API.Model.Properties;
7 7
 
8 8
 namespace UnivateProperties_API.Repository.Properties
9 9
 {
@@ -18,12 +18,12 @@ namespace UnivateProperties_API.Repository.Properties
18 18
 
19 19
         public List<UserDefinedField> Get(Func<UserDefinedField, bool> where)
20 20
         {
21
-            return dBContext.UserDefinedFields.Where(where).ToList();
21
+            return dBContext.UserDefinedFields.Where(where).OrderBy(x => x.Rank).ToList();
22 22
         }
23 23
 
24 24
         public List<UserDefinedField> GetAll()
25 25
         {
26
-            return dBContext.UserDefinedFields.ToList();
26
+            return dBContext.UserDefinedFields.OrderBy(x => x.Rank).ToList();
27 27
         }
28 28
 
29 29
         public UserDefinedField GetDetailed(Func<UserDefinedField, bool> first)

+ 25
- 3
UnivateProperties_API/Repository/Properties/UserDefinedGroupRepository.cs 查看文件

@@ -4,7 +4,7 @@ using System.Collections.Generic;
4 4
 using System.Linq;
5 5
 using UnivateProperties_API.Containers.Property;
6 6
 using UnivateProperties_API.Context;
7
-using UnivateProperties_API.Model.Property;
7
+using UnivateProperties_API.Model.Properties;
8 8
 
9 9
 namespace UnivateProperties_API.Repository.Properties
10 10
 {
@@ -19,12 +19,12 @@ namespace UnivateProperties_API.Repository.Properties
19 19
 
20 20
         public List<UserDefinedGroup> Get(Func<UserDefinedGroup, bool> where)
21 21
         {
22
-            return dBContext.UserDefinedGroups.Where(where).ToList();
22
+            return dBContext.UserDefinedGroups.Where(where).OrderBy(x => x.Rank).ToList();
23 23
         }
24 24
 
25 25
         public List<UserDefinedGroup> GetAll()
26 26
         {
27
-            return dBContext.UserDefinedGroups.ToList();
27
+            return dBContext.UserDefinedGroups.OrderBy(x => x.Rank).ToList();
28 28
         }
29 29
 
30 30
         public UserDefinedGroup GetDetailed(Func<UserDefinedGroup, bool> first)
@@ -75,6 +75,28 @@ namespace UnivateProperties_API.Repository.Properties
75 75
             return FieldGroups;
76 76
         }
77 77
 
78
+        public List<Group> GetFieldList(string propertyType, string name, int propertyID)
79
+        {
80
+            List<Group> FieldGroups = GetFieldList(name);
81
+            if (name == "Property Overview")
82
+                FieldGroups = GetFieldList(name);
83
+            else
84
+                FieldGroups = GetFieldListByPropType(propertyType);
85
+
86
+            var savedValues = dBContext.PropertyUserFields.Where(x => x.PropertyId == propertyID).ToList();
87
+            foreach (Group group in FieldGroups)
88
+            {
89
+                foreach(GroupFields field in group.Fields)
90
+                {
91
+                    var item = savedValues.Find(x => x.UserDefinedFieldId == field.ID);
92
+                    if (item != null)
93
+                        field.Value = item.Value;
94
+                }
95
+            }
96
+
97
+            return FieldGroups;
98
+        }
99
+
78 100
         public List<Group> GetFieldListByPropType(string propertyType)
79 101
         {
80 102
             List<Group> FieldGroups = new List<Group>();

+ 2
- 5
UnivateProperties_API/Repository/Users/AgentRepository.cs 查看文件

@@ -3,6 +3,7 @@ using System;
3 3
 using System.Collections.Generic;
4 4
 using System.Linq;
5 5
 using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Helpers;
6 7
 using UnivateProperties_API.Model.Users;
7 8
 
8 9
 namespace UnivateProperties_API.Repository.Users
@@ -28,6 +29,7 @@ namespace UnivateProperties_API.Repository.Users
28 29
 
29 30
         public Agent GetDetailed(Func<Agent, bool> first)
30 31
         {
32
+
31 33
             var item = _dbContext.Agents.FirstOrDefault(first);
32 34
             //AgentRepository account = new AgentRepository(_dbContext);
33 35
             //item = GetDetailedObject(item, account);
@@ -42,11 +44,6 @@ namespace UnivateProperties_API.Repository.Users
42 44
 
43 45
         public void Insert(Agent item)
44 46
         {
45
-            if (item.AgencyId != 0 && item.Agency == null)
46
-            {
47
-                AgencyRepository arepo = new AgencyRepository(_dbContext);
48
-                item.Agency = arepo.Get(a => a.Id == item.AgencyId).FirstOrDefault();
49
-            }
50 47
             _dbContext.Add(item);
51 48
             Save();
52 49
         }

+ 9
- 46
UnivateProperties_API/Repository/Users/RegisterRepository.cs 查看文件

@@ -37,11 +37,11 @@ namespace UnivateProperties_API.Repository.Users
37 37
 
38 38
             // check if username exists
39 39
             if (user == null)
40
-                return null;
40
+                throw new AppException("Username is incorrect");
41 41
 
42 42
             // check if password is correct
43
-            if (!VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt))
44
-                return null;
43
+            if (!MyCommon.VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt))
44
+                throw new AppException("Password is incorrect");
45 45
 
46 46
             // authentication successful
47 47
             return user;
@@ -57,7 +57,7 @@ namespace UnivateProperties_API.Repository.Users
57 57
                 throw new AppException("Username \"" + user.Username + "\" is already taken");
58 58
 
59 59
             byte[] passwordHash, passwordSalt;
60
-            CreatePasswordHash(password, out passwordHash, out passwordSalt);
60
+            MyCommon.CreatePasswordHash(password, out passwordHash, out passwordSalt);
61 61
 
62 62
             user.PasswordHash = passwordHash;
63 63
             user.PasswordSalt = passwordSalt;
@@ -105,18 +105,12 @@ namespace UnivateProperties_API.Repository.Users
105 105
                 throw new AppException("Individual \"" + individual.Username + "\" is already taken");
106 106
             byte[] passwordHash, passwordSalt;
107 107
 
108
-            CreatePasswordHash(individual.Password, out passwordHash, out passwordSalt);
108
+            MyCommon.CreatePasswordHash(individual.Password, out passwordHash, out passwordSalt);
109
+
110
+            User createUser = new User(individual.Username, individual.Password);
109 111
 
110
-            User createUser = new User()
111
-            {
112
-                Username = individual.Username,
113
-                PasswordHash = passwordHash,
114
-                PasswordSalt = passwordSalt
115
-            };
116 112
             Create(createUser, individual.Password, save);
117
-            Person person = new Person()
118
-            {
119
-            };
113
+
120 114
             if (personType == PersonType.Agent)
121 115
             {
122 116
                 Agent agent = new Agent()
@@ -171,7 +165,7 @@ namespace UnivateProperties_API.Repository.Users
171 165
             if (!string.IsNullOrWhiteSpace(password))
172 166
             {
173 167
                 byte[] passwordHash, passwordSalt;
174
-                CreatePasswordHash(password, out passwordHash, out passwordSalt);
168
+                MyCommon.CreatePasswordHash(password, out passwordHash, out passwordSalt);
175 169
 
176 170
                 user.PasswordHash = passwordHash;
177 171
                 user.PasswordSalt = passwordSalt;
@@ -248,36 +242,5 @@ namespace UnivateProperties_API.Repository.Users
248 242
         {
249 243
             _dbContext.SaveChanges();
250 244
         }
251
-
252
-        private static void CreatePasswordHash(string password, out byte[] passwordHash, out byte[] passwordSalt)
253
-        {
254
-            if (password == null) throw new ArgumentNullException("password");
255
-            if (string.IsNullOrWhiteSpace(password)) throw new ArgumentException("Value cannot be empty or whitespace only string.", "password");
256
-
257
-            using (var hmac = new System.Security.Cryptography.HMACSHA512())
258
-            {
259
-                passwordSalt = hmac.Key;
260
-                passwordHash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
261
-            }
262
-        }
263
-
264
-        private static bool VerifyPasswordHash(string password, byte[] storedHash, byte[] storedSalt)
265
-        {
266
-            if (password == null) throw new ArgumentNullException("password");
267
-            if (string.IsNullOrWhiteSpace(password)) throw new ArgumentException("Value cannot be empty or whitespace only string.", "password");
268
-            if (storedHash.Length != 64) throw new ArgumentException("Invalid length of password hash (64 bytes expected).", "passwordHash");
269
-            if (storedSalt.Length != 128) throw new ArgumentException("Invalid length of password salt (128 bytes expected).", "passwordHash");
270
-
271
-            using (var hmac = new System.Security.Cryptography.HMACSHA512(storedSalt))
272
-            {
273
-                var computedHash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
274
-                for (int i = 0; i < computedHash.Length; i++)
275
-                {
276
-                    if (computedHash[i] != storedHash[i]) return false;
277
-                }
278
-            }
279
-
280
-            return true;
281
-        }
282 245
     }
283 246
 }

+ 1
- 1
UnivateProperties_API/Startup.cs 查看文件

@@ -12,7 +12,7 @@ using System.Text;
12 12
 using System.Threading.Tasks;
13 13
 using UnivateProperties_API.Context;
14 14
 using UnivateProperties_API.Model.Communication;
15
-using UnivateProperties_API.Model.Property;
15
+using UnivateProperties_API.Model.Properties;
16 16
 using UnivateProperties_API.Model.Region;
17 17
 using UnivateProperties_API.Model.Timeshare;
18 18
 using UnivateProperties_API.Model.Users;

Loading…
取消
儲存