Sfoglia il codice sorgente

Added fields and bank entity

master
Kobus 5 anni fa
parent
commit
066e9a055b
43 ha cambiato i file con 306 aggiunte e 107 eliminazioni
  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 Vedi File

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

+ 5
- 1
UnivateProperties_API/Containers/Property/PropertyDisplay.cs Vedi File

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

+ 15
- 0
UnivateProperties_API/Containers/Property/PropertyList.cs Vedi File

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 Vedi File

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 Vedi File

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

+ 12
- 4
UnivateProperties_API/Controllers/Properties/PropertyController.cs Vedi File

2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
 using System.Linq;
3
 using System.Linq;
4
 using System.Transactions;
4
 using System.Transactions;
5
-using UnivateProperties_API.Model.Property;
5
+using UnivateProperties_API.Model.Properties;
6
 using UnivateProperties_API.Repository.Properties;
6
 using UnivateProperties_API.Repository.Properties;
7
 
7
 
8
 namespace UnivateProperties_API.Controllers.Properties
8
 namespace UnivateProperties_API.Controllers.Properties
9
 {
9
 {
10
-    [Route("Property/[controller]")]
10
+    [Route("api/[controller]")]
11
     [ApiController]
11
     [ApiController]
12
     public class PropertyController : ControllerBase
12
     public class PropertyController : ControllerBase
13
     {
13
     {
18
             _Repo = repo;
18
             _Repo = repo;
19
         }
19
         }
20
 
20
 
21
+        #region Get Methods
21
         [HttpGet]
22
         [HttpGet]
22
         public IActionResult Get()
23
         public IActionResult Get()
23
         {
24
         {
69
 
70
 
70
                 if (string.IsNullOrEmpty(by) || by.ToUpper() == "ALL")
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
                 else
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
             else
80
             else
80
                 return new NoContentResult();
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
         [HttpPost]
91
         [HttpPost]
84
         public IActionResult Post([FromBody] Property property)
92
         public IActionResult Post([FromBody] Property property)
85
         {
93
         {

+ 7
- 1
UnivateProperties_API/Controllers/Properties/PropertyFieldsController.cs Vedi File

3
 
3
 
4
 namespace UnivateProperties_API.Controllers.Properties
4
 namespace UnivateProperties_API.Controllers.Properties
5
 {
5
 {
6
-    [Route("Property/[controller]")]
6
+    [Route("api/[controller]")]
7
     [ApiController]
7
     [ApiController]
8
     public class PropertyFieldsController : ControllerBase
8
     public class PropertyFieldsController : ControllerBase
9
     {
9
     {
31
         {
31
         {
32
             return new OkObjectResult(_Repo.GetFieldListByPropType(type));
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 Vedi File

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

+ 2
- 2
UnivateProperties_API/Controllers/Properties/PropertyTypeController.cs Vedi File

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

+ 8
- 2
UnivateProperties_API/Controllers/Properties/PropertyUserFieldController.cs Vedi File

1
 using System.Transactions;
1
 using System.Transactions;
2
 using Microsoft.AspNetCore.Mvc;
2
 using Microsoft.AspNetCore.Mvc;
3
-using UnivateProperties_API.Model.Property;
3
+using UnivateProperties_API.Model.Properties;
4
 using UnivateProperties_API.Repository;
4
 using UnivateProperties_API.Repository;
5
 
5
 
6
 namespace UnivateProperties_API.Controllers.Properties
6
 namespace UnivateProperties_API.Controllers.Properties
7
 {
7
 {
8
-    [Route("Property/[controller]")]
8
+    [Route("api/[controller]")]
9
     [ApiController]
9
     [ApiController]
10
     public class PropertyUserFieldController : ControllerBase
10
     public class PropertyUserFieldController : ControllerBase
11
     {
11
     {
28
             return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
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
         [HttpPost]
37
         [HttpPost]
32
         public IActionResult Post([FromBody] PropertyUserField propertyUserField)
38
         public IActionResult Post([FromBody] PropertyUserField propertyUserField)
33
         {
39
         {

+ 2
- 2
UnivateProperties_API/Controllers/Properties/UserDefinedFieldController.cs Vedi File

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

+ 2
- 2
UnivateProperties_API/Controllers/Properties/UserDefinedGroupController.cs Vedi File

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

+ 1
- 1
UnivateProperties_API/Controllers/Region/CityController.cs Vedi File

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

+ 1
- 1
UnivateProperties_API/Controllers/Region/ProvinceController.cs Vedi File

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

+ 1
- 1
UnivateProperties_API/Controllers/Region/SuburbController.cs Vedi File

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

+ 10
- 4
UnivateProperties_API/Controllers/Users/AgentController.cs Vedi File

1
 using System.Transactions;
1
 using System.Transactions;
2
 using Microsoft.AspNetCore.Mvc;
2
 using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Containers.Users;
4
+using UnivateProperties_API.Helpers;
3
 using UnivateProperties_API.Model.Users;
5
 using UnivateProperties_API.Model.Users;
4
 using UnivateProperties_API.Repository;
6
 using UnivateProperties_API.Repository;
5
-using UnivateProperties_API.Repository.Users;
6
 
7
 
7
 namespace User_API.Controllers
8
 namespace User_API.Controllers
8
 {
9
 {
30
         }
31
         }
31
 
32
 
32
         [HttpPost()]
33
         [HttpPost()]
33
-        public IActionResult Post([FromBody] Agent agent)
34
+        public IActionResult Post([FromBody] AgentDto agentDto)
34
         {
35
         {
35
             using (var scope = new TransactionScope())
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
                 _Repo.Insert(agent);
44
                 _Repo.Insert(agent);
39
                 scope.Complete();
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 Vedi File

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

+ 33
- 1
UnivateProperties_API/Helpers/MyCommon.cs Vedi File

1
-using System.Text.RegularExpressions;
1
+using System;
2
+using System.Text.RegularExpressions;
2
 
3
 
3
 namespace UnivateProperties_API.Helpers
4
 namespace UnivateProperties_API.Helpers
4
 {
5
 {
14
             }
15
             }
15
             else return false;
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 Vedi File

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 Vedi File

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 Vedi File

2
 using System.ComponentModel.DataAnnotations.Schema;
2
 using System.ComponentModel.DataAnnotations.Schema;
3
 using UnivateProperties_API.Containers.Property;
3
 using UnivateProperties_API.Containers.Property;
4
 using UnivateProperties_API.Model.Region;
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
     public class Property : BaseEntity
10
     public class Property : BaseEntity
9
     {
11
     {
26
         public int CityId { get; set; }
28
         public int CityId { get; set; }
27
         public int ProvinceId { get; set; }
29
         public int ProvinceId { get; set; }
28
         public bool Published { get; set; }
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
         public virtual PropertyType PropertyType { get; set; }
36
         public virtual PropertyType PropertyType { get; set; }
31
         public virtual Province Province { get; set; }
37
         public virtual Province Province { get; set; }
32
         public virtual City City { get; set; }
38
         public virtual City City { get; set; }
33
         public virtual Suburb Suburb { get; set; }
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
         public ICollection<PropertyUserField> PropertyUserFields { get; set; }
45
         public ICollection<PropertyUserField> PropertyUserFields { get; set; }
36
         public ICollection<PropertyImage> PropertyImages { get; set; }
46
         public ICollection<PropertyImage> PropertyImages { get; set; }

UnivateProperties_API/Model/Property/PropertyImage.cs → UnivateProperties_API/Model/Properties/PropertyImage.cs Vedi File

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

UnivateProperties_API/Model/Property/PropertyType.cs → UnivateProperties_API/Model/Properties/PropertyType.cs Vedi File

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

UnivateProperties_API/Model/Property/PropertyUserField.cs → UnivateProperties_API/Model/Properties/PropertyUserField.cs Vedi File

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

UnivateProperties_API/Model/Property/UserDefinedField.cs → UnivateProperties_API/Model/Properties/UserDefinedField.cs Vedi File

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

UnivateProperties_API/Model/Property/UserDefinedGroup.cs → UnivateProperties_API/Model/Properties/UserDefinedGroup.cs Vedi File

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

+ 3
- 1
UnivateProperties_API/Model/Users/Agency.cs Vedi File

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

+ 4
- 1
UnivateProperties_API/Model/Users/Agent.cs Vedi File

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

+ 10
- 1
UnivateProperties_API/Model/Users/Individual.cs Vedi File

1
 using System.Collections.Generic;
1
 using System.Collections.Generic;
2
 using System.ComponentModel.DataAnnotations;
2
 using System.ComponentModel.DataAnnotations;
3
 using System.ComponentModel.DataAnnotations.Schema;
3
 using System.ComponentModel.DataAnnotations.Schema;
4
+using UnivateProperties_API.Model.Misc;
5
+using UnivateProperties_API.Model.Properties;
4
 
6
 
5
 namespace UnivateProperties_API.Model.Users
7
 namespace UnivateProperties_API.Model.Users
6
 {
8
 {
14
         #endregion Constructor
16
         #endregion Constructor
15
 
17
 
16
         #region Properties
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
         #endregion Properties
27
         #endregion Properties
19
     }
28
     }
20
 }
29
 }

+ 1
- 1
UnivateProperties_API/Model/Users/Person.cs Vedi File

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

+ 17
- 1
UnivateProperties_API/Model/Users/User.cs Vedi File

1
-namespace UnivateProperties_API.Model.Users
1
+using UnivateProperties_API.Helpers;
2
+
3
+namespace UnivateProperties_API.Model.Users
2
 {
4
 {
3
     public class User : BaseEntity
5
     public class User : BaseEntity
4
     {
6
     {
5
         #region Constructor
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
         public User()
22
         public User()
7
         {
23
         {
8
 
24
 

+ 1
- 1
UnivateProperties_API/Repository/Properties/IPropertyImageRepository.cs Vedi File

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

+ 2
- 1
UnivateProperties_API/Repository/Properties/IPropertyRepository.cs Vedi File

1
 using System;
1
 using System;
2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
 using UnivateProperties_API.Containers.Property;
3
 using UnivateProperties_API.Containers.Property;
4
-using UnivateProperties_API.Model.Property;
4
+using UnivateProperties_API.Model.Properties;
5
 
5
 
6
 namespace UnivateProperties_API.Repository.Properties
6
 namespace UnivateProperties_API.Repository.Properties
7
 {
7
 {
13
         List<PropertyDisplay> GetDisplay(string type, string propertyType, string province, string city, string suburb, string propType);
13
         List<PropertyDisplay> GetDisplay(string type, string propertyType, string province, string city, string suburb, string propType);
14
         List<PropertyDisplay> GetLatestDisplay();
14
         List<PropertyDisplay> GetLatestDisplay();
15
         List<PropertyType> GetPropertyTypes(Func<PropertyType, bool> where);
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 Vedi File

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

+ 1
- 1
UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs Vedi File

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

+ 44
- 5
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Vedi File

4
 using System.Linq;
4
 using System.Linq;
5
 using UnivateProperties_API.Containers.Property;
5
 using UnivateProperties_API.Containers.Property;
6
 using UnivateProperties_API.Context;
6
 using UnivateProperties_API.Context;
7
-using UnivateProperties_API.Model.Property;
7
+using UnivateProperties_API.Model.Properties;
8
 
8
 
9
 namespace UnivateProperties_API.Repository.Properties
9
 namespace UnivateProperties_API.Repository.Properties
10
 {
10
 {
121
             {
121
             {
122
                 if (pt.UsageType == PropertyUsageType.Residential)
122
                 if (pt.UsageType == PropertyUsageType.Residential)
123
                 {
123
                 {
124
+                    string type = dBContext.PropertyTypes.Find(item.PropertyTypeId).Description;
124
                     if (item.PropertyUserFields.Count > 0)
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
                         UserDefinedField bedrooms = dBContext.UserDefinedFields.Where(u => u.FieldName == "Bedrooms").FirstOrDefault();
128
                         UserDefinedField bedrooms = dBContext.UserDefinedFields.Where(u => u.FieldName == "Bedrooms").FirstOrDefault();
129
                         var udValue = item.PropertyUserFields.Where(u => u.UserDefinedFieldId == bedrooms.Id).FirstOrDefault();
129
                         var udValue = item.PropertyUserFields.Where(u => u.UserDefinedFieldId == bedrooms.Id).FirstOrDefault();
130
                         if (udValue != null)
130
                         if (udValue != null)
132
                         else
132
                         else
133
                             item.ShortDescription = string.Format(shortDesc, "", "", pt.Description).Trim();
133
                             item.ShortDescription = string.Format(shortDesc, "", "", pt.Description).Trim();
134
                     }
134
                     }
135
+                    else
136
+                    {
137
+                        item.ShortDescription = type;
138
+                    }
135
                 }
139
                 }
136
                 else
140
                 else
137
                 {
141
                 {
327
                             select c.Description).FirstOrDefault(),
331
                             select c.Description).FirstOrDefault(),
328
                     Suburb = (from s in dBContext.Suburbs
332
                     Suburb = (from s in dBContext.Suburbs
329
                               where s.Id == item.SuburbId
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
                 if (!string.IsNullOrEmpty(display.Area) && display.Area.EndsWith("2"))
339
                 if (!string.IsNullOrEmpty(display.Area) && display.Area.EndsWith("2"))
358
             List<Property> props = GetAll().OrderBy(x => x.Created).Take(3).ToList();
363
             List<Property> props = GetAll().OrderBy(x => x.Created).Take(3).ToList();
359
             return GetDisplayDetails(props);
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 Vedi File

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

+ 1
- 1
UnivateProperties_API/Repository/Properties/PropertyUserFieldRepository.cs Vedi File

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

+ 3
- 3
UnivateProperties_API/Repository/Properties/UserDefinedFieldRepository.cs Vedi File

3
 using System.Collections.Generic;
3
 using System.Collections.Generic;
4
 using System.Linq;
4
 using System.Linq;
5
 using UnivateProperties_API.Context;
5
 using UnivateProperties_API.Context;
6
-using UnivateProperties_API.Model.Property;
6
+using UnivateProperties_API.Model.Properties;
7
 
7
 
8
 namespace UnivateProperties_API.Repository.Properties
8
 namespace UnivateProperties_API.Repository.Properties
9
 {
9
 {
18
 
18
 
19
         public List<UserDefinedField> Get(Func<UserDefinedField, bool> where)
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
         public List<UserDefinedField> GetAll()
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
         public UserDefinedField GetDetailed(Func<UserDefinedField, bool> first)
29
         public UserDefinedField GetDetailed(Func<UserDefinedField, bool> first)

+ 25
- 3
UnivateProperties_API/Repository/Properties/UserDefinedGroupRepository.cs Vedi File

4
 using System.Linq;
4
 using System.Linq;
5
 using UnivateProperties_API.Containers.Property;
5
 using UnivateProperties_API.Containers.Property;
6
 using UnivateProperties_API.Context;
6
 using UnivateProperties_API.Context;
7
-using UnivateProperties_API.Model.Property;
7
+using UnivateProperties_API.Model.Properties;
8
 
8
 
9
 namespace UnivateProperties_API.Repository.Properties
9
 namespace UnivateProperties_API.Repository.Properties
10
 {
10
 {
19
 
19
 
20
         public List<UserDefinedGroup> Get(Func<UserDefinedGroup, bool> where)
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
         public List<UserDefinedGroup> GetAll()
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
         public UserDefinedGroup GetDetailed(Func<UserDefinedGroup, bool> first)
30
         public UserDefinedGroup GetDetailed(Func<UserDefinedGroup, bool> first)
75
             return FieldGroups;
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
         public List<Group> GetFieldListByPropType(string propertyType)
100
         public List<Group> GetFieldListByPropType(string propertyType)
79
         {
101
         {
80
             List<Group> FieldGroups = new List<Group>();
102
             List<Group> FieldGroups = new List<Group>();

+ 2
- 5
UnivateProperties_API/Repository/Users/AgentRepository.cs Vedi File

3
 using System.Collections.Generic;
3
 using System.Collections.Generic;
4
 using System.Linq;
4
 using System.Linq;
5
 using UnivateProperties_API.Context;
5
 using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Helpers;
6
 using UnivateProperties_API.Model.Users;
7
 using UnivateProperties_API.Model.Users;
7
 
8
 
8
 namespace UnivateProperties_API.Repository.Users
9
 namespace UnivateProperties_API.Repository.Users
28
 
29
 
29
         public Agent GetDetailed(Func<Agent, bool> first)
30
         public Agent GetDetailed(Func<Agent, bool> first)
30
         {
31
         {
32
+
31
             var item = _dbContext.Agents.FirstOrDefault(first);
33
             var item = _dbContext.Agents.FirstOrDefault(first);
32
             //AgentRepository account = new AgentRepository(_dbContext);
34
             //AgentRepository account = new AgentRepository(_dbContext);
33
             //item = GetDetailedObject(item, account);
35
             //item = GetDetailedObject(item, account);
42
 
44
 
43
         public void Insert(Agent item)
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
             _dbContext.Add(item);
47
             _dbContext.Add(item);
51
             Save();
48
             Save();
52
         }
49
         }

+ 9
- 46
UnivateProperties_API/Repository/Users/RegisterRepository.cs Vedi File

37
 
37
 
38
             // check if username exists
38
             // check if username exists
39
             if (user == null)
39
             if (user == null)
40
-                return null;
40
+                throw new AppException("Username is incorrect");
41
 
41
 
42
             // check if password is correct
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
             // authentication successful
46
             // authentication successful
47
             return user;
47
             return user;
57
                 throw new AppException("Username \"" + user.Username + "\" is already taken");
57
                 throw new AppException("Username \"" + user.Username + "\" is already taken");
58
 
58
 
59
             byte[] passwordHash, passwordSalt;
59
             byte[] passwordHash, passwordSalt;
60
-            CreatePasswordHash(password, out passwordHash, out passwordSalt);
60
+            MyCommon.CreatePasswordHash(password, out passwordHash, out passwordSalt);
61
 
61
 
62
             user.PasswordHash = passwordHash;
62
             user.PasswordHash = passwordHash;
63
             user.PasswordSalt = passwordSalt;
63
             user.PasswordSalt = passwordSalt;
105
                 throw new AppException("Individual \"" + individual.Username + "\" is already taken");
105
                 throw new AppException("Individual \"" + individual.Username + "\" is already taken");
106
             byte[] passwordHash, passwordSalt;
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
             Create(createUser, individual.Password, save);
112
             Create(createUser, individual.Password, save);
117
-            Person person = new Person()
118
-            {
119
-            };
113
+
120
             if (personType == PersonType.Agent)
114
             if (personType == PersonType.Agent)
121
             {
115
             {
122
                 Agent agent = new Agent()
116
                 Agent agent = new Agent()
171
             if (!string.IsNullOrWhiteSpace(password))
165
             if (!string.IsNullOrWhiteSpace(password))
172
             {
166
             {
173
                 byte[] passwordHash, passwordSalt;
167
                 byte[] passwordHash, passwordSalt;
174
-                CreatePasswordHash(password, out passwordHash, out passwordSalt);
168
+                MyCommon.CreatePasswordHash(password, out passwordHash, out passwordSalt);
175
 
169
 
176
                 user.PasswordHash = passwordHash;
170
                 user.PasswordHash = passwordHash;
177
                 user.PasswordSalt = passwordSalt;
171
                 user.PasswordSalt = passwordSalt;
248
         {
242
         {
249
             _dbContext.SaveChanges();
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 Vedi File

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

Loading…
Annulla
Salva