Kaynağa Gözat

commit merge

master
Kobus Botha 5 yıl önce
ebeveyn
işleme
fbfb2c7f79

+ 17
- 12
UnivateProperties_API/Containers/Property/ImageFormatter.cs Dosyayı Görüntüle

@@ -35,25 +35,30 @@ namespace UnivateProperties_API.Containers.Property
35 35
 
36 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 Dosyayı Görüntüle

@@ -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
 }

+ 1
- 0
UnivateProperties_API/Containers/Property/PropertyList.cs Dosyayı Görüntüle

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

+ 2
- 0
UnivateProperties_API/Containers/Regions/SuburbSearch.cs Dosyayı Görüntüle

@@ -8,6 +8,8 @@ namespace UnivateProperties_API.Containers.Regions
8 8
     public class SuburbSearch
9 9
     {
10 10
         public int Id { get; set; }
11
+        public string Province { get; set; }
12
+        public string City { get; set; }
11 13
         public string Suburb { get; set; }
12 14
         public string Display { get; set; }
13 15
     }

+ 1
- 0
UnivateProperties_API/Context/DataContext.cs Dosyayı Görüntüle

@@ -181,6 +181,7 @@ namespace UnivateProperties_API.Context
181 181
             modelBuilder.Entity<BidItem>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
182 182
             modelBuilder.Entity<ProcessFlow>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
183 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 185
             modelBuilder.Entity<PlaceHolder>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
185 186
         }
186 187
 

+ 1
- 1
UnivateProperties_API/Controllers/Misc/CarouselController.cs Dosyayı Görüntüle

@@ -25,7 +25,7 @@ namespace UnivateProperties_API.Controllers.Misc
25 25
         [HttpGet("{id}")]
26 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 31
         [HttpPost]

+ 5
- 5
UnivateProperties_API/Controllers/Properties/PropertyController.cs Dosyayı Görüntüle

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

+ 61
- 2
UnivateProperties_API/Repository/Misc/CarouselRepository.cs Dosyayı Görüntüle

@@ -1,6 +1,7 @@
1 1
 using Microsoft.EntityFrameworkCore;
2 2
 using System;
3 3
 using System.Collections.Generic;
4
+using System.IO;
4 5
 using System.Linq;
5 6
 using UnivateProperties_API.Containers.Misc;
6 7
 using UnivateProperties_API.Containers.Property;
@@ -56,8 +57,32 @@ namespace UnivateProperties_API.Repository.Misc
56 57
 
57 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 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 88
         public void Insert(IEnumerable<Carousel> items)
@@ -117,12 +142,13 @@ namespace UnivateProperties_API.Repository.Misc
117 142
             var CarouselList = dBContext.Carousel.ToList();
118 143
 
119 144
             foreach (var item in CarouselList)
120
-            {
145
+            {                
121 146
                 if (!string.IsNullOrEmpty(item.Image) && !item.Image.StartsWith("data:image"))
122 147
                     item.Image = ImageFormatter.ImageToBase64(item.Image);
123 148
 
124 149
                 var carItem = new CarouselList()
125 150
                 {
151
+                    Id = item.Id,
126 152
                     Image = item.Image,
127 153
                     Header = item.Header
128 154
                 };
@@ -147,5 +173,38 @@ namespace UnivateProperties_API.Repository.Misc
147 173
 
148 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 Dosyayı Görüntüle

@@ -7,5 +7,6 @@ namespace UnivateProperties_API.Repository.Misc
7 7
     public interface ICarouselRepository : IRepository<Carousel>
8 8
     {
9 9
         List<CarouselList> GetCarouselItems();
10
+        CarouselList GetCarousel(int id);
10 11
     }
11 12
 }

+ 3
- 1
UnivateProperties_API/Repository/Properties/IPropertyRepository.cs Dosyayı Görüntüle

@@ -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
 }

+ 64
- 23
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Dosyayı Görüntüle

@@ -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
 
@@ -561,16 +561,20 @@ namespace UnivateProperties_API.Repository.Properties
561 561
             if (Type.ToUpper() == "MY")
562 562
             {                
563 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 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 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 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 580
             List<PropertyList> list = new List<PropertyList>();
@@ -583,7 +587,8 @@ namespace UnivateProperties_API.Repository.Properties
583 587
                     Name = string.IsNullOrEmpty(p.PropertyName) ? p.ShortDescription : p.PropertyName,
584 588
                     Price = string.Format("R {0:n}", p.Price),
585 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 594
                 prop.Size = (from u in dBContext.PropertyUserFields
@@ -654,7 +659,7 @@ namespace UnivateProperties_API.Repository.Properties
654 659
 
655 660
             foreach( string prop in property.GetAllProperties())
656 661
             {
657
-                if (prop != "Item")
662
+                if (prop != "Item" && prop != "Display")
658 663
                     property[prop] = items[prop];
659 664
             }
660 665
 
@@ -668,14 +673,9 @@ namespace UnivateProperties_API.Repository.Properties
668 673
 
669 674
             property.Video = property.Video.Replace("https://www.youtube.com/watch?v=", "");
670 675
 
671
-            dBContext.Properties.Add(property);
672
-            Save();
673
-
674 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 680
                 bool saveFiles = false;
681 681
                 var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
@@ -689,6 +689,7 @@ namespace UnivateProperties_API.Repository.Properties
689 689
                     }
690 690
                 }
691 691
 
692
+                property.PropertyImages = new List<PropertyImage>();
692 693
                 foreach (PropertyImage image in images)
693 694
                 {
694 695
                     lastID++;
@@ -699,26 +700,27 @@ namespace UnivateProperties_API.Repository.Properties
699 700
                         string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
700 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 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 711
                 foreach (PropertyUserField field in fields)
714 712
                 {
715 713
                     lastID++;
716 714
                     field.Id = lastID;
717 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 726
         public bool MayEdit(int id)
@@ -729,6 +731,45 @@ namespace UnivateProperties_API.Repository.Properties
729 731
                                select b).FirstOrDefault();
730 732
 
731 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 Dosyayı Görüntüle

@@ -115,20 +115,33 @@ namespace UnivateProperties_API.Repository.Region
115 115
 
116 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 119
             List<SuburbSearch> searchList = new List<SuburbSearch>();
120 120
             
121 121
             foreach (var sub in suburbs)
122 122
             {
123 123
                 searchList.Add(new SuburbSearch()
124
-                {
125
-                    Id = sub.Id,
124
+                {                       
125
+                    Province = sub.City.Province.Description,
126
+                    City = sub.City.Description,
126 127
                     Suburb = sub.Description,
127 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 147
         public List<Suburb> GetByProperty(int propertyId)

Loading…
İptal
Kaydet