ソースを参照

commit merge

master
Kobus 5年前
コミット
c4d4ec2d50

+ 2
- 1
UnivateProperties_API/Containers/Property/PropertyDisplay.cs ファイルの表示

@@ -6,6 +6,7 @@ namespace UnivateProperties_API.Containers.Property
6 6
     {
7 7
         #region Properties
8 8
         public int Id { get; set; }
9
+        public string PropertyUsageType { get; set; }
9 10
         public string ShortDescription { get; set; }
10 11
         public bool IsSale { get; set; }
11 12
         public string DisplayPrice { get; set; }
@@ -29,7 +30,7 @@ namespace UnivateProperties_API.Containers.Property
29 30
         public string City { get; set; }
30 31
         public string Suburb { get; set; }
31 32
         public string DisplayImage { get; set; }
32
-        public decimal Price { get; set; }
33
+        public decimal Price { get; set; }        
33 34
         public DateTime DateCreated { get; set; }
34 35
         #endregion 
35 36
     }

+ 2
- 0
UnivateProperties_API/Containers/Property/PropertySearch.cs ファイルの表示

@@ -11,6 +11,8 @@
11 11
         public string Province { get; set; }
12 12
         public string City { get; set; }
13 13
         public string Suburb { get; set; }
14
+        public decimal MinPrice { get; set; }
15
+        public decimal MaxPrice { get; set; }
14 16
         #endregion 
15 17
     }
16 18
 }

+ 2
- 1
UnivateProperties_API/Containers/Timeshare/TimeshareSearch.cs ファイルの表示

@@ -1,8 +1,9 @@
1 1
 namespace UnivateProperties_API.Containers.Timeshare
2 2
 {
3
-    public class TimeshareSearch
3
+    public class SearchObject
4 4
     {
5 5
         public string UserName { get; set; }
6
+        public string Type { get; set; }
6 7
         public string Property { get; set; }
7 8
         public string Value { get; set; }
8 9
     }

+ 2
- 1
UnivateProperties_API/Containers/Timeshare/TimeshareSearchDisplay.cs ファイルの表示

@@ -2,9 +2,10 @@
2 2
 
3 3
 namespace UnivateProperties_API.Containers.Timeshare
4 4
 {
5
-    public class TimeshareSearchDisplay
5
+    public class SearchDisplay
6 6
     {
7 7
         public string UserName { get; set; }
8
+        public string Type { get; set; }
8 9
         public DateTime Date { get; set; }
9 10
         public string Property { get; set; }
10 11
         public string Value { get; set; }

+ 6
- 10
UnivateProperties_API/Controllers/Logging/SearchLogController.cs ファイルの表示

@@ -17,23 +17,19 @@ namespace UnivateProperties_API.Controllers.Logging
17 17
         }
18 18
       
19 19
 
20
-        [HttpGet("{type}")]
21
-        public IActionResult Get(string type)
22
-        {
23
-            if (type.ToUpper() == "PROPERTY")
24
-                return new OkObjectResult(_Repo.GetPropertySearches());
25
-            else if (type.ToUpper() == "TIMESHARE")
26
-                return new OkObjectResult(_Repo.GetTimeshareSearches());
27
-            else return NoContent();
20
+        [HttpGet]
21
+        public IActionResult Get()
22
+        {      
23
+            return new OkObjectResult(_Repo.GetSearches());
28 24
         }
29 25
         
30 26
 
31 27
         [HttpPost]
32
-        public IActionResult Post([FromBody] TimeshareSearch item)
28
+        public IActionResult Post([FromBody] SearchObject item)
33 29
         {
34 30
             using (var scope = new TransactionScope())
35 31
             {
36
-                _Repo.SaveTimeshareSearch(item);
32
+                _Repo.SaveSearch(item);
37 33
                 scope.Complete();
38 34
                 return new OkObjectResult(item);
39 35
             }

+ 6
- 4
UnivateProperties_API/Controllers/Properties/PropertyController.cs ファイルの表示

@@ -78,15 +78,15 @@ namespace UnivateProperties_API.Controllers.Properties
78 78
         }
79 79
         #endregion
80 80
 
81
-        [HttpPost("search")]
81
+        [HttpGet("search")]
82 82
         public IActionResult Search([FromBody] PropertySearch search)
83 83
         {
84 84
             return new OkObjectResult(_Repo.GetDisplay(search));
85 85
         }
86 86
 
87 87
         //Will need to come out. Post search not working......:(
88
-        [HttpGet("search/{userName}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}")]
89
-        public IActionResult Search(string userName, string keyword, string salesType, string propertyUsageType, string propertyType, string province, string city, string suburb)
88
+        [HttpGet("search/{userName}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}/{minPrice}/{maxPrice}")]
89
+        public IActionResult Search(string userName, string keyword, string salesType, string propertyUsageType, string propertyType, string province, string city, string suburb, decimal minPrice, decimal maxPrice)
90 90
         {
91 91
             var search = new PropertySearch()
92 92
             {
@@ -97,7 +97,9 @@ namespace UnivateProperties_API.Controllers.Properties
97 97
                 PropertyType = propertyType,
98 98
                 Province = province,
99 99
                 City = city,
100
-                Suburb = suburb
100
+                Suburb = suburb,
101
+                MinPrice = minPrice,
102
+                MaxPrice = maxPrice
101 103
             };
102 104
 
103 105
             return new OkObjectResult(_Repo.GetDisplay(search));

+ 4
- 1
UnivateProperties_API/Controllers/Users/RegisterController.cs ファイルの表示

@@ -40,6 +40,8 @@ namespace UnivateProperties_API.Controllers.Users
40 40
             if (user == null)
41 41
                 return BadRequest(new { message = "Username or password is incorrect" });
42 42
 
43
+            var name = _Repo.UserDetails(user.Id);
44
+
43 45
             var tokenHandler = new JwtSecurityTokenHandler();
44 46
             var key = Encoding.ASCII.GetBytes(_appSettings.Secret);
45 47
             var tokenDescriptor = new SecurityTokenDescriptor
@@ -59,7 +61,8 @@ namespace UnivateProperties_API.Controllers.Users
59 61
             {
60 62
                 user.Id,
61 63
                 user.Username,
62
-                Token = tokenString
64
+                Token = tokenString,
65
+                name
63 66
             });
64 67
         }
65 68
 

+ 1028
- 0
UnivateProperties_API/Migrations/20190912055827_SearchLogStuff.Designer.cs
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 40
- 0
UnivateProperties_API/Migrations/20190912055827_SearchLogStuff.cs ファイルの表示

@@ -0,0 +1,40 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class SearchLogStuff : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+            migrationBuilder.DropColumn(
10
+                name: "UserID",
11
+                table: "SearchLogs");
12
+
13
+            migrationBuilder.DropColumn(
14
+                name: "GCRecord",
15
+                table: "Properties");
16
+
17
+            migrationBuilder.AddColumn<string>(
18
+                name: "Type",
19
+                table: "SearchLogs",
20
+                nullable: true);
21
+        }
22
+
23
+        protected override void Down(MigrationBuilder migrationBuilder)
24
+        {
25
+            migrationBuilder.DropColumn(
26
+                name: "Type",
27
+                table: "SearchLogs");
28
+
29
+            migrationBuilder.AddColumn<int>(
30
+                name: "UserID",
31
+                table: "SearchLogs",
32
+                nullable: true);
33
+
34
+            migrationBuilder.AddColumn<int>(
35
+                name: "GCRecord",
36
+                table: "Properties",
37
+                nullable: true);
38
+        }
39
+    }
40
+}

+ 2
- 3
UnivateProperties_API/Repository/Logging/ISearchLogRepository.cs ファイルの表示

@@ -7,8 +7,7 @@ namespace UnivateProperties_API.Repository.Logging
7 7
 {
8 8
     public interface ISearchLogRepository: IRepository<SearchLog>
9 9
     {
10
-        List<TimeshareSearchDisplay> GetTimeshareSearches();
11
-        List<PropertySearchDispaly> GetPropertySearches();
12
-        void SaveTimeshareSearch(TimeshareSearch item);
10
+        List<SearchDisplay> GetSearches();        
11
+        void SaveSearch(SearchObject item);
13 12
     }
14 13
 }

+ 15
- 38
UnivateProperties_API/Repository/Logging/SearchLogRepository.cs ファイルの表示

@@ -39,44 +39,21 @@ namespace UnivateProperties_API.Repository.Logging
39 39
         public List<SearchLog> GetDetailedAll()
40 40
         {
41 41
             return _dbContext.SearchLogs.ToList();
42
-        }
42
+        }        
43 43
 
44
-        public List<PropertySearchDispaly> GetPropertySearches()
44
+        public List<SearchDisplay> GetSearches()
45 45
         {
46
-            var list = new List<PropertySearchDispaly>();
47
-            var logs = Get(x => x.Type == "Property");
46
+            var list = new List<SearchDisplay>();
47
+            var logs = GetAll();
48 48
             foreach (SearchLog log in logs)
49 49
             {
50
-                var propSearch = JsonConvert.DeserializeObject<PropertySearch>(log.Search);
51
-                list.Add(new PropertySearchDispaly()
52
-                {
50
+                var searchObject = JsonConvert.DeserializeObject<SearchObject>(log.Search);
51
+                list.Add(new SearchDisplay() {
53 52
                     Date = log.Created,
54
-                    UserName = propSearch.UserName,
55
-                    Keyword = propSearch.Keyword,
56
-                    SalesType = propSearch.SalesType,
57
-                    PropertyUsageType = propSearch.PropertyUsageType,
58
-                    PropertyType = propSearch.PropertyType,
59
-                    Province = propSearch.Province,
60
-                    City = propSearch.City,
61
-                    Suburb = propSearch.Suburb
62
-                });
63
-                Debug.WriteLine(propSearch);
64
-            }
65
-            return list;            
66
-        }
67
-
68
-        public List<TimeshareSearchDisplay> GetTimeshareSearches()
69
-        {
70
-            var list = new List<TimeshareSearchDisplay>();
71
-            var logs = Get(x => x.Type == "Timeshare");
72
-            foreach (SearchLog log in logs)
73
-            {
74
-                var timeshareSearch = JsonConvert.DeserializeObject<TimeshareSearch>(log.Search);
75
-                list.Add(new TimeshareSearchDisplay() {
76
-                    Date = log.Created,
77
-                    UserName = timeshareSearch.UserName,
78
-                    Property = timeshareSearch.Property,
79
-                    Value = timeshareSearch.Value
53
+                    Type = log.Type,
54
+                    UserName = searchObject.UserName,
55
+                    Property = searchObject.Property,
56
+                    Value = searchObject.Value
80 57
                 });
81 58
             }
82 59
             return list;
@@ -127,14 +104,14 @@ namespace UnivateProperties_API.Repository.Logging
127 104
             _dbContext.SaveChanges();
128 105
         }
129 106
 
130
-        public void SaveTimeshareSearch(TimeshareSearch item)
131
-        {
107
+        public void SaveSearch(SearchObject item)
108
+        {            
132 109
             var searchLog = new SearchLog
133
-            {
134
-                Type = "Timeshare",
110
+            { 
111
+                Type = item.Type,
135 112
                 Search = JsonConvert.SerializeObject(item)
136 113
             };
137
-            _dbContext.SearchLogs.Remove(searchLog);
114
+            _dbContext.SearchLogs.Add(searchLog);
138 115
             Save();
139 116
         }
140 117
 

+ 72
- 9
UnivateProperties_API/Repository/Properties/PropertyRepository.cs ファイルの表示

@@ -4,7 +4,9 @@ using System;
4 4
 using System.Collections.Generic;
5 5
 using System.Linq;
6 6
 using UnivateProperties_API.Containers.Property;
7
+using UnivateProperties_API.Containers.Timeshare;
7 8
 using UnivateProperties_API.Context;
9
+using UnivateProperties_API.Model.Logging;
8 10
 using UnivateProperties_API.Model.Properties;
9 11
 
10 12
 namespace UnivateProperties_API.Repository.Properties
@@ -155,8 +157,14 @@ namespace UnivateProperties_API.Repository.Properties
155 157
 
156 158
             if (images != null)
157 159
             {
160
+                var lastID = (from p in dBContext.PropertyImages
161
+                              orderby p.Id descending
162
+                              select p.Id).FirstOrDefault();
163
+
158 164
                 foreach (PropertyImage image in images)
159 165
                 {
166
+                    lastID++;
167
+                    image.Id = lastID;
160 168
                     image.PropertyId = item.Id;
161 169
                     dBContext.PropertyImages.Add(image);
162 170
                     Save();
@@ -241,16 +249,14 @@ namespace UnivateProperties_API.Repository.Properties
241 249
 
242 250
             return GetDisplayDetails(props);
243 251
         }
244
-
252
+        
245 253
         public List<PropertyDisplay> GetDisplay(PropertySearch search)
246 254
         {
247
-            //Save to Log
248
-            dBContext.SearchLogs.Add(new Model.Logging.SearchLog()
255
+            SearchObject obj = new SearchObject()
249 256
             {
250
-                Type = "Property",
251
-                Search = JsonConvert.SerializeObject(search)
252
-            });
253
-            Save();
257
+                UserName = search.UserName,
258
+                Type = "Property"
259
+            };
254 260
 
255 261
             if (!string.IsNullOrEmpty(search.Keyword) && search.Keyword.ToUpper() != "ALL")
256 262
             {
@@ -267,6 +273,9 @@ namespace UnivateProperties_API.Repository.Properties
267 273
                                         || EF.Functions.Like(s.Description.ToLower(), $"%{keyword}%")
268 274
                                         || EF.Functions.Like(pt.Description.ToLower(), $"%{keyword}%")
269 275
                                         select p).ToList();
276
+                obj.Property = "Keyword";
277
+                obj.Value = search.Keyword;
278
+                SaveLog(obj);
270 279
 
271 280
                 return GetDisplayDetails(props);
272 281
             }
@@ -275,7 +284,7 @@ namespace UnivateProperties_API.Repository.Properties
275 284
                 List<Property> props;
276 285
                 PropertyUsageType uType = PropertyUsageType.Both;
277 286
 
278
-                if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined")
287
+                if (!string.IsNullOrEmpty(search.PropertyUsageType) && search.PropertyUsageType != "undefined" && search.PropertyUsageType.ToUpper() != "ALL")
279 288
                 {
280 289
                     if (search.PropertyUsageType.ToUpper() == "COMMERCIAL")
281 290
                         uType = PropertyUsageType.Commercial;
@@ -287,12 +296,20 @@ namespace UnivateProperties_API.Repository.Properties
287 296
                          where pt.UsageType == uType
288 297
                          select p).ToList();
289 298
 
299
+                obj.Property = "PropertyUsageType";
300
+                obj.Value = search.PropertyUsageType;
301
+                SaveLog(obj);
302
+
290 303
                 if (!string.IsNullOrEmpty(search.SalesType) && search.SalesType != "undefined" && search.SalesType.ToUpper() != "ALL")
291 304
                 {
292 305
                     if (search.SalesType.ToUpper() == "SALE")
293 306
                         props = props.Where(p => p.IsSale).ToList();
294 307
                     else
295 308
                         props = props.Where(p => !p.IsSale).ToList();
309
+
310
+                    obj.Property = "SalesType";
311
+                    obj.Value = search.SalesType;
312
+                    SaveLog(obj);
296 313
                 }
297 314
 
298 315
                 if (!string.IsNullOrEmpty(search.Province) && search.Province != "undefined" && search.Province.ToUpper() != "ALL")
@@ -301,6 +318,10 @@ namespace UnivateProperties_API.Repository.Properties
301 318
                              join pp in dBContext.Provinces on p.ProvinceId equals pp.Id
302 319
                              where pp.Description.ToUpper() == search.Province.ToUpper()
303 320
                              select p).ToList();
321
+
322
+                    obj.Property = "Province";
323
+                    obj.Value = search.Province;
324
+                    SaveLog(obj);
304 325
                 }
305 326
 
306 327
                 if (!string.IsNullOrEmpty(search.City) && search.City != "undefined" && search.City.ToUpper() != "ALL")
@@ -309,6 +330,10 @@ namespace UnivateProperties_API.Repository.Properties
309 330
                              join c in dBContext.Cities on p.CityId equals c.Id
310 331
                              where c.Description.ToUpper() == search.City.ToUpper()
311 332
                              select p).ToList();
333
+
334
+                    obj.Property = "City";
335
+                    obj.Value = search.City;
336
+                    SaveLog(obj);
312 337
                 }
313 338
 
314 339
                 if (!string.IsNullOrEmpty(search.Suburb) && search.Suburb != "undefined" && search.Suburb.ToUpper() != "ALL")
@@ -317,6 +342,10 @@ namespace UnivateProperties_API.Repository.Properties
317 342
                              join s in dBContext.Suburbs on p.SuburbId equals s.Id
318 343
                              where s.Description.ToUpper() == search.Suburb.ToUpper()
319 344
                              select p).ToList();
345
+
346
+                    obj.Property = "Suburb";
347
+                    obj.Value = search.Suburb;
348
+                    SaveLog(obj);
320 349
                 }
321 350
                 if (!string.IsNullOrEmpty(search.PropertyType) && search.PropertyType != "Undefined" && search.PropertyType.ToUpper() != "ALL")
322 351
                 {
@@ -325,12 +354,43 @@ namespace UnivateProperties_API.Repository.Properties
325 354
                     {
326 355
                         props = props.Where(p => p.PropertyTypeId == pType.Id).ToList();
327 356
                     }
357
+
358
+                    obj.Property = "PropertyType";
359
+                    obj.Value = search.PropertyType;
360
+                    SaveLog(obj);
361
+                }
362
+                if (search.MinPrice > 0)
363
+                {
364
+                    props = props.Where(p => p.Price >= search.MinPrice).ToList();
365
+
366
+                    obj.Property = "MinPrice";
367
+                    obj.Value = search.MinPrice.ToString();
368
+                    SaveLog(obj);
369
+                }
370
+                if (search.MaxPrice > 0)
371
+                {
372
+                    props = props.Where(p => p.Price <= search.MaxPrice).ToList();
373
+
374
+                    obj.Property = "MaxPrice";
375
+                    obj.Value = search.MaxPrice.ToString();
376
+                    SaveLog(obj);
328 377
                 }
329 378
 
330 379
                 return GetDisplayDetails(props);
331 380
             }
332 381
         }        
333 382
 
383
+        private void SaveLog(SearchObject item)
384
+        {
385
+            var searchLog = new SearchLog
386
+            {
387
+                Type = item.Type,
388
+                Search = JsonConvert.SerializeObject(item)
389
+            };
390
+            dBContext.SearchLogs.Add(searchLog);
391
+            Save();
392
+        }
393
+
334 394
         private List<PropertyDisplay> GetDisplayDetails(List<Property> props)
335 395
         {
336 396
             var properties = new List<PropertyDisplay>();
@@ -376,7 +436,10 @@ namespace UnivateProperties_API.Repository.Properties
376 436
                               where s.Id == item.SuburbId
377 437
                               select s.Description).FirstOrDefault(),
378 438
                     Price = item.Price,
379
-                    DateCreated = item.Created
439
+                    DateCreated = item.Created,
440
+                    PropertyUsageType = (from p in dBContext.PropertyTypes
441
+                                         where p.Id == item.PropertyTypeId
442
+                                         select p.UsageType.ToString()).FirstOrDefault()
380 443
                 };
381 444
 
382 445
                 if (!string.IsNullOrEmpty(display.Area) && display.Area.EndsWith("2"))

+ 9
- 1
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs ファイルの表示

@@ -116,7 +116,15 @@ namespace UnivateProperties_API.Repository.Timeshare
116 116
         public void Insert(TimeshareWeek item)
117 117
         {
118 118
             item = GetDetailedWeek(item);
119
-            if(item.Status == null)
119
+            item.Id = _dbContext.Weeks.Max(x => x.Id) + 1;
120
+            if (item.Owner != null && item.Owner.Id == 0)
121
+            {
122
+                item.Owner.Id = _dbContext.Individuals.Max(x => x.Id) + 1;
123
+            }
124
+            // Set starting Status of A1
125
+            StatusRepository repo = new StatusRepository(_dbContext);
126
+            item.Status = repo.GetDetailed(s => s.Code == "A1");
127
+            if(item.Status != null)
120 128
             {
121 129
                 //Create initial
122 130
                 item.Status = new Status()

+ 1
- 0
UnivateProperties_API/Repository/Users/IRegisterRepository.cs ファイルの表示

@@ -20,5 +20,6 @@ namespace UnivateProperties_API.Repository.Users
20 20
         void Delete(int id);
21 21
         void DeleteAgency(int id);
22 22
         void DeleteIndividual(int id);
23
+        string UserDetails(int userId);
23 24
     }
24 25
 }

+ 22
- 0
UnivateProperties_API/Repository/Users/RegisterRepository.cs ファイルの表示

@@ -274,5 +274,27 @@ namespace UnivateProperties_API.Repository.Users
274 274
             id += 1;
275 275
             return id;
276 276
         }
277
+
278
+        public string UserDetails(int userId)
279
+        {
280
+            var individual = _dbContext.Individuals.Where(i => i.UserId == userId).FirstOrDefault();
281
+
282
+            if (individual == null)
283
+            {
284
+                var agent = _dbContext.Agents.Where(i => i.UserId == userId).FirstOrDefault();
285
+                if (agent != null)
286
+                {
287
+                    return agent.Name + " " + agent.Surname;
288
+                }
289
+                else
290
+                {
291
+                    return "";
292
+                }
293
+            }
294
+            else
295
+            {
296
+                return individual.Name + " " + individual.Surname;
297
+            }
298
+        }
277 299
     }
278 300
 }

読み込み中…
キャンセル
保存