瀏覽代碼

Property Search & fixes to property API

master
George Williams 5 年之前
父節點
當前提交
abb358c266

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

@@ -2,6 +2,7 @@
2 2
 using System.Collections.Generic;
3 3
 using System.Linq;
4 4
 using System.Threading.Tasks;
5
+using UnivateProperties_API.Model.Properties;
5 6
 
6 7
 namespace UnivateProperties_API.Containers.Property
7 8
 {
@@ -40,4 +41,10 @@ namespace UnivateProperties_API.Containers.Property
40 41
         public string Image { get; set;  }
41 42
         public bool IsDefault { get; set; }
42 43
     }
44
+
45
+    public class PropertyImageContainer
46
+    {
47
+        public int PropertyId { get; set; }
48
+        public List<PropertyImage> Images { get; set; }
49
+    }
43 50
 }

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

@@ -88,20 +88,20 @@ namespace UnivateProperties_API.Controllers.Properties
88 88
         [HttpPost]
89 89
         public IActionResult Post([FromBody] PropertyContainer property)
90 90
         {
91
-            using (var scope = new TransactionScope())
91
+            using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
92 92
             {
93 93
                 _Repo.Insert(property);
94
-                scope.Complete();
94
+                scope.Complete();                
95 95
                 return CreatedAtAction(nameof(Get), new { id = property.Id }, property);
96
-            }
97
-        }       
96
+            }            
97
+        }      
98 98
 
99 99
         [HttpPut]
100 100
         public IActionResult Put([FromBody] PropertyContainer property)
101 101
         {
102 102
             if (property != null)
103 103
             {
104
-                using (var scope = new TransactionScope())
104
+                using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
105 105
                 {
106 106
                     _Repo.Update(property);
107 107
                     scope.Complete();

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

@@ -16,6 +16,8 @@ namespace UnivateProperties_API.Repository.Properties
16 16
         void Insert(PropertyContainer items);
17 17
         PropertyContainer GetDetailed(int id, bool detailed);
18 18
         void Update(PropertyContainer item);
19
-        bool MayEdit(int id);        
19
+        bool MayEdit(int id);
20
+        void InsertImages(int propertyID, List<PropertyImage> Images);
21
+        void InsertFields(int propertyID, List<PropertyUserField> Fields);
20 22
     }
21 23
 }

+ 58
- 18
UnivateProperties_API/Repository/Properties/PropertyRepository.cs 查看文件

@@ -548,7 +548,7 @@ namespace UnivateProperties_API.Repository.Properties
548 548
 
549 549
         public List<PropertyDisplay> GetLatestDisplay()
550 550
         {
551
-            List<Property> props = GetAll().OrderBy(x => x.Created).Take(3).ToList();
551
+            List<Property> props = GetAll().OrderByDescending(x => x.Created).Take(3).ToList();
552 552
             return GetDisplayDetails(props);
553 553
         }
554 554
 
@@ -565,13 +565,17 @@ namespace UnivateProperties_API.Repository.Properties
565 565
                 if (agent != null)
566 566
                     properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.AgentId == agent.Id).ToList();
567 567
             }
568
-            else
568
+            else if (Type.ToUpper() == "ADMIN")
569 569
             {
570 570
                 if (individual != null)
571 571
                     properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.OwnerId == individual.Id).ToList();
572 572
                 if (agent != null)
573 573
                     properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.AgencyId == agent.AgencyId).ToList();
574 574
             }
575
+            else if (Type.ToUpper() == "SUPERADMIN")
576
+            {
577
+                properties = dBContext.Properties.Include("City").Include("Suburb").ToList();
578
+            }
575 579
             
576 580
             List<PropertyList> list = new List<PropertyList>();
577 581
 
@@ -655,7 +659,7 @@ namespace UnivateProperties_API.Repository.Properties
655 659
 
656 660
             foreach( string prop in property.GetAllProperties())
657 661
             {
658
-                if (prop != "Item")
662
+                if (prop != "Item" && prop != "Display")
659 663
                     property[prop] = items[prop];
660 664
             }
661 665
 
@@ -669,14 +673,9 @@ namespace UnivateProperties_API.Repository.Properties
669 673
 
670 674
             property.Video = property.Video.Replace("https://www.youtube.com/watch?v=", "");
671 675
 
672
-            dBContext.Properties.Add(property);
673
-            Save();
674
-
675 676
             if (images != null)
676 677
             {
677
-                var lastID = (from p in dBContext.PropertyImages
678
-                              orderby p.Id descending
679
-                              select p.Id).FirstOrDefault();
678
+                var lastID = dBContext.GetMaxID("PropertyImages");
680 679
 
681 680
                 bool saveFiles = false;
682 681
                 var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
@@ -690,6 +689,7 @@ namespace UnivateProperties_API.Repository.Properties
690 689
                     }
691 690
                 }
692 691
 
692
+                property.PropertyImages = new List<PropertyImage>();
693 693
                 foreach (PropertyImage image in images)
694 694
                 {
695 695
                     lastID++;
@@ -700,26 +700,27 @@ namespace UnivateProperties_API.Repository.Properties
700 700
                         string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
701 701
                         image.Image = path;
702 702
                     }
703
-                    dBContext.PropertyImages.Add(image);
704
-                    Save();
703
+                    property.PropertyImages.Add(image);
705 704
                 }
706 705
             }
707 706
 
708 707
             if (fields != null)
709 708
             {
710
-                var lastID = (from p in dBContext.PropertyUserFields
711
-                              orderby p.Id descending
712
-                              select p.Id).FirstOrDefault();
713
-
709
+                var lastID = dBContext.GetMaxID("PropertyUserFields");
710
+                property.PropertyUserFields = new List<PropertyUserField>();
714 711
                 foreach (PropertyUserField field in fields)
715 712
                 {
716 713
                     lastID++;
717 714
                     field.Id = lastID;
718 715
                     field.PropertyId = property.Id;
719
-                    dBContext.PropertyUserFields.Add(field);
720
-                    Save();
716
+                    property.PropertyUserFields.Add(field);
721 717
                 }
722 718
             }
719
+
720
+            dBContext.Properties.Add(property);
721
+            Save();
722
+
723
+            items.Id = property.Id;            
723 724
         }
724 725
 
725 726
         public bool MayEdit(int id)
@@ -730,6 +731,45 @@ namespace UnivateProperties_API.Repository.Properties
730 731
                                select b).FirstOrDefault();
731 732
 
732 733
             return (hasBidItems == null) ? true : false;
733
-        }                
734
+        }
735
+
736
+        public void InsertImages(int propertyID, List<PropertyImage> Images)
737
+        {
738
+            if (Images != null)
739
+            {
740
+                var lastID = dBContext.GetMaxID("PropertyImages");
741
+
742
+                bool saveFiles = false;
743
+                var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
744
+                if (!string.IsNullOrEmpty(loc))
745
+                {
746
+                    saveFiles = true;
747
+                    loc += string.Format("\\{0}", propertyID);
748
+                    if (Directory.Exists(loc))
749
+                    {
750
+                        Directory.CreateDirectory(loc);
751
+                    }
752
+                }
753
+
754
+                foreach (PropertyImage image in Images)
755
+                {
756
+                    lastID++;
757
+                    image.Id = lastID;
758
+                    image.PropertyId = propertyID;
759
+                    if (saveFiles)
760
+                    {
761
+                        string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
762
+                        image.Image = path;
763
+                    }
764
+                    dBContext.PropertyImages.Add(image);
765
+                    Save();
766
+                }
767
+            }
768
+        }
769
+
770
+        public void InsertFields(int propertyID, List<PropertyUserField> Fields)
771
+        {
772
+            throw new NotImplementedException();
773
+        }
734 774
     }
735 775
 }

+ 14
- 3
UnivateProperties_API/Repository/Region/SuburbRepository.cs 查看文件

@@ -121,8 +121,7 @@ namespace UnivateProperties_API.Repository.Region
121 121
             foreach (var sub in suburbs)
122 122
             {
123 123
                 searchList.Add(new SuburbSearch()
124
-                {
125
-                    Id = sub.Id,
124
+                {                       
126 125
                     Province = sub.City.Province.Description,
127 126
                     City = sub.City.Description,
128 127
                     Suburb = sub.Description,
@@ -130,7 +129,19 @@ namespace UnivateProperties_API.Repository.Region
130 129
                 });
131 130
             }
132 131
 
133
-            return searchList;
132
+            var cities = dBContext.Cities.Include("Province").ToList();
133
+            foreach(var city in cities)
134
+            {
135
+                searchList.Add(new SuburbSearch()
136
+                {                    
137
+                    Province = city.Province.Description,
138
+                    City = city.Description,
139
+                    Suburb = "",
140
+                    Display = string.Format("{0}", city.Description)
141
+                });
142
+            }
143
+
144
+            return searchList.OrderBy(s => s.City).ThenBy(s => s.Suburb).ToList();
134 145
         }
135 146
 
136 147
         public List<Suburb> GetByProperty(int propertyId)

Loading…
取消
儲存