Kobus 5 年前
父节点
当前提交
246fc597ac

+ 2
- 1
UnivateProperties_API/Containers/Property/GroupFields.cs 查看文件

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

+ 13
- 0
UnivateProperties_API/Containers/Property/PropertyContainer.cs 查看文件

1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+
6
+namespace UnivateProperties_API.Containers.Property
7
+{
8
+    public class PropertyContainer : Model.Properties.Property
9
+    {
10
+        public int UserId { get; set; }
11
+        public string PropertyUsageType { get; set; } 
12
+    }
13
+}

+ 12
- 6
UnivateProperties_API/Controllers/Properties/PropertyController.cs 查看文件

26
             return new OkObjectResult(_Repo.GetDisplay());
26
             return new OkObjectResult(_Repo.GetDisplay());
27
         }
27
         }
28
 
28
 
29
-        [HttpGet("{id}")]
30
-        public IActionResult Get(int id)
29
+        [HttpGet("getDetailed/{id}")]
30
+        public IActionResult GetDetailed(int id)
31
         {
31
         {
32
-            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
33
-        }          
32
+            return new OkObjectResult(_Repo.GetDetailed(id, true));
33
+        }
34
+
35
+        [HttpGet("getProperty/{id}")]
36
+        public IActionResult GetProperty(int id)
37
+        {
38
+            return new OkObjectResult(_Repo.GetDetailed(id, false));
39
+        }
34
 
40
 
35
         [HttpGet("latestProperties")]
41
         [HttpGet("latestProperties")]
36
         public IActionResult GetLatestProperties()
42
         public IActionResult GetLatestProperties()
74
         }
80
         }
75
 
81
 
76
         [HttpPost]
82
         [HttpPost]
77
-        public IActionResult Post([FromBody] Property property)
83
+        public IActionResult Post([FromBody] PropertyContainer property)
78
         {
84
         {
79
             using (var scope = new TransactionScope())
85
             using (var scope = new TransactionScope())
80
             {
86
             {
85
         }
91
         }
86
 
92
 
87
         [HttpPut]
93
         [HttpPut]
88
-        public IActionResult Put([FromBody] Property property)
94
+        public IActionResult Put([FromBody] PropertyContainer property)
89
         {
95
         {
90
             if (property != null)
96
             if (property != null)
91
             {
97
             {

+ 2
- 0
UnivateProperties_API/Model/Properties/Property.cs 查看文件

28
         public int CityId { get; set; }
28
         public int CityId { get; set; }
29
         public int ProvinceId { get; set; }
29
         public int ProvinceId { get; set; }
30
         public bool Published { get; set; }
30
         public bool Published { get; set; }
31
+        public string VirtualTour { get; set; }
32
+        public string Video { get; set; }
31
         [ForeignKey("Status")]
33
         [ForeignKey("Status")]
32
         public int? StatusId { get; set; }
34
         public int? StatusId { get; set; }
33
         [ForeignKey("Owner")]
35
         [ForeignKey("Owner")]

+ 3
- 0
UnivateProperties_API/Repository/Properties/IPropertyRepository.cs 查看文件

13
         List<PropertyDisplay> GetLatestDisplay();
13
         List<PropertyDisplay> GetLatestDisplay();
14
         List<PropertyType> GetPropertyTypes(Func<PropertyType, bool> where);
14
         List<PropertyType> GetPropertyTypes(Func<PropertyType, bool> where);
15
         List<PropertyList> GetPropertyList(string Type, int By);
15
         List<PropertyList> GetPropertyList(string Type, int By);
16
+        void Insert(PropertyContainer items);
17
+        PropertyContainer GetDetailed(int id, bool detailed);
18
+        void Update(PropertyContainer item);
16
     }
19
     }
17
 }
20
 }

+ 207
- 133
UnivateProperties_API/Repository/Properties/PropertyRepository.cs 查看文件

1
 using Microsoft.EntityFrameworkCore;
1
 using Microsoft.EntityFrameworkCore;
2
 using Newtonsoft.Json;
2
 using Newtonsoft.Json;
3
 using System;
3
 using System;
4
-using System.IO;
5
 using System.Collections.Generic;
4
 using System.Collections.Generic;
5
+using System.IO;
6
 using System.Linq;
6
 using System.Linq;
7
 using UnivateProperties_API.Containers.Property;
7
 using UnivateProperties_API.Containers.Property;
8
 using UnivateProperties_API.Containers.Timeshare;
8
 using UnivateProperties_API.Containers.Timeshare;
9
 using UnivateProperties_API.Context;
9
 using UnivateProperties_API.Context;
10
 using UnivateProperties_API.Model.Logging;
10
 using UnivateProperties_API.Model.Logging;
11
 using UnivateProperties_API.Model.Properties;
11
 using UnivateProperties_API.Model.Properties;
12
-using System.Drawing;
13
 
12
 
14
 namespace UnivateProperties_API.Repository.Properties
13
 namespace UnivateProperties_API.Repository.Properties
15
 {
14
 {
40
 
39
 
41
         public Property GetDetailed(Func<Property, bool> first)
40
         public Property GetDetailed(Func<Property, bool> first)
42
         {
41
         {
43
-            var property = dBContext.Properties.Include("Status").FirstOrDefault(first);
42
+            throw new NotImplementedException();            
43
+        }
44
+
45
+        public PropertyContainer GetDetailed(int id, bool detailed)
46
+        {
47
+            var property = dBContext.Properties.Include("Status").Where(p => p.Id == id).FirstOrDefault();            
44
             if (property != null)
48
             if (property != null)
45
             {
49
             {
46
-                GetDetail(ref property);
50
+                return GetDetail(property, detailed);
47
             }
51
             }
48
-            return property;
52
+            return null;
49
         }
53
         }
50
 
54
 
51
         public List<Property> GetDetailedAll()
55
         public List<Property> GetDetailedAll()
54
             return properties;
58
             return properties;
55
         }
59
         }
56
 
60
 
57
-        private void GetDetail(ref Property property)
58
-        {
61
+        private PropertyContainer GetDetail(Property property, bool detailed)
62
+        {            
59
             int propID = property.Id;
63
             int propID = property.Id;
60
             var propertyType = dBContext.PropertyTypes.Find(property.PropertyTypeId);
64
             var propertyType = dBContext.PropertyTypes.Find(property.PropertyTypeId);
61
             property.Province = dBContext.Provinces.Find(property.ProvinceId);
65
             property.Province = dBContext.Provinces.Find(property.ProvinceId);
63
             property.Suburb = dBContext.Suburbs.Find(property.SuburbId);
67
             property.Suburb = dBContext.Suburbs.Find(property.SuburbId);
64
             property.DisplayData = new List<PropertyDetailGroup>();
68
             property.DisplayData = new List<PropertyDetailGroup>();
65
 
69
 
66
-            var groups = (from g in dBContext.UserDefinedGroups
67
-                          where g.UsageType == propertyType.UsageType
68
-                          || g.UsageType == PropertyUsageType.Both
69
-                          orderby g.Rank
70
-                          select g).ToList();
71
-
72
-            foreach (UserDefinedGroup uGroup in groups)
70
+            if (detailed)
73
             {
71
             {
74
-                var groupFields = (from f in dBContext.PropertyUserFields
75
-                                   join uf in dBContext.UserDefinedFields on f.UserDefinedFieldId equals uf.Id
76
-                                   join g in dBContext.UserDefinedGroups on uf.GroupId equals g.Id
77
-                                   where f.PropertyId == propID
78
-                                   && g.Id == uGroup.Id
79
-                                   orderby g.Rank, uf.Rank
80
-                                   select new { uf.FieldName, f.Value, f.Description }).ToList();
81
-
82
-                if (groupFields.Count > 0)
83
-                {
84
-                    PropertyDetailGroup detailGroup = new PropertyDetailGroup()
85
-                    {
86
-                        GroupName = uGroup.Description,
87
-                        Values = new List<PropertyDetail>()
88
-                    };
89
-
90
-                    if (uGroup.Description == "Property Overview")
91
-                    {
92
-                        detailGroup.Values.Add(new PropertyDetail()
93
-                        {
94
-                            Name = "Property Type",
95
-                            Value = property.PropertyType.Description
96
-                        });
97
-                    }
72
+                var groups = (from g in dBContext.UserDefinedGroups
73
+                              where g.UsageType == propertyType.UsageType
74
+                              || g.UsageType == PropertyUsageType.Both
75
+                              orderby g.Rank
76
+                              select g).ToList();
98
 
77
 
99
-                    foreach (var val in groupFields)
78
+                foreach (UserDefinedGroup uGroup in groups)
79
+                {
80
+                    var groupFields = (from f in dBContext.PropertyUserFields
81
+                                       join uf in dBContext.UserDefinedFields on f.UserDefinedFieldId equals uf.Id
82
+                                       join g in dBContext.UserDefinedGroups on uf.GroupId equals g.Id
83
+                                       where f.PropertyId == propID
84
+                                       && g.Id == uGroup.Id
85
+                                       orderby g.Rank, uf.Rank
86
+                                       select new { uf.FieldName, f.Value, f.Description }).ToList();
87
+
88
+                    if (groupFields.Count > 0)
100
                     {
89
                     {
101
-                        var irem = new PropertyDetail()
90
+                        PropertyDetailGroup detailGroup = new PropertyDetailGroup()
102
                         {
91
                         {
103
-                            Name = val.FieldName,
104
-                            Description = val.Description
92
+                            GroupName = uGroup.Description,
93
+                            Values = new List<PropertyDetail>()
105
                         };
94
                         };
106
 
95
 
107
-                        detailGroup.Values.Add(irem);
96
+                        if (uGroup.Description == "Property Overview")
97
+                        {
98
+                            detailGroup.Values.Add(new PropertyDetail()
99
+                            {
100
+                                Name = "Property Type",
101
+                                Value = property.PropertyType.Description
102
+                            });
103
+                        }
108
 
104
 
109
-                        if ((val.FieldName == "Erf Size" || val.FieldName == "Floor Size") && val.Value.EndsWith("2"))
105
+                        foreach (var val in groupFields)
110
                         {
106
                         {
111
-                            irem.Value = val.Value.Substring(0, val.Value.Length - 1) + "<sup>" + val.Value.Last() + "</sup>";
107
+                            var irem = new PropertyDetail()
108
+                            {
109
+                                Name = val.FieldName,
110
+                                Description = val.Description
111
+                            };
112
+
113
+                            detailGroup.Values.Add(irem);
114
+
115
+                            if ((val.FieldName == "Erf Size" || val.FieldName == "Floor Size") && val.Value.EndsWith("2"))
116
+                            {
117
+                                irem.Value = val.Value.Substring(0, val.Value.Length - 1) + "<sup>" + val.Value.Last() + "</sup>";
118
+                            }
119
+                            else
120
+                                irem.Value = val.Value;
112
                         }
121
                         }
113
-                        else
114
-                            irem.Value = val.Value;
115
-                    }
116
 
122
 
117
-                    property.DisplayData.Add(detailGroup);
123
+                        property.DisplayData.Add(detailGroup);
124
+                    }
118
                 }
125
                 }
119
             }
126
             }
120
-        }
121
-
122
-        public void Insert(Property item)
123
-        {
124
-            PropertyType pt = dBContext.PropertyTypes.Find(item.PropertyTypeId);
125
-            if (pt != null)
127
+            else
126
             {
128
             {
127
-                if (pt.UsageType == PropertyUsageType.Residential)
128
-                {
129
-                    string type = dBContext.PropertyTypes.Find(item.PropertyTypeId).Description;
130
-                    if (item.PropertyUserFields.Count > 0)
131
-                    {
132
-                        string shortDesc = "{0} {1} {2}";                        
133
-                        UserDefinedField bedrooms = dBContext.UserDefinedFields.Where(u => u.FieldName == "Bedrooms").FirstOrDefault();
134
-                        var udValue = item.PropertyUserFields.Where(u => u.UserDefinedFieldId == bedrooms.Id).FirstOrDefault();
135
-                        if (udValue != null)
136
-                            item.ShortDescription = string.Format(shortDesc, udValue.Value, "Bedroom", pt.Description).Trim();
137
-                        else
138
-                            item.ShortDescription = string.Format(shortDesc, "", "", pt.Description).Trim();
139
-                    }
140
-                    else
141
-                    {
142
-                        item.ShortDescription = type;
143
-                    }
144
-                }
145
-                else
146
-                {
147
-                    item.ShortDescription = pt.Description;
148
-                }
129
+                if (!string.IsNullOrEmpty(property.Video))
130
+                    property.Video = string.Format("https://www.youtube.com/watch?v={0}", property.Video);
149
             }
131
             }
150
 
132
 
151
-            var images = item.PropertyImages;
152
-            var fields = item.PropertyUserFields;
133
+            var propertyDetails = new PropertyContainer();
153
 
134
 
154
-            item.PropertyImages = null;
155
-            item.PropertyUserFields = null;
156
-
157
-            dBContext.Properties.Add(item);
158
-            Save();
159
-
160
-            if (images != null)
135
+            foreach (string prop in property.GetAllProperties())
161
             {
136
             {
162
-                var lastID = (from p in dBContext.PropertyImages
163
-                              orderby p.Id descending
164
-                              select p.Id).FirstOrDefault();
137
+                if (prop != "Item")
138
+                    propertyDetails[prop] = property[prop];
139
+            }            
165
 
140
 
166
-                bool saveFiles = false;
167
-                var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
168
-                if (!string.IsNullOrEmpty(loc))
169
-                {
170
-                    saveFiles = true;
171
-                    loc += string.Format("\\{0}", item.Id);
172
-                    if (Directory.Exists(loc))
173
-                    {
174
-                        Directory.CreateDirectory(loc);
175
-                    }
176
-                }
177
-                
178
-                foreach (PropertyImage image in images)
179
-                {
180
-                    lastID++;
181
-                    image.Id = lastID;
182
-                    image.PropertyId = item.Id;
183
-                    if (saveFiles)
184
-                    {
185
-                        string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
186
-                        image.Image = path;
187
-                    }
188
-                    dBContext.PropertyImages.Add(image);
189
-                    Save();
190
-                }
191
-            }
141
+            propertyDetails.PropertyUsageType = propertyType.UsageType == PropertyUsageType.Commercial ? "Commercial" : "Residential";
192
 
142
 
193
-            if (fields != null)
194
-            {
195
-                var lastID = (from p in dBContext.PropertyUserFields
196
-                              orderby p.Id descending
197
-                              select p.Id).FirstOrDefault();
143
+            if (property.OwnerId > 0)
144
+                propertyDetails.UserId = (dBContext.Individuals.Where(p => p.Id == property.OwnerId).FirstOrDefault().UserId).Value;
145
+            if (property.AgentId > 0)
146
+                propertyDetails.UserId = (dBContext.Agents.Where(p => p.Id == property.AgentId).FirstOrDefault().UserId).Value;
198
 
147
 
199
-                foreach (PropertyUserField field in fields)
200
-                {
201
-                    lastID++;
202
-                    field.Id = lastID;
203
-                    field.PropertyId = item.Id;
204
-                    dBContext.PropertyUserFields.Add(field);
205
-                    Save();
206
-                }
207
-            }
148
+            return propertyDetails;
149
+        }
150
+
151
+        public void Insert(Property item)
152
+        {
153
+            throw new NotImplementedException();
208
         }
154
         }
209
 
155
 
210
         public void Insert(IEnumerable<Property> items)
156
         public void Insert(IEnumerable<Property> items)
218
 
164
 
219
         public void Remove(Property item)
165
         public void Remove(Property item)
220
         {
166
         {
221
-            dBContext.Properties.Remove(item);
167
+            item.IsDeleted = true;
222
             Save();
168
             Save();
223
         }
169
         }
224
 
170
 
226
         {
172
         {
227
             foreach (var item in items)
173
             foreach (var item in items)
228
             {
174
             {
229
-                dBContext.Properties.Remove(item);
175
+                item.IsDeleted = true;
230
             }
176
             }
231
             Save();
177
             Save();
232
         }
178
         }
248
 
194
 
249
         public void Update(Property item)
195
         public void Update(Property item)
250
         {
196
         {
197
+            if (item.Video.StartsWith("http"))
198
+                item.Video = item.Video.Replace("https://www.youtube.com/watch?v=", "");
199
+
251
             dBContext.Entry(item).State = EntityState.Modified;
200
             dBContext.Entry(item).State = EntityState.Modified;
252
             Save();
201
             Save();
253
         }
202
         }
254
 
203
 
204
+        public void Update(PropertyContainer item)
205
+        {
206
+            if (item.Video.StartsWith("http"))
207
+                item.Video = item.Video.Replace("https://www.youtube.com/watch?v=", "");
208
+
209
+            var property = new Property();
210
+            foreach (string prop in property.GetAllProperties())
211
+            {
212
+                if (prop != "Item")
213
+                    property[prop] = item[prop];
214
+            }
215
+
216
+            dBContext.Entry(property).State = EntityState.Modified;
217
+            Save();
218
+        }
219
+
255
         public List<PropertyDisplay> GetDisplay()
220
         public List<PropertyDisplay> GetDisplay()
256
         {
221
         {
257
             List<Property> props = GetAll();
222
             List<Property> props = GetAll();
461
                                          select p.UsageType.ToString()).FirstOrDefault()
426
                                          select p.UsageType.ToString()).FirstOrDefault()
462
                 };
427
                 };
463
 
428
 
464
-                if (!display.DisplayImage.StartsWith("data:image"))
429
+                if (display.DisplayImage != null && !display.DisplayImage.StartsWith("data:image"))
465
                 {
430
                 {
466
                     display.DisplayImage = ImageFormatter.ImageToBase64(display.DisplayImage);
431
                     display.DisplayImage = ImageFormatter.ImageToBase64(display.DisplayImage);
467
                 }
432
                 }
552
         {
517
         {
553
             // Not sure if properties need it
518
             // Not sure if properties need it
554
             return 0;
519
             return 0;
555
-        }       
520
+        }
521
+
522
+        public void Insert(PropertyContainer items)
523
+        {
524
+            Property property = new Property();
525
+
526
+            PropertyType pt = dBContext.PropertyTypes.Find(items.PropertyTypeId);
527
+            if (pt != null)
528
+            {
529
+                if (pt.UsageType == PropertyUsageType.Residential)
530
+                {
531
+                    string type = dBContext.PropertyTypes.Find(items.PropertyTypeId).Description;
532
+                    if (items.PropertyUserFields.Count > 0)
533
+                    {
534
+                        string shortDesc = "{0} {1} {2}";
535
+                        UserDefinedField bedrooms = dBContext.UserDefinedFields.Where(u => u.FieldName == "Bedrooms").FirstOrDefault();
536
+                        var udValue = items.PropertyUserFields.Where(u => u.UserDefinedFieldId == bedrooms.Id).FirstOrDefault();
537
+                        if (udValue != null)
538
+                            items.ShortDescription = string.Format(shortDesc, udValue.Value, "Bedroom", pt.Description).Trim();
539
+                        else
540
+                            items.ShortDescription = string.Format(shortDesc, "", "", pt.Description).Trim();
541
+                    }
542
+                    else
543
+                    {
544
+                        items.ShortDescription = type;
545
+                    }
546
+                }
547
+                else
548
+                {
549
+                    items.ShortDescription = pt.Description;
550
+                }
551
+            }
552
+
553
+            var images = items.PropertyImages;
554
+            var fields = items.PropertyUserFields;
555
+
556
+            items.PropertyImages = null;
557
+            items.PropertyUserFields = null;
558
+
559
+            var individual = dBContext.Individuals.Where(i => i.UserId == items.UserId).FirstOrDefault();
560
+            var agent = dBContext.Agents.Where(a => a.UserId == items.UserId).FirstOrDefault();            
561
+
562
+            foreach( string prop in property.GetAllProperties())
563
+            {
564
+                if (prop != "Item")
565
+                    property[prop] = items[prop];
566
+            }
567
+
568
+            if (individual != null)
569
+                property.OwnerId = individual.Id;
570
+            if (agent != null)
571
+            {
572
+                property.AgencyId = agent.AgencyId;
573
+                property.AgentId = agent.Id;
574
+            }
575
+
576
+            property.Video = property.Video.Replace("https://www.youtube.com/watch?v=", "");
577
+
578
+            dBContext.Properties.Add(property);
579
+            Save();
580
+
581
+            if (images != null)
582
+            {
583
+                var lastID = (from p in dBContext.PropertyImages
584
+                              orderby p.Id descending
585
+                              select p.Id).FirstOrDefault();
586
+
587
+                bool saveFiles = false;
588
+                var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
589
+                if (!string.IsNullOrEmpty(loc))
590
+                {
591
+                    saveFiles = true;
592
+                    loc += string.Format("\\{0}", property.Id);
593
+                    if (Directory.Exists(loc))
594
+                    {
595
+                        Directory.CreateDirectory(loc);
596
+                    }
597
+                }
598
+
599
+                foreach (PropertyImage image in images)
600
+                {
601
+                    lastID++;
602
+                    image.Id = lastID;
603
+                    image.PropertyId = property.Id;
604
+                    if (saveFiles)
605
+                    {
606
+                        string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
607
+                        image.Image = path;
608
+                    }
609
+                    dBContext.PropertyImages.Add(image);
610
+                    Save();
611
+                }
612
+            }
613
+
614
+            if (fields != null)
615
+            {
616
+                var lastID = (from p in dBContext.PropertyUserFields
617
+                              orderby p.Id descending
618
+                              select p.Id).FirstOrDefault();
619
+
620
+                foreach (PropertyUserField field in fields)
621
+                {
622
+                    lastID++;
623
+                    field.Id = lastID;
624
+                    field.PropertyId = property.Id;
625
+                    dBContext.PropertyUserFields.Add(field);
626
+                    Save();
627
+                }
628
+            }
629
+        }        
556
     }
630
     }
557
 }
631
 }

+ 3
- 0
UnivateProperties_API/Repository/Properties/UserDefinedGroupRepository.cs 查看文件

90
                 {
90
                 {
91
                     var item = savedValues.Find(x => x.UserDefinedFieldId == field.ID);
91
                     var item = savedValues.Find(x => x.UserDefinedFieldId == field.ID);
92
                     if (item != null)
92
                     if (item != null)
93
+                    {
93
                         field.Value = item.Value;
94
                         field.Value = item.Value;
95
+                        field.ItemID = item.Id;
96
+                    }
94
                 }
97
                 }
95
             }
98
             }
96
 
99
 

正在加载...
取消
保存