Kobus Botha 5 years ago
parent
commit
4c9568e541

+ 4
- 1
UnivateProperties_API/Containers/Property/PropertyDisplay.cs View File

32
         public string DisplayImage { get; set; }
32
         public string DisplayImage { get; set; }
33
         public decimal Price { get; set; }        
33
         public decimal Price { get; set; }        
34
         public DateTime DateCreated { get; set; }
34
         public DateTime DateCreated { get; set; }
35
-        #endregion 
35
+        public DateTime DateAvailable { get; set; }
36
+        public string Available { get; set; }
37
+        public bool HasPendingOffer { get; set; }
38
+        #endregion
36
     }
39
     }
37
 }
40
 }

+ 4
- 1
UnivateProperties_API/Containers/Property/PropertyList.cs View File

1
-namespace UnivateProperties_API.Containers.Property
1
+using System;
2
+
3
+namespace UnivateProperties_API.Containers.Property
2
 {
4
 {
3
     public class PropertyList
5
     public class PropertyList
4
     {
6
     {
5
         #region Properties
7
         #region Properties
6
         public string Name { get; set; }
8
         public string Name { get; set; }
7
         public int Id { get; set; }
9
         public int Id { get; set; }
10
+        public DateTime DateAvailable { get; set; }
8
         public string Size { get; set; }
11
         public string Size { get; set; }
9
         public string Price { get; set; }
12
         public string Price { get; set; }
10
         public string UsageType { get; set;  }
13
         public string UsageType { get; set;  }

+ 5
- 2
UnivateProperties_API/Containers/Property/PropertySearch.cs View File

1
-using System.Collections.Generic;
1
+using System;
2
+using System.Collections.Generic;
2
 
3
 
3
 namespace UnivateProperties_API.Containers.Property
4
 namespace UnivateProperties_API.Containers.Property
4
 {
5
 {
15
         public string Suburb { get; set; }
16
         public string Suburb { get; set; }
16
         public decimal MinPrice { get; set; }
17
         public decimal MinPrice { get; set; }
17
         public decimal MaxPrice { get; set; }
18
         public decimal MaxPrice { get; set; }
18
-        #endregion 
19
+        public DateTime AvailableFrom { get; set; }
20
+        public int PropertyId { get; set; }
21
+        #endregion
19
     }
22
     }
20
 }
23
 }

+ 4
- 1
UnivateProperties_API/Containers/Timeshare/Detailed/DetailedAddress.cs View File

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

+ 11
- 4
UnivateProperties_API/Controllers/Properties/PropertyController.cs View File

1
 using Microsoft.AspNetCore.Mvc;
1
 using Microsoft.AspNetCore.Mvc;
2
+using System;
2
 using System.Collections.Generic;
3
 using System.Collections.Generic;
3
 using System.Linq;
4
 using System.Linq;
4
 using System.Transactions;
5
 using System.Transactions;
65
         }
66
         }
66
 
67
 
67
         //Will need to come out. Post search not working......:(
68
         //Will need to come out. Post search not working......:(
68
-        [HttpGet("search/{userName}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}/{minPrice}/{maxPrice}")]
69
-        public IActionResult Search(string userName, string keyword, string salesType, string propertyUsageType, string propertyType, string province, string city, string suburb, decimal minPrice, decimal maxPrice)
69
+        [HttpGet("search/{userName}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}/{minPrice}/{maxPrice}/{availableFrom}/{propertyId}")]
70
+        public IActionResult Search(string userName, string keyword, string salesType, string propertyUsageType, string propertyType, string province, string city, string suburb, decimal minPrice, decimal maxPrice, string availableFrom, int propertyId)
70
         {
71
         {
71
             var search = new PropertySearch()
72
             var search = new PropertySearch()
72
             {
73
             {
79
                 City = city,
80
                 City = city,
80
                 Suburb = suburb,
81
                 Suburb = suburb,
81
                 MinPrice = minPrice,
82
                 MinPrice = minPrice,
82
-                MaxPrice = maxPrice
83
-            };
83
+                MaxPrice = maxPrice,
84
+                PropertyId = propertyId
85
+            };            
86
+
87
+            if (availableFrom == "undefined")
88
+                search.AvailableFrom = DateTime.MinValue;
89
+            else
90
+                search.AvailableFrom = DateTime.Parse(availableFrom);
84
 
91
 
85
             return new OkObjectResult(_Repo.GetDisplay(search));
92
             return new OkObjectResult(_Repo.GetDisplay(search));
86
         }
93
         }

+ 5
- 5
UnivateProperties_API/Controllers/Users/IndividualController.cs View File

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

+ 13
- 0
UnivateProperties_API/Helpers/MyCommon.cs View File

120
 
120
 
121
             return true;
121
             return true;
122
         }
122
         }
123
+
124
+        public static string CreateRandomPassword(int length = 6)
125
+        {
126
+            string validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*?_-";
127
+            Random random = new Random();
128
+
129
+            char[] chars = new char[length];
130
+            for (int i = 0; i < length; i++)
131
+            {
132
+                chars[i] = validChars[random.Next(0, validChars.Length)];
133
+            }
134
+            return new string(chars);
135
+        }
123
     }
136
     }
124
 }
137
 }

+ 1
- 0
UnivateProperties_API/Model/Misc/Address.cs View File

10
         public string Suburb { get; set; }
10
         public string Suburb { get; set; }
11
         public string City { get; set; }
11
         public string City { get; set; }
12
         public string PostalCode { get; set; }
12
         public string PostalCode { get; set; }
13
+        public string Province { get; set; }
13
         [ForeignKey("Owner")]
14
         [ForeignKey("Owner")]
14
         public int? OwnerId { get; set; }
15
         public int? OwnerId { get; set; }
15
 
16
 

+ 7
- 5
UnivateProperties_API/Model/Properties/Property.cs View File

1
-using System.Collections.Generic;
1
+using System;
2
+using System.Collections.Generic;
2
 using System.ComponentModel.DataAnnotations.Schema;
3
 using System.ComponentModel.DataAnnotations.Schema;
3
 using UnivateProperties_API.Containers.Property;
4
 using UnivateProperties_API.Containers.Property;
4
 using UnivateProperties_API.Model.ProcessFlow;
5
 using UnivateProperties_API.Model.ProcessFlow;
9
 namespace UnivateProperties_API.Model.Properties
10
 namespace UnivateProperties_API.Model.Properties
10
 {
11
 {
11
     public class Property : BaseEntity
12
     public class Property : BaseEntity
12
-    {        
13
+    {
13
         #region Properties        
14
         #region Properties        
14
-        [ForeignKey("PropertyType")]        
15
+        [ForeignKey("PropertyType")]
15
         public int PropertyTypeId { get; set; }
16
         public int PropertyTypeId { get; set; }
16
         public string PropertyName { get; set; }
17
         public string PropertyName { get; set; }
17
         public string Unit { get; set; }
18
         public string Unit { get; set; }
18
-        public decimal OperationalCosts { get; set; }           
19
+        public decimal OperationalCosts { get; set; }
19
         public decimal Price { get; set; }
20
         public decimal Price { get; set; }
20
         public string PricePer { get; set; }
21
         public string PricePer { get; set; }
21
         public bool IsSale { get; set; }
22
         public bool IsSale { get; set; }
37
         [ForeignKey("Agent")]
38
         [ForeignKey("Agent")]
38
         public int? AgentId { get; set; }
39
         public int? AgentId { get; set; }
39
         [ForeignKey("Agency")]
40
         [ForeignKey("Agency")]
40
-        public int? AgencyId { get; set; }        
41
+        public int? AgencyId { get; set; }
42
+        public DateTime DateAvailable { get; set; }
41
 
43
 
42
         public virtual PropertyType PropertyType { get; set; }
44
         public virtual PropertyType PropertyType { get; set; }
43
         public virtual Province Province { get; set; }
45
         public virtual Province Province { get; set; }

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

+ 3
- 2
UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs View File

19
         }
19
         }
20
         public List<PropertyImage> Get(Func<PropertyImage, bool> where)
20
         public List<PropertyImage> Get(Func<PropertyImage, bool> where)
21
         {
21
         {
22
-            var images = dBContext.PropertyImages.Where(where).ToList();
22
+            var images = dBContext.PropertyImages.Where(where).OrderByDescending(i => i.IsDefault).ThenBy(i => i.Id).ToList();
23
 
23
 
24
             foreach (PropertyImage img in images)
24
             foreach (PropertyImage img in images)
25
             {
25
             {
49
         {
49
         {
50
             var images = (from p in dBContext.PropertyImages
50
             var images = (from p in dBContext.PropertyImages
51
                           where p.PropertyId == PropertyId
51
                           where p.PropertyId == PropertyId
52
-                          select p.Image).ToList();
52
+                          orderby p.IsDefault descending
53
+                          select p.Image).ToList();            
53
 
54
 
54
             List<string> formated = new List<string>();
55
             List<string> formated = new List<string>();
55
 
56
 

+ 48
- 10
UnivateProperties_API/Repository/Properties/PropertyRepository.cs View File

1
-using Microsoft.EntityFrameworkCore;
1
+#define ReturnImages
2
+//#undef ReturnImages  //Comment out to return images
3
+
4
+using Microsoft.EntityFrameworkCore;
2
 using Newtonsoft.Json;
5
 using Newtonsoft.Json;
3
 using System;
6
 using System;
4
 using System.Collections.Generic;
7
 using System.Collections.Generic;
104
 
107
 
105
                         foreach (var val in groupFields)
108
                         foreach (var val in groupFields)
106
                         {
109
                         {
107
-                            var irem = new PropertyDetail()
110
+                            var item = new PropertyDetail()
108
                             {
111
                             {
109
                                 Name = val.FieldName,
112
                                 Name = val.FieldName,
110
                                 Description = val.Description
113
                                 Description = val.Description
111
                             };
114
                             };
112
 
115
 
113
-                            detailGroup.Values.Add(irem);
116
+                            detailGroup.Values.Add(item);
114
 
117
 
115
-                            if ((val.FieldName == "Erf Size" || val.FieldName == "Floor Size") && val.Value.EndsWith("2"))
118
+                            if (!string.IsNullOrEmpty(val.Value) && (val.FieldName == "Erf Size" || val.FieldName == "Floor Size") && val.Value.EndsWith("2"))
116
                             {
119
                             {
117
-                                irem.Value = val.Value.Substring(0, val.Value.Length - 1) + "<sup>" + val.Value.Last() + "</sup>";
120
+                                item.Value = val.Value.Substring(0, val.Value.Length - 1) + "<sup>" + val.Value.Last() + "</sup>";
118
                             }
121
                             }
119
                             else
122
                             else
120
-                                irem.Value = val.Value;
123
+                                item.Value = val.Value;
121
                         }
124
                         }
122
 
125
 
123
                         property.DisplayData.Add(detailGroup);
126
                         property.DisplayData.Add(detailGroup);
329
         
332
         
330
         public List<PropertyDisplay> GetDisplay(PropertySearch search)
333
         public List<PropertyDisplay> GetDisplay(PropertySearch search)
331
         {
334
         {
335
+            //return GetDisplayDetails(dBContext.Properties.ToList());
336
+
337
+            //StreamWriter SW = new StreamWriter(@"c:\temp\SearchData.txt", true);
338
+            //SW.WriteLine(string.Format("{0:yyyy-MM-dd hh:mm:ss} - {1}", DateTime.Now, JsonConvert.SerializeObject(search)));
339
+            //SW.Close();
340
+
332
             SearchObject obj = new SearchObject()
341
             SearchObject obj = new SearchObject()
333
             {
342
             {
334
                 UserName = search.UserName,
343
                 UserName = search.UserName,
359
             else
368
             else
360
             {
369
             {
361
                 List<Property> props;
370
                 List<Property> props;
371
+
372
+                //Property ID search will override other searches. 
373
+                if (search.PropertyId > 0)
374
+                {
375
+                    props = dBContext.Properties.Where(p => p.Id == search.PropertyId).ToList();
376
+                    return GetDisplayDetails(props);
377
+                }
378
+
362
                 PropertyUsageType uType = PropertyUsageType.Both;
379
                 PropertyUsageType uType = PropertyUsageType.Both;
363
 
380
 
364
                 if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined" && search.PropertyUsageType.ToUpper() != "ALL")
381
                 if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined" && search.PropertyUsageType.ToUpper() != "ALL")
380
                 if (!string.IsNullOrEmpty(search.SalesType) && search.SalesType != "undefined" && search.SalesType.ToUpper() != "ALL")
397
                 if (!string.IsNullOrEmpty(search.SalesType) && search.SalesType != "undefined" && search.SalesType.ToUpper() != "ALL")
381
                 {
398
                 {
382
                     if (search.SalesType.ToUpper() == "SALE")
399
                     if (search.SalesType.ToUpper() == "SALE")
400
+                    {
383
                         props = props.Where(p => p.IsSale).ToList();
401
                         props = props.Where(p => p.IsSale).ToList();
402
+                        search.AvailableFrom = DateTime.MinValue; //Sales do not have an available from date. 
403
+                    }
384
                     else
404
                     else
385
                         props = props.Where(p => !p.IsSale).ToList();
405
                         props = props.Where(p => !p.IsSale).ToList();
386
 
406
 
453
                     SaveLog(obj);
473
                     SaveLog(obj);
454
                 }
474
                 }
455
 
475
 
476
+                if (search.AvailableFrom != DateTime.MinValue)
477
+                {
478
+                    props = props.Where(p => p.DateAvailable.Date >= search.AvailableFrom.Date).ToList();
479
+
480
+                    obj.Property = "AvailableFrom";
481
+                    obj.Value = search.AvailableFrom.ToString();
482
+                    SaveLog(obj);
483
+                }
484
+
456
                 return GetDisplayDetails(props);
485
                 return GetDisplayDetails(props);
457
             }
486
             }
458
         }        
487
         }        
472
         {
501
         {
473
             var properties = new List<PropertyDisplay>();
502
             var properties = new List<PropertyDisplay>();
474
             foreach (var item in props)
503
             foreach (var item in props)
475
-            {
504
+            {                
476
                 PropertyDisplay display = new PropertyDisplay
505
                 PropertyDisplay display = new PropertyDisplay
477
-                {
506
+                {          
507
+                    DateAvailable = item.DateAvailable,
508
+                    Available = item.DateAvailable.Date > DateTime.Now.Date ? string.Format("Available form: {0: dd MMM yyyy}", item.DateAvailable) : "Available Now",
478
                     Id = item.Id,
509
                     Id = item.Id,
479
                     ShortDescription = item.ShortDescription,
510
                     ShortDescription = item.ShortDescription,
480
                     IsSale = item.IsSale,
511
                     IsSale = item.IsSale,
516
                     DateCreated = item.Created,
547
                     DateCreated = item.Created,
517
                     PropertyUsageType = (from p in dBContext.PropertyTypes
548
                     PropertyUsageType = (from p in dBContext.PropertyTypes
518
                                          where p.Id == item.PropertyTypeId
549
                                          where p.Id == item.PropertyTypeId
519
-                                         select p.UsageType.ToString()).FirstOrDefault()
550
+                                         select p.UsageType.ToString()).FirstOrDefault(),
551
+                    HasPendingOffer = !MayEdit(item.Id)
520
                 };
552
                 };
521
 
553
 
522
                 if (display.DisplayImage != null && !display.DisplayImage.StartsWith("data:image"))
554
                 if (display.DisplayImage != null && !display.DisplayImage.StartsWith("data:image"))
529
                     display.Area = display.Area.Substring(0, display.Area.Length - 1) + "<sup>" + display.Area.Last() + "</sup>";
561
                     display.Area = display.Area.Substring(0, display.Area.Length - 1) + "<sup>" + display.Area.Last() + "</sup>";
530
                 }
562
                 }
531
 
563
 
564
+                if (display.HasPendingOffer)
565
+                    display.Available = "Offer Pending";
566
+#if !ReturnImages
567
+                display.DisplayImage = "";
568
+#endif
532
                 properties.Add(display);
569
                 properties.Add(display);
533
             }
570
             }
534
 
571
 
588
                     Price = string.Format("R {0:n}", p.Price),
625
                     Price = string.Format("R {0:n}", p.Price),
589
                     Publish = p.Published.ToString(),
626
                     Publish = p.Published.ToString(),
590
                     Type = dBContext.PropertyTypes.Find(p.PropertyTypeId)?.Description,
627
                     Type = dBContext.PropertyTypes.Find(p.PropertyTypeId)?.Description,
591
-                    CarouselDescription = string.Format("{0}, {1} <br/>{2}", p.Suburb.Description, p.City.Description, p.AddressLine3)
628
+                    CarouselDescription = string.Format("{0}, {1} <br/>{2}", p.Suburb.Description, p.City.Description, p.AddressLine3),
629
+                    DateAvailable = p.DateAvailable
592
                 };
630
                 };
593
 
631
 
594
                 prop.Size = (from u in dBContext.PropertyUserFields
632
                 prop.Size = (from u in dBContext.PropertyUserFields

+ 6
- 0
UnivateProperties_API/Repository/Users/AgentRepository.cs View File

2
 using System;
2
 using System;
3
 using System.Collections.Generic;
3
 using System.Collections.Generic;
4
 using System.Linq;
4
 using System.Linq;
5
+using UnivateProperties_API.Containers.Users;
5
 using UnivateProperties_API.Context;
6
 using UnivateProperties_API.Context;
6
 using UnivateProperties_API.Model.Users;
7
 using UnivateProperties_API.Model.Users;
7
 
8
 
38
         public void Insert(Agent item)
39
         public void Insert(Agent item)
39
         {
40
         {
40
             item.Id = NewId();
41
             item.Id = NewId();
42
+            item.User.Role = Role.Agent;
43
+            if (_dbContext.Agents.Any(a => a.AgencyId == null))
44
+            {
45
+                item.AgencyId = 10;
46
+            }
41
             _dbContext.Add(item);
47
             _dbContext.Add(item);
42
             Save();
48
             Save();
43
         }
49
         }

+ 23
- 2
UnivateProperties_API/Repository/Users/IndividualRepository.cs View File

25
 
25
 
26
         public List<Individual> GetAll()
26
         public List<Individual> GetAll()
27
         {
27
         {
28
-            foreach(var item in _dbContext.Individuals.Include("User").ToList())
28
+            foreach(var item in _dbContext.Individuals.Include("User").Include("Address").Include("BankAccount").ToList())
29
             {
29
             {
30
                 var list = MyCommon.GetVisibleColumns(item);
30
                 var list = MyCommon.GetVisibleColumns(item);
31
             }
31
             }
58
 
58
 
59
         public DetailedOwner GetIndividual(int id)
59
         public DetailedOwner GetIndividual(int id)
60
         {
60
         {
61
-            var item = _dbContext.Individuals.FirstOrDefault(x => x.UserId == id);
61
+            var item = _dbContext.Individuals.Include("Address").Include("BankAccount").FirstOrDefault(x => x.UserId == id);
62
             if(item != null)
62
             if(item != null)
63
             {
63
             {
64
                 return new DetailedOwner(item);
64
                 return new DetailedOwner(item);
124
             Save();
124
             Save();
125
         }
125
         }
126
 
126
 
127
+        public void Update(DetailedOwner item)
128
+        {
129
+            var individual = _dbContext.Individuals.Include("Address").Include("BankAccount").FirstOrDefault(x => x.Id == item.Id);
130
+            if (individual != null)
131
+            {
132
+                individual.UpdateFromDetailedOwner(item);
133
+            }
134
+            _dbContext.Entry(individual).State = EntityState.Modified;
135
+            Save();
136
+        }
137
+
127
         public void Save()
138
         public void Save()
128
         {
139
         {
129
             _dbContext.SaveChanges();
140
             _dbContext.SaveChanges();
144
             id += 1;
155
             id += 1;
145
             return id;
156
             return id;
146
         }
157
         }
158
+
159
+        //public List<Individual> PasswordReset(Individual item)
160
+        //{
161
+        //    var individual = _dbContext.Individuals.Include("User").FirstOrDefault(x => x.Id == item.Id);
162
+        //    if (individual != null)
163
+        //    {
164
+        //        individual.User.PasswordHash = MyCommon.CreateRandomPassword(item);
165
+        //    }
166
+        //    return item;
167
+        //}
147
     }
168
     }
148
 }
169
 }

+ 30
- 0
UnivateProperties_API/Repository/Users/RegisterRepository.cs View File

5
 using UnivateProperties_API.Containers.Users.Simple;
5
 using UnivateProperties_API.Containers.Users.Simple;
6
 using UnivateProperties_API.Context;
6
 using UnivateProperties_API.Context;
7
 using UnivateProperties_API.Helpers;
7
 using UnivateProperties_API.Helpers;
8
+using UnivateProperties_API.Model.Communication;
8
 using UnivateProperties_API.Model.Users;
9
 using UnivateProperties_API.Model.Users;
10
+using UnivateProperties_API.Repository.Communication;
9
 
11
 
10
 namespace UnivateProperties_API.Repository.Users
12
 namespace UnivateProperties_API.Repository.Users
11
 {
13
 {
99
 
101
 
100
             Create(createUser, individual.Password, false);
102
             Create(createUser, individual.Password, false);
101
 
103
 
104
+            Person p = null;
105
+            
102
             if (personType == PersonType.Agent)
106
             if (personType == PersonType.Agent)
103
             {
107
             {
104
                 Agent agent = new Agent()
108
                 Agent agent = new Agent()
112
                     Agency = agency
116
                     Agency = agency
113
                 };
117
                 };
114
                 agent.Id = NewAgentId();
118
                 agent.Id = NewAgentId();
119
+                agent.User.Role = Role.Agency;
120
+                p = agent;
115
                 _dbContext.Agents.Add(agent);
121
                 _dbContext.Agents.Add(agent);
116
             }
122
             }
117
             else if (personType == PersonType.Individual)
123
             else if (personType == PersonType.Individual)
126
                     Telephone = individual.Telephone
132
                     Telephone = individual.Telephone
127
                 };
133
                 };
128
                 i.Id = NewIndividualId();
134
                 i.Id = NewIndividualId();
135
+                i.User.Role = Role.PrivateUser;
136
+                p = i;
129
                 _dbContext.Individuals.Add(i);
137
                 _dbContext.Individuals.Add(i);
138
+
139
+            }
140
+            Template template = _dbContext.Templates.FirstOrDefault(x => x.Name == "IndivRegEmail");
141
+            if (template != null && personType == PersonType.Individual)
142
+            {
143
+                    TemplateRepository templateRepository = new TemplateRepository(_dbContext);
144
+                    templateRepository.SendEmailTemplate(template, p, new List<Model.BaseEntity>() { p });
145
+            }
146
+
147
+            Template templ = _dbContext.Templates.FirstOrDefault(x => x.Name == "AgencyRegEmail");
148
+            if (templ != null)
149
+            {
150
+                TemplateRepository templateRepository = new TemplateRepository(_dbContext);
151
+                templateRepository.SendEmailTemplate(templ, p, new List<Model.BaseEntity>() { p });
130
             }
152
             }
153
+
154
+            Template temp = _dbContext.Templates.FirstOrDefault(x => x.Name == "VerificationEmail");
155
+            if (temp != null)
156
+            {
157
+                TemplateRepository templateRepository = new TemplateRepository(_dbContext);
158
+                templateRepository.SendEmailTemplate(temp, p, new List<Model.BaseEntity>() { p });
159
+            }
160
+
131
             if (save)
161
             if (save)
132
             {
162
             {
133
                 Save();
163
                 Save();

Loading…
Cancel
Save