Kobus Botha 5 jaren geleden
bovenliggende
commit
4c9568e541

+ 4
- 1
UnivateProperties_API/Containers/Property/PropertyDisplay.cs Bestand weergeven

@@ -32,6 +32,9 @@ namespace UnivateProperties_API.Containers.Property
32 32
         public string DisplayImage { get; set; }
33 33
         public decimal Price { get; set; }        
34 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 Bestand weergeven

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

+ 5
- 2
UnivateProperties_API/Containers/Property/PropertySearch.cs Bestand weergeven

@@ -1,4 +1,5 @@
1
-using System.Collections.Generic;
1
+using System;
2
+using System.Collections.Generic;
2 3
 
3 4
 namespace UnivateProperties_API.Containers.Property
4 5
 {
@@ -15,6 +16,8 @@ namespace UnivateProperties_API.Containers.Property
15 16
         public string Suburb { get; set; }
16 17
         public decimal MinPrice { get; set; }
17 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 Bestand weergeven

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

+ 11
- 4
UnivateProperties_API/Controllers/Properties/PropertyController.cs Bestand weergeven

@@ -1,4 +1,5 @@
1 1
 using Microsoft.AspNetCore.Mvc;
2
+using System;
2 3
 using System.Collections.Generic;
3 4
 using System.Linq;
4 5
 using System.Transactions;
@@ -65,8 +66,8 @@ namespace UnivateProperties_API.Controllers.Properties
65 66
         }
66 67
 
67 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 72
             var search = new PropertySearch()
72 73
             {
@@ -79,8 +80,14 @@ namespace UnivateProperties_API.Controllers.Properties
79 80
                 City = city,
80 81
                 Suburb = suburb,
81 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 92
             return new OkObjectResult(_Repo.GetDisplay(search));
86 93
         }

+ 5
- 5
UnivateProperties_API/Controllers/Users/IndividualController.cs Bestand weergeven

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

+ 13
- 0
UnivateProperties_API/Helpers/MyCommon.cs Bestand weergeven

@@ -120,5 +120,18 @@ namespace UnivateProperties_API.Helpers
120 120
 
121 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 Bestand weergeven

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

+ 7
- 5
UnivateProperties_API/Model/Properties/Property.cs Bestand weergeven

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

+ 64
- 0
UnivateProperties_API/Model/Users/Individual.cs Bestand weergeven

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

+ 3
- 2
UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs Bestand weergeven

@@ -19,7 +19,7 @@ namespace UnivateProperties_API.Repository.Properties
19 19
         }
20 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 24
             foreach (PropertyImage img in images)
25 25
             {
@@ -49,7 +49,8 @@ namespace UnivateProperties_API.Repository.Properties
49 49
         {
50 50
             var images = (from p in dBContext.PropertyImages
51 51
                           where p.PropertyId == PropertyId
52
-                          select p.Image).ToList();
52
+                          orderby p.IsDefault descending
53
+                          select p.Image).ToList();            
53 54
 
54 55
             List<string> formated = new List<string>();
55 56
 

+ 48
- 10
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Bestand weergeven

@@ -1,4 +1,7 @@
1
-using Microsoft.EntityFrameworkCore;
1
+#define ReturnImages
2
+//#undef ReturnImages  //Comment out to return images
3
+
4
+using Microsoft.EntityFrameworkCore;
2 5
 using Newtonsoft.Json;
3 6
 using System;
4 7
 using System.Collections.Generic;
@@ -104,20 +107,20 @@ namespace UnivateProperties_API.Repository.Properties
104 107
 
105 108
                         foreach (var val in groupFields)
106 109
                         {
107
-                            var irem = new PropertyDetail()
110
+                            var item = new PropertyDetail()
108 111
                             {
109 112
                                 Name = val.FieldName,
110 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 122
                             else
120
-                                irem.Value = val.Value;
123
+                                item.Value = val.Value;
121 124
                         }
122 125
 
123 126
                         property.DisplayData.Add(detailGroup);
@@ -329,6 +332,12 @@ namespace UnivateProperties_API.Repository.Properties
329 332
         
330 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 341
             SearchObject obj = new SearchObject()
333 342
             {
334 343
                 UserName = search.UserName,
@@ -359,6 +368,14 @@ namespace UnivateProperties_API.Repository.Properties
359 368
             else
360 369
             {
361 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 379
                 PropertyUsageType uType = PropertyUsageType.Both;
363 380
 
364 381
                 if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined" && search.PropertyUsageType.ToUpper() != "ALL")
@@ -380,7 +397,10 @@ namespace UnivateProperties_API.Repository.Properties
380 397
                 if (!string.IsNullOrEmpty(search.SalesType) && search.SalesType != "undefined" && search.SalesType.ToUpper() != "ALL")
381 398
                 {
382 399
                     if (search.SalesType.ToUpper() == "SALE")
400
+                    {
383 401
                         props = props.Where(p => p.IsSale).ToList();
402
+                        search.AvailableFrom = DateTime.MinValue; //Sales do not have an available from date. 
403
+                    }
384 404
                     else
385 405
                         props = props.Where(p => !p.IsSale).ToList();
386 406
 
@@ -453,6 +473,15 @@ namespace UnivateProperties_API.Repository.Properties
453 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 485
                 return GetDisplayDetails(props);
457 486
             }
458 487
         }        
@@ -472,9 +501,11 @@ namespace UnivateProperties_API.Repository.Properties
472 501
         {
473 502
             var properties = new List<PropertyDisplay>();
474 503
             foreach (var item in props)
475
-            {
504
+            {                
476 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 509
                     Id = item.Id,
479 510
                     ShortDescription = item.ShortDescription,
480 511
                     IsSale = item.IsSale,
@@ -516,7 +547,8 @@ namespace UnivateProperties_API.Repository.Properties
516 547
                     DateCreated = item.Created,
517 548
                     PropertyUsageType = (from p in dBContext.PropertyTypes
518 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 554
                 if (display.DisplayImage != null && !display.DisplayImage.StartsWith("data:image"))
@@ -529,6 +561,11 @@ namespace UnivateProperties_API.Repository.Properties
529 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 569
                 properties.Add(display);
533 570
             }
534 571
 
@@ -588,7 +625,8 @@ namespace UnivateProperties_API.Repository.Properties
588 625
                     Price = string.Format("R {0:n}", p.Price),
589 626
                     Publish = p.Published.ToString(),
590 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 632
                 prop.Size = (from u in dBContext.PropertyUserFields

+ 6
- 0
UnivateProperties_API/Repository/Users/AgentRepository.cs Bestand weergeven

@@ -2,6 +2,7 @@
2 2
 using System;
3 3
 using System.Collections.Generic;
4 4
 using System.Linq;
5
+using UnivateProperties_API.Containers.Users;
5 6
 using UnivateProperties_API.Context;
6 7
 using UnivateProperties_API.Model.Users;
7 8
 
@@ -38,6 +39,11 @@ namespace UnivateProperties_API.Repository.Users
38 39
         public void Insert(Agent item)
39 40
         {
40 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 47
             _dbContext.Add(item);
42 48
             Save();
43 49
         }

+ 23
- 2
UnivateProperties_API/Repository/Users/IndividualRepository.cs Bestand weergeven

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

@@ -5,7 +5,9 @@ using UnivateProperties_API.Containers.Users;
5 5
 using UnivateProperties_API.Containers.Users.Simple;
6 6
 using UnivateProperties_API.Context;
7 7
 using UnivateProperties_API.Helpers;
8
+using UnivateProperties_API.Model.Communication;
8 9
 using UnivateProperties_API.Model.Users;
10
+using UnivateProperties_API.Repository.Communication;
9 11
 
10 12
 namespace UnivateProperties_API.Repository.Users
11 13
 {
@@ -99,6 +101,8 @@ namespace UnivateProperties_API.Repository.Users
99 101
 
100 102
             Create(createUser, individual.Password, false);
101 103
 
104
+            Person p = null;
105
+            
102 106
             if (personType == PersonType.Agent)
103 107
             {
104 108
                 Agent agent = new Agent()
@@ -112,6 +116,8 @@ namespace UnivateProperties_API.Repository.Users
112 116
                     Agency = agency
113 117
                 };
114 118
                 agent.Id = NewAgentId();
119
+                agent.User.Role = Role.Agency;
120
+                p = agent;
115 121
                 _dbContext.Agents.Add(agent);
116 122
             }
117 123
             else if (personType == PersonType.Individual)
@@ -126,8 +132,32 @@ namespace UnivateProperties_API.Repository.Users
126 132
                     Telephone = individual.Telephone
127 133
                 };
128 134
                 i.Id = NewIndividualId();
135
+                i.User.Role = Role.PrivateUser;
136
+                p = i;
129 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 161
             if (save)
132 162
             {
133 163
                 Save();

Laden…
Annuleren
Opslaan