Browse Source

Search log API changes

master
George Williams 5 years ago
parent
commit
b71e5e614c

+ 1
- 1
UnivateProperties_API/Containers/Property/PropertySearch.cs View File

3
     public class PropertySearch
3
     public class PropertySearch
4
     {
4
     {
5
         #region Properties 
5
         #region Properties 
6
-        public int UserID { get; set; }
6
+        public string UserName { get; set; }
7
         public string Keyword { get; set; }
7
         public string Keyword { get; set; }
8
         public string SalesType { get; set; }
8
         public string SalesType { get; set; }
9
         public string PropertyUsageType { get; set; }
9
         public string PropertyUsageType { get; set; }

+ 19
- 0
UnivateProperties_API/Containers/Property/PropertySearchDispaly.cs View File

1
+using System;
2
+
3
+namespace UnivateProperties_API.Containers.Property
4
+{
5
+    public class PropertySearchDispaly
6
+    {
7
+        #region Properties 
8
+        public string UserName { get; set; }
9
+        public DateTime Date { get; set; }
10
+        public string Keyword { get; set; }
11
+        public string SalesType { get; set; }
12
+        public string PropertyUsageType { get; set; }
13
+        public string PropertyType { get; set; }
14
+        public string Province { get; set; }
15
+        public string City { get; set; }
16
+        public string Suburb { get; set; }
17
+        #endregion 
18
+    }
19
+}

+ 9
- 0
UnivateProperties_API/Containers/Timeshare/TimeshareSearch.cs View File

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

+ 12
- 0
UnivateProperties_API/Containers/Timeshare/TimeshareSearchDisplay.cs View File

1
+using System;
2
+
3
+namespace UnivateProperties_API.Containers.Timeshare
4
+{
5
+    public class TimeshareSearchDisplay
6
+    {
7
+        public string UserName { get; set; }
8
+        public DateTime Date { get; set; }
9
+        public string Property { get; set; }
10
+        public string Value { get; set; }
11
+    }
12
+}

+ 42
- 0
UnivateProperties_API/Controllers/Logging/SearchLogController.cs View File

1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Transactions;
3
+using UnivateProperties_API.Containers.Timeshare;
4
+using UnivateProperties_API.Repository.Logging;
5
+
6
+namespace UnivateProperties_API.Controllers.Logging
7
+{
8
+    [Route("api/[controller]")]
9
+    [ApiController]
10
+    public class SearchLogController : ControllerBase
11
+    {
12
+        private readonly ISearchLogRepository _Repo;
13
+
14
+        public SearchLogController(ISearchLogRepository repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+      
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();
28
+        }
29
+        
30
+
31
+        [HttpPost]
32
+        public IActionResult Post([FromBody] TimeshareSearch item)
33
+        {
34
+            using (var scope = new TransactionScope())
35
+            {
36
+                _Repo.SaveTimeshareSearch(item);
37
+                scope.Complete();
38
+                return new OkObjectResult(item);
39
+            }
40
+        }        
41
+    }
42
+}

+ 3
- 3
UnivateProperties_API/Controllers/Properties/PropertyController.cs View File

85
         }
85
         }
86
 
86
 
87
         //Will need to come out. Post search not working......:(
87
         //Will need to come out. Post search not working......:(
88
-        [HttpGet("search/{userId}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}")]
89
-        public IActionResult Search(int userId, 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}")]
89
+        public IActionResult Search(string userName, string keyword, string salesType, string propertyUsageType, string propertyType, string province, string city, string suburb)
90
         {
90
         {
91
             var search = new PropertySearch()
91
             var search = new PropertySearch()
92
             {
92
             {
93
-                UserID = userId,
93
+                UserName = userName,
94
                 Keyword = keyword,
94
                 Keyword = keyword,
95
                 SalesType = salesType,
95
                 SalesType = salesType,
96
                 PropertyUsageType = propertyUsageType,
96
                 PropertyUsageType = propertyUsageType,

+ 2
- 7
UnivateProperties_API/Model/Logging/SearchLog.cs View File

1
-using System;
2
-using System.Collections.Generic;
3
-using System.Linq;
4
-using System.Threading.Tasks;
5
-
6
-namespace UnivateProperties_API.Model.Logging
1
+namespace UnivateProperties_API.Model.Logging
7
 {
2
 {
8
     public class SearchLog : BaseEntity
3
     public class SearchLog : BaseEntity
9
     {
4
     {
10
         #region Properties 
5
         #region Properties 
11
-        public int? UserID { get; set; }
6
+        public string Type { get; set; }
12
         public string Search { get; set; }
7
         public string Search { get; set; }
13
         #endregion 
8
         #endregion 
14
     }
9
     }

+ 1
- 2
UnivateProperties_API/Model/Properties/Property.cs View File

35
         [ForeignKey("Agent")]
35
         [ForeignKey("Agent")]
36
         public int? AgentId { get; set; }
36
         public int? AgentId { get; set; }
37
         [ForeignKey("Agency")]
37
         [ForeignKey("Agency")]
38
-        public int? AgencyId { get; set; }
39
-        public int? GCRecord { get; set; }
38
+        public int? AgencyId { get; set; }        
40
 
39
 
41
         public virtual PropertyType PropertyType { get; set; }
40
         public virtual PropertyType PropertyType { get; set; }
42
         public virtual Province Province { get; set; }
41
         public virtual Province Province { get; set; }

+ 14
- 0
UnivateProperties_API/Repository/Logging/ISearchLogRepository.cs View File

1
+using System.Collections.Generic;
2
+using UnivateProperties_API.Containers.Property;
3
+using UnivateProperties_API.Containers.Timeshare;
4
+using UnivateProperties_API.Model.Logging;
5
+
6
+namespace UnivateProperties_API.Repository.Logging
7
+{
8
+    public interface ISearchLogRepository: IRepository<SearchLog>
9
+    {
10
+        List<TimeshareSearchDisplay> GetTimeshareSearches();
11
+        List<PropertySearchDispaly> GetPropertySearches();
12
+        void SaveTimeshareSearch(TimeshareSearch item);
13
+    }
14
+}

+ 147
- 0
UnivateProperties_API/Repository/Logging/SearchLogRepository.cs View File

1
+using Microsoft.EntityFrameworkCore;
2
+using Newtonsoft.Json;
3
+using System;
4
+using System.Collections.Generic;
5
+using System.Diagnostics;
6
+using System.Linq;
7
+using UnivateProperties_API.Containers.Property;
8
+using UnivateProperties_API.Containers.Timeshare;
9
+using UnivateProperties_API.Context;
10
+using UnivateProperties_API.Model.Logging;
11
+
12
+namespace UnivateProperties_API.Repository.Logging
13
+{
14
+    public class SearchLogRepository : ISearchLogRepository
15
+    {
16
+        private readonly DataContext _dbContext;
17
+
18
+        public SearchLogRepository(DataContext dbContext)
19
+        {
20
+            _dbContext = dbContext;
21
+        }
22
+
23
+        public List<SearchLog> Get(Func<SearchLog, bool> where)
24
+        {
25
+            return _dbContext.SearchLogs.Where(where).ToList();
26
+        }
27
+
28
+        public List<SearchLog> GetAll()
29
+        {
30
+            return _dbContext.SearchLogs.ToList();
31
+        }
32
+
33
+        public SearchLog GetDetailed(Func<SearchLog, bool> first)
34
+        {
35
+            var item = _dbContext.SearchLogs.FirstOrDefault(first);
36
+            return item;
37
+        }
38
+
39
+        public List<SearchLog> GetDetailedAll()
40
+        {
41
+            return _dbContext.SearchLogs.ToList();
42
+        }
43
+
44
+        public List<PropertySearchDispaly> GetPropertySearches()
45
+        {
46
+            var list = new List<PropertySearchDispaly>();
47
+            var logs = Get(x => x.Type == "Property");
48
+            foreach (SearchLog log in logs)
49
+            {
50
+                var propSearch = JsonConvert.DeserializeObject<PropertySearch>(log.Search);
51
+                list.Add(new PropertySearchDispaly()
52
+                {
53
+                    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
80
+                });
81
+            }
82
+            return list;
83
+        }
84
+
85
+        public void Insert(SearchLog item)
86
+        {
87
+            _dbContext.SearchLogs.Add(item);
88
+            Save();
89
+        }
90
+
91
+        public void Insert(IEnumerable<SearchLog> items)
92
+        {
93
+            foreach (var item in items)
94
+            {
95
+                _dbContext.SearchLogs.Add(item);
96
+                Save();
97
+            }
98
+        }
99
+
100
+        public void Remove(SearchLog item)
101
+        {
102
+            _dbContext.SearchLogs.Remove(item);
103
+            Save();
104
+        }
105
+
106
+        public void Remove(IEnumerable<SearchLog> items)
107
+        {
108
+            foreach (var item in items)
109
+            {
110
+                _dbContext.SearchLogs.Remove(item);
111
+                Save();
112
+            }
113
+        }
114
+
115
+        public void RemoveAtId(int item)
116
+        {
117
+            var searchLog = Get(x => x.Id == item).FirstOrDefault();
118
+            if (searchLog != null)
119
+            {
120
+               _dbContext.SearchLogs.Remove(searchLog);
121
+                Save();
122
+            }
123
+        }
124
+
125
+        public void Save()
126
+        {
127
+            _dbContext.SaveChanges();
128
+        }
129
+
130
+        public void SaveTimeshareSearch(TimeshareSearch item)
131
+        {
132
+            var searchLog = new SearchLog
133
+            {
134
+                Type = "Timeshare",
135
+                Search = JsonConvert.SerializeObject(item)
136
+            };
137
+            _dbContext.SearchLogs.Remove(searchLog);
138
+            Save();
139
+        }
140
+
141
+        public void Update(SearchLog item)
142
+        {
143
+            _dbContext.Entry(item).State = EntityState.Modified;
144
+            Save();
145
+        }
146
+    }
147
+}

+ 3
- 6
UnivateProperties_API/Repository/ProccessFlow/BidRepository.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 System.Threading.Tasks;
6
 using UnivateProperties_API.Containers.ProcessFlow;
5
 using UnivateProperties_API.Containers.ProcessFlow;
7
 using UnivateProperties_API.Context;
6
 using UnivateProperties_API.Context;
8
 using UnivateProperties_API.Model.ProcessFlow;
7
 using UnivateProperties_API.Model.ProcessFlow;
113
 
112
 
114
         public void Insert(BidItem item)
113
         public void Insert(BidItem item)
115
         {
114
         {
116
-            var status = _dbContext.Status.Where(x => x.Code == "E1" && x.StatusType == StatusType.Bid).FirstOrDefault();
115
+            var status = _dbContext.Status.Where(x => x.Code == "E1").FirstOrDefault();
117
             if (status != null)
116
             if (status != null)
118
                 item.StatusId = status.Id;
117
                 item.StatusId = status.Id;
119
 
118
 
175
                 .Where(x => x.Id == id).FirstOrDefault();
174
                 .Where(x => x.Id == id).FirstOrDefault();
176
 
175
 
177
             var status =  (from s in _dbContext.Status
176
             var status =  (from s in _dbContext.Status
178
-                           where s.Code == "E2"
179
-                           && s.StatusType == StatusType.Bid
177
+                           where s.Code == "E2"                           
180
                            select s).FirstOrDefault();
178
                            select s).FirstOrDefault();
181
 
179
 
182
             if (status != null)
180
             if (status != null)
201
                 .Where(x => x.Id == item.Id).FirstOrDefault();
199
                 .Where(x => x.Id == item.Id).FirstOrDefault();
202
 
200
 
203
             var status = (from s in _dbContext.Status
201
             var status = (from s in _dbContext.Status
204
-                          where s.Code == "E3"
205
-                          && s.StatusType == StatusType.Bid
202
+                          where s.Code == "E3"                          
206
                           select s).FirstOrDefault();
203
                           select s).FirstOrDefault();
207
 
204
 
208
             if (status != null)
205
             if (status != null)

+ 1
- 1
UnivateProperties_API/Repository/Properties/PropertyRepository.cs View File

247
             //Save to Log
247
             //Save to Log
248
             dBContext.SearchLogs.Add(new Model.Logging.SearchLog()
248
             dBContext.SearchLogs.Add(new Model.Logging.SearchLog()
249
             {
249
             {
250
-                UserID = search.UserID,
250
+                Type = "Property",
251
                 Search = JsonConvert.SerializeObject(search)
251
                 Search = JsonConvert.SerializeObject(search)
252
             });
252
             });
253
             Save();
253
             Save();

+ 4
- 0
UnivateProperties_API/Startup.cs View File

21
 using UnivateProperties_API.Repository;
21
 using UnivateProperties_API.Repository;
22
 using UnivateProperties_API.Repository.Banks;
22
 using UnivateProperties_API.Repository.Banks;
23
 using UnivateProperties_API.Repository.Communication;
23
 using UnivateProperties_API.Repository.Communication;
24
+using UnivateProperties_API.Repository.Logging;
24
 using UnivateProperties_API.Repository.ProccessFlow;
25
 using UnivateProperties_API.Repository.ProccessFlow;
25
 using UnivateProperties_API.Repository.Properties;
26
 using UnivateProperties_API.Repository.Properties;
26
 using UnivateProperties_API.Repository.Region;
27
 using UnivateProperties_API.Repository.Region;
134
             services.AddTransient<IRepository<SMTPAccount>, SMTPAccountRepository>();
135
             services.AddTransient<IRepository<SMTPAccount>, SMTPAccountRepository>();
135
             services.AddTransient<IRepository<SMTPHost>, SMTPHostRepository>();
136
             services.AddTransient<IRepository<SMTPHost>, SMTPHostRepository>();
136
             #endregion Communication
137
             #endregion Communication
138
+            #region Logs 
139
+            services.AddTransient<ISearchLogRepository, SearchLogRepository>();
140
+            #endregion
137
             services.Configure<MvcOptions>(options =>
141
             services.Configure<MvcOptions>(options =>
138
             {
142
             {
139
                 options.Filters.Add(new CorsAuthorizationFilterFactory("MyPolicy"));
143
                 options.Filters.Add(new CorsAuthorizationFilterFactory("MyPolicy"));

Loading…
Cancel
Save