Browse Source

Property Search & fixes to property API

master
George Williams 5 years ago
parent
commit
abb358c266

+ 7
- 0
UnivateProperties_API/Containers/Property/PropertyContainer.cs View File

2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
 using System.Linq;
3
 using System.Linq;
4
 using System.Threading.Tasks;
4
 using System.Threading.Tasks;
5
+using UnivateProperties_API.Model.Properties;
5
 
6
 
6
 namespace UnivateProperties_API.Containers.Property
7
 namespace UnivateProperties_API.Containers.Property
7
 {
8
 {
40
         public string Image { get; set;  }
41
         public string Image { get; set;  }
41
         public bool IsDefault { get; set; }
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 View File

88
         [HttpPost]
88
         [HttpPost]
89
         public IActionResult Post([FromBody] PropertyContainer property)
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
                 _Repo.Insert(property);
93
                 _Repo.Insert(property);
94
-                scope.Complete();
94
+                scope.Complete();                
95
                 return CreatedAtAction(nameof(Get), new { id = property.Id }, property);
95
                 return CreatedAtAction(nameof(Get), new { id = property.Id }, property);
96
-            }
97
-        }       
96
+            }            
97
+        }      
98
 
98
 
99
         [HttpPut]
99
         [HttpPut]
100
         public IActionResult Put([FromBody] PropertyContainer property)
100
         public IActionResult Put([FromBody] PropertyContainer property)
101
         {
101
         {
102
             if (property != null)
102
             if (property != null)
103
             {
103
             {
104
-                using (var scope = new TransactionScope())
104
+                using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
105
                 {
105
                 {
106
                     _Repo.Update(property);
106
                     _Repo.Update(property);
107
                     scope.Complete();
107
                     scope.Complete();

+ 3
- 1
UnivateProperties_API/Repository/Properties/IPropertyRepository.cs View File

16
         void Insert(PropertyContainer items);
16
         void Insert(PropertyContainer items);
17
         PropertyContainer GetDetailed(int id, bool detailed);
17
         PropertyContainer GetDetailed(int id, bool detailed);
18
         void Update(PropertyContainer item);
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 View File

548
 
548
 
549
         public List<PropertyDisplay> GetLatestDisplay()
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
             return GetDisplayDetails(props);
552
             return GetDisplayDetails(props);
553
         }
553
         }
554
 
554
 
565
                 if (agent != null)
565
                 if (agent != null)
566
                     properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.AgentId == agent.Id).ToList();
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
                 if (individual != null)
570
                 if (individual != null)
571
                     properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.OwnerId == individual.Id).ToList();
571
                     properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.OwnerId == individual.Id).ToList();
572
                 if (agent != null)
572
                 if (agent != null)
573
                     properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.AgencyId == agent.AgencyId).ToList();
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
             List<PropertyList> list = new List<PropertyList>();
580
             List<PropertyList> list = new List<PropertyList>();
577
 
581
 
655
 
659
 
656
             foreach( string prop in property.GetAllProperties())
660
             foreach( string prop in property.GetAllProperties())
657
             {
661
             {
658
-                if (prop != "Item")
662
+                if (prop != "Item" && prop != "Display")
659
                     property[prop] = items[prop];
663
                     property[prop] = items[prop];
660
             }
664
             }
661
 
665
 
669
 
673
 
670
             property.Video = property.Video.Replace("https://www.youtube.com/watch?v=", "");
674
             property.Video = property.Video.Replace("https://www.youtube.com/watch?v=", "");
671
 
675
 
672
-            dBContext.Properties.Add(property);
673
-            Save();
674
-
675
             if (images != null)
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
                 bool saveFiles = false;
680
                 bool saveFiles = false;
682
                 var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
681
                 var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
690
                     }
689
                     }
691
                 }
690
                 }
692
 
691
 
692
+                property.PropertyImages = new List<PropertyImage>();
693
                 foreach (PropertyImage image in images)
693
                 foreach (PropertyImage image in images)
694
                 {
694
                 {
695
                     lastID++;
695
                     lastID++;
700
                         string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
700
                         string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
701
                         image.Image = path;
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
             if (fields != null)
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
                 foreach (PropertyUserField field in fields)
711
                 foreach (PropertyUserField field in fields)
715
                 {
712
                 {
716
                     lastID++;
713
                     lastID++;
717
                     field.Id = lastID;
714
                     field.Id = lastID;
718
                     field.PropertyId = property.Id;
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
         public bool MayEdit(int id)
726
         public bool MayEdit(int id)
730
                                select b).FirstOrDefault();
731
                                select b).FirstOrDefault();
731
 
732
 
732
             return (hasBidItems == null) ? true : false;
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 View File

121
             foreach (var sub in suburbs)
121
             foreach (var sub in suburbs)
122
             {
122
             {
123
                 searchList.Add(new SuburbSearch()
123
                 searchList.Add(new SuburbSearch()
124
-                {
125
-                    Id = sub.Id,
124
+                {                       
126
                     Province = sub.City.Province.Description,
125
                     Province = sub.City.Province.Description,
127
                     City = sub.City.Description,
126
                     City = sub.City.Description,
128
                     Suburb = sub.Description,
127
                     Suburb = sub.Description,
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
         public List<Suburb> GetByProperty(int propertyId)
147
         public List<Suburb> GetByProperty(int propertyId)

Loading…
Cancel
Save