瀏覽代碼

commit merge

master
Kobus Botha 5 年之前
父節點
當前提交
fbfb2c7f79

+ 17
- 12
UnivateProperties_API/Containers/Property/ImageFormatter.cs 查看文件

35
 
35
 
36
         public static string ImageToBase64(string Path)
36
         public static string ImageToBase64(string Path)
37
         {
37
         {
38
-            using (Image image = Image.FromFile(Path))
38
+            if (File.Exists(Path))
39
             {
39
             {
40
-                using (MemoryStream m = new MemoryStream())
40
+                using (Image image = Image.FromFile(Path))
41
                 {
41
                 {
42
-                    image.Save(m, image.RawFormat);
43
-                    byte[] imageBytes = m.ToArray();
42
+                    using (MemoryStream m = new MemoryStream())
43
+                    {
44
+                        image.Save(m, image.RawFormat);
45
+                        byte[] imageBytes = m.ToArray();
44
 
46
 
45
-                    string base64String = Convert.ToBase64String(imageBytes);
47
+                        string base64String = Convert.ToBase64String(imageBytes);
46
 
48
 
47
-                    if (Path.EndsWith(".jpg") || Path.EndsWith(".jpeg"))
48
-                        base64String = "data:image/jpeg;base64," + base64String;
49
-                    if (Path.EndsWith(".gif"))
50
-                        base64String = "data:image/gif;base64," + base64String;
51
-                    if (base64String.EndsWith(".png"))
52
-                        base64String = "data:image/png;base64," + base64String;
49
+                        if (Path.EndsWith(".jpg") || Path.EndsWith(".jpeg"))
50
+                            base64String = "data:image/jpeg;base64," + base64String;
51
+                        if (Path.EndsWith(".gif"))
52
+                            base64String = "data:image/gif;base64," + base64String;
53
+                        if (base64String.EndsWith(".png"))
54
+                            base64String = "data:image/png;base64," + base64String;
53
 
55
 
54
-                    return base64String;
56
+                        return base64String;
57
+                    }
55
                 }
58
                 }
56
             }
59
             }
60
+            else
61
+                return "";
57
         }
62
         }
58
     }
63
     }
59
 }
64
 }

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

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
 }

+ 1
- 0
UnivateProperties_API/Containers/Property/PropertyList.cs 查看文件

12
         public string SaleType { get; set; }
12
         public string SaleType { get; set; }
13
         public string Publish { get; set; }
13
         public string Publish { get; set; }
14
         public string Status { get; set; }
14
         public string Status { get; set; }
15
+        public string CarouselDescription { get; set; }
15
         #endregion
16
         #endregion
16
     }
17
     }
17
 }
18
 }

+ 2
- 0
UnivateProperties_API/Containers/Regions/SuburbSearch.cs 查看文件

8
     public class SuburbSearch
8
     public class SuburbSearch
9
     {
9
     {
10
         public int Id { get; set; }
10
         public int Id { get; set; }
11
+        public string Province { get; set; }
12
+        public string City { get; set; }
11
         public string Suburb { get; set; }
13
         public string Suburb { get; set; }
12
         public string Display { get; set; }
14
         public string Display { get; set; }
13
     }
15
     }

+ 1
- 0
UnivateProperties_API/Context/DataContext.cs 查看文件

181
             modelBuilder.Entity<BidItem>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
181
             modelBuilder.Entity<BidItem>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
182
             modelBuilder.Entity<ProcessFlow>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
182
             modelBuilder.Entity<ProcessFlow>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
183
             modelBuilder.Entity<Template>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
183
             modelBuilder.Entity<Template>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
184
+            modelBuilder.Entity<Carousel>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
184
             modelBuilder.Entity<PlaceHolder>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
185
             modelBuilder.Entity<PlaceHolder>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
185
         }
186
         }
186
 
187
 

+ 1
- 1
UnivateProperties_API/Controllers/Misc/CarouselController.cs 查看文件

25
         [HttpGet("{id}")]
25
         [HttpGet("{id}")]
26
         public IActionResult Get(int id)
26
         public IActionResult Get(int id)
27
         {
27
         {
28
-            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
28
+            return new OkObjectResult(_Repo.GetCarousel(id));
29
         }        
29
         }        
30
 
30
 
31
         [HttpPost]
31
         [HttpPost]

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

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();

+ 61
- 2
UnivateProperties_API/Repository/Misc/CarouselRepository.cs 查看文件

1
 using Microsoft.EntityFrameworkCore;
1
 using Microsoft.EntityFrameworkCore;
2
 using System;
2
 using System;
3
 using System.Collections.Generic;
3
 using System.Collections.Generic;
4
+using System.IO;
4
 using System.Linq;
5
 using System.Linq;
5
 using UnivateProperties_API.Containers.Misc;
6
 using UnivateProperties_API.Containers.Misc;
6
 using UnivateProperties_API.Containers.Property;
7
 using UnivateProperties_API.Containers.Property;
56
 
57
 
57
         public void Insert(Carousel item)
58
         public void Insert(Carousel item)
58
         {
59
         {
59
-            dBContext.Carousel.Add(item);
60
+            string image = item.Image;
61
+            item.Image = "";
62
+            dBContext.Add(item);
60
             Save();
63
             Save();
64
+
65
+            bool saveFiles = false;
66
+            var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
67
+            var lastID = item.Id;
68
+            item.Id = lastID;
69
+            if (!string.IsNullOrEmpty(loc))
70
+            {
71
+                saveFiles = true;
72
+                loc = loc.Replace("Properties", "Carousel");
73
+                if (Directory.Exists(loc))
74
+                {
75
+                    Directory.CreateDirectory(loc);
76
+                }
77
+            }
78
+            if (saveFiles)
79
+            {
80
+                string path = ImageFormatter.Base64ToImage(image, loc, lastID.ToString());
81
+                item.Image = path;
82
+            }
83
+
84
+            Update(item);
85
+            
61
         }
86
         }
62
 
87
 
63
         public void Insert(IEnumerable<Carousel> items)
88
         public void Insert(IEnumerable<Carousel> items)
117
             var CarouselList = dBContext.Carousel.ToList();
142
             var CarouselList = dBContext.Carousel.ToList();
118
 
143
 
119
             foreach (var item in CarouselList)
144
             foreach (var item in CarouselList)
120
-            {
145
+            {                
121
                 if (!string.IsNullOrEmpty(item.Image) && !item.Image.StartsWith("data:image"))
146
                 if (!string.IsNullOrEmpty(item.Image) && !item.Image.StartsWith("data:image"))
122
                     item.Image = ImageFormatter.ImageToBase64(item.Image);
147
                     item.Image = ImageFormatter.ImageToBase64(item.Image);
123
 
148
 
124
                 var carItem = new CarouselList()
149
                 var carItem = new CarouselList()
125
                 {
150
                 {
151
+                    Id = item.Id,
126
                     Image = item.Image,
152
                     Image = item.Image,
127
                     Header = item.Header
153
                     Header = item.Header
128
                 };
154
                 };
147
 
173
 
148
             return list;
174
             return list;
149
         }
175
         }
176
+
177
+        public CarouselList GetCarousel(int id)
178
+        {
179
+            var carousel = dBContext.Carousel.Where(c => c.Id == id).FirstOrDefault();
180
+
181
+            CarouselList item = new CarouselList();
182
+            if (carousel != null)
183
+            {
184
+                foreach (string prop in carousel.GetAllProperties())
185
+                {
186
+                    if (prop != "Item" && prop != "Display")
187
+                        item[prop] = carousel[prop];
188
+                }
189
+
190
+                if (item.PropertyId > 0)
191
+                {
192
+                    var property = dBContext.Properties.Include("Province").Include("City").Include("Suburb").Where(p => p.Id == item.PropertyId).FirstOrDefault();
193
+                    item.Address = string.Format("{0}, {1} <br/>{2}", property.Suburb.Description, property.City.Description, property.AddressLine3);
194
+                    item.IsProperty = true;
195
+                }
196
+                if (item.TimeshareId > 0)
197
+                {
198
+                    var timeshare = dBContext.Weeks.Where(t => t.Id == item.TimeshareId).FirstOrDefault();
199
+                    item.Bedrooms = timeshare.Bedrooms;
200
+                    item.Sleeps = timeshare.MaxSleep;
201
+                    item.Arrival = timeshare.ArrivalDate;
202
+                    item.Departure = timeshare.DepartureDate;
203
+                    item.IsProperty = false;
204
+                }
205
+            }
206
+
207
+            return item;
208
+        }
150
     }
209
     }
151
 }
210
 }

+ 1
- 0
UnivateProperties_API/Repository/Misc/ICarouselRepository.cs 查看文件

7
     public interface ICarouselRepository : IRepository<Carousel>
7
     public interface ICarouselRepository : IRepository<Carousel>
8
     {
8
     {
9
         List<CarouselList> GetCarouselItems();
9
         List<CarouselList> GetCarouselItems();
10
+        CarouselList GetCarousel(int id);
10
     }
11
     }
11
 }
12
 }

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

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
 }

+ 64
- 23
UnivateProperties_API/Repository/Properties/PropertyRepository.cs 查看文件

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
 
561
             if (Type.ToUpper() == "MY")
561
             if (Type.ToUpper() == "MY")
562
             {                
562
             {                
563
                 if (individual != null)
563
                 if (individual != null)
564
-                    properties = Get(x => x.OwnerId == individual.Id);
564
+                    properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.OwnerId == individual.Id).ToList();
565
                 if (agent != null)
565
                 if (agent != null)
566
-                    properties = Get(x => x.AgentId == agent.Id);
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 = Get(x => x.OwnerId == individual.Id);
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 = Get(x => x.AgencyId == agent.AgencyId);
573
+                    properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.AgencyId == agent.AgencyId).ToList();
574
+            }
575
+            else if (Type.ToUpper() == "SUPERADMIN")
576
+            {
577
+                properties = dBContext.Properties.Include("City").Include("Suburb").ToList();
574
             }
578
             }
575
             
579
             
576
             List<PropertyList> list = new List<PropertyList>();
580
             List<PropertyList> list = new List<PropertyList>();
583
                     Name = string.IsNullOrEmpty(p.PropertyName) ? p.ShortDescription : p.PropertyName,
587
                     Name = string.IsNullOrEmpty(p.PropertyName) ? p.ShortDescription : p.PropertyName,
584
                     Price = string.Format("R {0:n}", p.Price),
588
                     Price = string.Format("R {0:n}", p.Price),
585
                     Publish = p.Published.ToString(),
589
                     Publish = p.Published.ToString(),
586
-                    Type = dBContext.PropertyTypes.Find(p.PropertyTypeId)?.Description
590
+                    Type = dBContext.PropertyTypes.Find(p.PropertyTypeId)?.Description,
591
+                    CarouselDescription = string.Format("{0}, {1} <br/>{2}", p.Suburb.Description, p.City.Description, p.AddressLine3)
587
                 };
592
                 };
588
 
593
 
589
                 prop.Size = (from u in dBContext.PropertyUserFields
594
                 prop.Size = (from u in dBContext.PropertyUserFields
654
 
659
 
655
             foreach( string prop in property.GetAllProperties())
660
             foreach( string prop in property.GetAllProperties())
656
             {
661
             {
657
-                if (prop != "Item")
662
+                if (prop != "Item" && prop != "Display")
658
                     property[prop] = items[prop];
663
                     property[prop] = items[prop];
659
             }
664
             }
660
 
665
 
668
 
673
 
669
             property.Video = property.Video.Replace("https://www.youtube.com/watch?v=", "");
674
             property.Video = property.Video.Replace("https://www.youtube.com/watch?v=", "");
670
 
675
 
671
-            dBContext.Properties.Add(property);
672
-            Save();
673
-
674
             if (images != null)
676
             if (images != null)
675
             {
677
             {
676
-                var lastID = (from p in dBContext.PropertyImages
677
-                              orderby p.Id descending
678
-                              select p.Id).FirstOrDefault();
678
+                var lastID = dBContext.GetMaxID("PropertyImages");
679
 
679
 
680
                 bool saveFiles = false;
680
                 bool saveFiles = false;
681
                 var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
681
                 var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
689
                     }
689
                     }
690
                 }
690
                 }
691
 
691
 
692
+                property.PropertyImages = new List<PropertyImage>();
692
                 foreach (PropertyImage image in images)
693
                 foreach (PropertyImage image in images)
693
                 {
694
                 {
694
                     lastID++;
695
                     lastID++;
699
                         string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
700
                         string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
700
                         image.Image = path;
701
                         image.Image = path;
701
                     }
702
                     }
702
-                    dBContext.PropertyImages.Add(image);
703
-                    Save();
703
+                    property.PropertyImages.Add(image);
704
                 }
704
                 }
705
             }
705
             }
706
 
706
 
707
             if (fields != null)
707
             if (fields != null)
708
             {
708
             {
709
-                var lastID = (from p in dBContext.PropertyUserFields
710
-                              orderby p.Id descending
711
-                              select p.Id).FirstOrDefault();
712
-
709
+                var lastID = dBContext.GetMaxID("PropertyUserFields");
710
+                property.PropertyUserFields = new List<PropertyUserField>();
713
                 foreach (PropertyUserField field in fields)
711
                 foreach (PropertyUserField field in fields)
714
                 {
712
                 {
715
                     lastID++;
713
                     lastID++;
716
                     field.Id = lastID;
714
                     field.Id = lastID;
717
                     field.PropertyId = property.Id;
715
                     field.PropertyId = property.Id;
718
-                    dBContext.PropertyUserFields.Add(field);
719
-                    Save();
716
+                    property.PropertyUserFields.Add(field);
720
                 }
717
                 }
721
             }
718
             }
719
+
720
+            dBContext.Properties.Add(property);
721
+            Save();
722
+
723
+            items.Id = property.Id;            
722
         }
724
         }
723
 
725
 
724
         public bool MayEdit(int id)
726
         public bool MayEdit(int id)
729
                                select b).FirstOrDefault();
731
                                select b).FirstOrDefault();
730
 
732
 
731
             return (hasBidItems == null) ? true : false;
733
             return (hasBidItems == null) ? true : false;
732
-        }                
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
+        }
733
     }
774
     }
734
 }
775
 }

+ 17
- 4
UnivateProperties_API/Repository/Region/SuburbRepository.cs 查看文件

115
 
115
 
116
         public List<SuburbSearch> GetSearchList()
116
         public List<SuburbSearch> GetSearchList()
117
         {
117
         {
118
-            var suburbs = dBContext.Suburbs.Include("City").ToList();
118
+            var suburbs = dBContext.Suburbs.Include("City").Include("City.Province").ToList();
119
             List<SuburbSearch> searchList = new List<SuburbSearch>();
119
             List<SuburbSearch> searchList = new List<SuburbSearch>();
120
             
120
             
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
+                {                       
125
+                    Province = sub.City.Province.Description,
126
+                    City = sub.City.Description,
126
                     Suburb = sub.Description,
127
                     Suburb = sub.Description,
127
                     Display = string.Format("{0} - {1}", sub.Description, sub.City.Description)
128
                     Display = string.Format("{0} - {1}", sub.Description, sub.City.Description)
128
                 });
129
                 });
129
             }
130
             }
130
 
131
 
131
-            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();
132
         }
145
         }
133
 
146
 
134
         public List<Suburb> GetByProperty(int propertyId)
147
         public List<Suburb> GetByProperty(int propertyId)

Loading…
取消
儲存