Kaynağa Gözat

Property Edit & Carousel WIP

master
George Williams 5 yıl önce
ebeveyn
işleme
8fe1a1196a
22 değiştirilmiş dosya ile 536 ekleme ve 18 silme
  1. 31
    1
      UnivateProperties_API/Containers/Property/PropertyContainer.cs
  2. 3
    1
      UnivateProperties_API/Containers/Property/PropertySearch.cs
  3. 14
    0
      UnivateProperties_API/Containers/Regions/SuburbSearch.cs
  4. 34
    2
      UnivateProperties_API/Context/DataContext.cs
  5. 69
    0
      UnivateProperties_API/Controllers/Misc/CarouselController.cs
  6. 9
    3
      UnivateProperties_API/Controllers/Properties/PropertyController.cs
  7. 12
    5
      UnivateProperties_API/Controllers/Properties/PropertyImageController.cs
  8. 6
    0
      UnivateProperties_API/Controllers/Region/CityController.cs
  9. 12
    0
      UnivateProperties_API/Controllers/Region/SuburbController.cs
  10. 14
    0
      UnivateProperties_API/Model/Misc/Carousel.cs
  11. 113
    0
      UnivateProperties_API/Repository/Misc/CarouselRepository.cs
  12. 2
    0
      UnivateProperties_API/Repository/Properties/IPropertyImageRepository.cs
  13. 1
    0
      UnivateProperties_API/Repository/Properties/IPropertyRepository.cs
  14. 52
    1
      UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs
  15. 106
    3
      UnivateProperties_API/Repository/Properties/PropertyRepository.cs
  16. 1
    1
      UnivateProperties_API/Repository/Properties/UserDefinedGroupRepository.cs
  17. 14
    0
      UnivateProperties_API/Repository/Region/CityRepository.cs
  18. 1
    0
      UnivateProperties_API/Repository/Region/ICityRepository.cs
  19. 3
    0
      UnivateProperties_API/Repository/Region/ISuburbRepository.cs
  20. 33
    0
      UnivateProperties_API/Repository/Region/SuburbRepository.cs
  21. 5
    0
      UnivateProperties_API/Startup.cs
  22. 1
    1
      UnivateProperties_API/UnivateProperties_API.csproj

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

@@ -8,6 +8,36 @@ namespace UnivateProperties_API.Containers.Property
8 8
     public class PropertyContainer : Model.Properties.Property
9 9
     {
10 10
         public int UserId { get; set; }
11
-        public string PropertyUsageType { get; set; } 
11
+        public string PropertyUsageType { get; set; }
12
+        public List<NewImage> NewImages { get; set; }
13
+        public List<PropertyFieldGroup> PropertyOverviewFields { get; set; }
14
+        public List<PropertyFieldGroup> PropertyFields { get; set; }
15
+    }
16
+
17
+    public class PropertyFieldGroup
18
+    {
19
+        public string Name { get; set; }
20
+        public List<PropertyFieldEdit> Fields { get; set; }
21
+    }
22
+
23
+    public class PropertyFieldEdit
24
+    {
25
+        public int Id { get; set; }
26
+        public string Name { get; set; }
27
+        public string Type { get; set; }
28
+        public string Value { get; set; }
29
+        public int ItemId { get; set; }
30
+    }
31
+
32
+    public class NewPropertyImages
33
+    {
34
+        public int PropertyId { get; set; }
35
+        public List<NewImage> Images { get; set; }
36
+    }
37
+
38
+    public class NewImage
39
+    {        
40
+        public string Image { get; set;  }
41
+        public bool IsDefault { get; set; }
12 42
     }
13 43
 }

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

@@ -1,4 +1,6 @@
1
-namespace UnivateProperties_API.Containers.Property
1
+using System.Collections.Generic;
2
+
3
+namespace UnivateProperties_API.Containers.Property
2 4
 {
3 5
     public class PropertySearch
4 6
     {

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

@@ -0,0 +1,14 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+
6
+namespace UnivateProperties_API.Containers.Regions
7
+{
8
+    public class SuburbSearch
9
+    {
10
+        public int Id { get; set; }
11
+        public string Suburb { get; set; }
12
+        public string Display { get; set; }
13
+    }
14
+}

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

@@ -1,4 +1,5 @@
1 1
 using Microsoft.EntityFrameworkCore;
2
+
2 3
 using UnivateProperties_API.Model.Communication;
3 4
 using UnivateProperties_API.Model.Users;
4 5
 using UnivateProperties_API.Model.Properties;
@@ -10,14 +11,23 @@ using UnivateProperties_API.Model.Banks;
10 11
 using UnivateProperties_API.Model.Misc;
11 12
 using UnivateProperties_API.Model.ProcessFlow;
12 13
 using UnivateProperties_API.Model.Logging;
14
+using Npgsql;
15
+using System;
13 16
 
14 17
 namespace UnivateProperties_API.Context
15 18
 {
16 19
     public class DataContext : DbContext
17 20
     {
21
+        private string connectionString = "";
18 22
         public DataContext(DbContextOptions<DataContext> options) : base(options)
19 23
         {
20
-
24
+            foreach (var extention in options.Extensions)
25
+            {
26
+                if (extention.GetType().ToString() == "Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal.NpgsqlOptionsExtension")
27
+                {
28
+                    connectionString = ((Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal.NpgsqlOptionsExtension)extention).ConnectionString;
29
+                }
30
+            }
21 31
         }
22 32
 
23 33
         #region User
@@ -72,6 +82,7 @@ namespace UnivateProperties_API.Context
72 82
 
73 83
         #region Misc
74 84
         public DbSet<Location> Location { get; set; }
85
+        public DbSet<Carousel> Carousel { get; set; }
75 86
         #endregion
76 87
 
77 88
         public override int SaveChanges()
@@ -142,6 +153,7 @@ namespace UnivateProperties_API.Context
142 153
             modelBuilder.Entity<User>()
143 154
             .HasIndex(u => u.Username)
144 155
             .IsUnique(true);
156
+           
145 157
             modelBuilder.Entity<Email>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
146 158
             modelBuilder.Entity<SMTPAccount>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
147 159
             modelBuilder.Entity<SMTPHost>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
@@ -168,7 +180,27 @@ namespace UnivateProperties_API.Context
168 180
             modelBuilder.Entity<Address>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
169 181
             modelBuilder.Entity<BidItem>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
170 182
             modelBuilder.Entity<ProcessFlow>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
171
-            modelBuilder.Entity<Template>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
183
+            modelBuilder.Entity<Template>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);            
184
+        }
185
+
186
+    
187
+        public int GetMaxID(string tableName)
188
+        {
189
+            NpgsqlConnection connection = new NpgsqlConnection(connectionString);
190
+            connection.Open();
191
+
192
+            NpgsqlCommand cmd = connection.CreateCommand();
193
+            cmd.CommandText = string.Format("select MAX(\"Id\") from \"{0}\"", tableName);
194
+            NpgsqlDataReader reader = cmd.ExecuteReader();
195
+            int returnValue = 0; 
196
+
197
+            while(reader.Read())
198
+            {
199
+                returnValue = int.Parse(reader[0].ToString());
200
+            }
201
+
202
+            connection.Close();
203
+            return returnValue;
172 204
         }
173 205
     }
174 206
 }

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

@@ -0,0 +1,69 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+using System.Transactions;
6
+using Microsoft.AspNetCore.Http;
7
+using Microsoft.AspNetCore.Mvc;
8
+using UnivateProperties_API.Model.Misc;
9
+using UnivateProperties_API.Repository;
10
+
11
+namespace UnivateProperties_API.Controllers.Misc
12
+{
13
+    [Route("api/[controller]")]
14
+    [ApiController]
15
+    public class CarouselController : ControllerBase
16
+    {
17
+        private readonly IRepository<Carousel> _Repo;
18
+
19
+        public CarouselController(IRepository<Carousel> repo)
20
+        {
21
+            _Repo = repo;
22
+        }
23
+
24
+        [HttpGet]
25
+        public IActionResult Get()
26
+        {
27
+            return new OkObjectResult(_Repo.GetAll());
28
+        }
29
+
30
+        [HttpGet("{id}")]
31
+        public IActionResult Get(int id)
32
+        {
33
+            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
34
+        }        
35
+
36
+        [HttpPost]
37
+        public IActionResult Post([FromBody] Carousel carousel)
38
+        {
39
+            using (var scope = new TransactionScope())
40
+            {
41
+                _Repo.Insert(carousel);
42
+                scope.Complete();
43
+                return CreatedAtAction(nameof(Get), new { id = carousel.Id }, carousel);
44
+            }
45
+        }
46
+
47
+        [HttpPut]
48
+        public IActionResult Put([FromBody] Carousel carousel)
49
+        {
50
+            if (carousel != null)
51
+            {
52
+                using (var scope = new TransactionScope())
53
+                {
54
+                    _Repo.Update(carousel);
55
+                    scope.Complete();
56
+                    return new OkResult();
57
+                }
58
+            }
59
+            return new NoContentResult();
60
+        }
61
+
62
+        [HttpDelete("{id}")]
63
+        public IActionResult Delete(int id)
64
+        {
65
+            _Repo.RemoveAtId(id);
66
+            return new OkResult();
67
+        }
68
+    }
69
+}

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

@@ -49,7 +49,13 @@ namespace UnivateProperties_API.Controllers.Properties
49 49
         {
50 50
             return new OkObjectResult(_Repo.GetPropertyList(type, by));
51 51
         }
52
-        
52
+
53
+        [HttpGet("MayEditProperty/{id}")]
54
+        public IActionResult MayEditProperty(int id)
55
+        {
56
+            return new OkObjectResult(_Repo.MayEdit(id));
57
+        }
58
+
53 59
         #endregion
54 60
 
55 61
         [HttpGet("search")]
@@ -88,7 +94,7 @@ namespace UnivateProperties_API.Controllers.Properties
88 94
                 scope.Complete();
89 95
                 return CreatedAtAction(nameof(Get), new { id = property.Id }, property);
90 96
             }
91
-        }
97
+        }       
92 98
 
93 99
         [HttpPut]
94 100
         public IActionResult Put([FromBody] PropertyContainer property)
@@ -103,7 +109,7 @@ namespace UnivateProperties_API.Controllers.Properties
103 109
                 }
104 110
             }
105 111
             return new NoContentResult();
106
-        }
112
+        }        
107 113
 
108 114
         [HttpDelete("{id}")]
109 115
         public IActionResult Delete(int id)

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

@@ -1,5 +1,6 @@
1 1
 using System.Transactions;
2 2
 using Microsoft.AspNetCore.Mvc;
3
+using UnivateProperties_API.Containers.Property;
3 4
 using UnivateProperties_API.Model.Properties;
4 5
 using UnivateProperties_API.Repository.Properties;
5 6
 
@@ -28,20 +29,26 @@ namespace UnivateProperties_API.Controllers.Properties
28 29
             return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
29 30
         }
30 31
 
31
-        [HttpGet("{Property}/{PropertyId}", Name = "GetImagesByProperty")]
32
-        public IActionResult Get(string Property, int PropertyId) //Property string is more of a placeholder here.
32
+        [HttpGet("GetImagesByProperty/{PropertyId}")]
33
+        public IActionResult GetImagesByProperty(int PropertyId) //Property string is more of a placeholder here.
33 34
         {
34 35
             return new OkObjectResult(_Repo.GetImages(PropertyId));
35 36
         }
36 37
 
38
+        [HttpGet("GetProperySavedImages/{PropertyId}")]
39
+        public IActionResult GetProperySavedImages(int PropertyId) //Property string is more of a placeholder here.
40
+        {
41
+            return new OkObjectResult(_Repo.Get(x => x.PropertyId == PropertyId));
42
+        }
43
+
37 44
         [HttpPost]
38
-        public IActionResult Post([FromBody] PropertyImage propertyImage)
45
+        public IActionResult Post([FromBody] NewPropertyImages propertyImage)
39 46
         {
40 47
             using (var scope = new TransactionScope())
41 48
             {
42
-                _Repo.Insert(propertyImage);
49
+                _Repo.Update(propertyImage);
43 50
                 scope.Complete();
44
-                return CreatedAtAction(nameof(Get), new { id = propertyImage.Id }, propertyImage);
51
+                return new OkResult();
45 52
             }
46 53
         }
47 54
 

+ 6
- 0
UnivateProperties_API/Controllers/Region/CityController.cs Dosyayı Görüntüle

@@ -23,6 +23,12 @@ namespace UnivateProperties_API.Controllers.Region
23 23
             return new OkObjectResult(_Repo.GetAll());
24 24
         }
25 25
 
26
+        [HttpGet("GetByProperty/{id}")]
27
+        public IActionResult GetByProperty(int id)
28
+        {
29
+            return new OkObjectResult(_Repo.GetByProperty(id));
30
+        }
31
+
26 32
         [HttpGet("{id}")]
27 33
         public IActionResult Get(int id)
28 34
         {

+ 12
- 0
UnivateProperties_API/Controllers/Region/SuburbController.cs Dosyayı Görüntüle

@@ -22,6 +22,18 @@ namespace UnivateProperties_API.Controllers.Region
22 22
             return new OkObjectResult(_Repo.GetAll());
23 23
         }
24 24
 
25
+        [HttpGet("GetSearchList")]
26
+        public IActionResult GetSearchList()
27
+        {
28
+            return new OkObjectResult(_Repo.GetSearchList());
29
+        }
30
+
31
+        [HttpGet("GetByProperty/{id}")]
32
+        public IActionResult GetByProperty(int id)
33
+        {
34
+            return new OkObjectResult(_Repo.GetByProperty(id));
35
+        }
36
+
25 37
         [HttpGet("{id}")]
26 38
         public IActionResult Get(int id)
27 39
         {

+ 14
- 0
UnivateProperties_API/Model/Misc/Carousel.cs Dosyayı Görüntüle

@@ -0,0 +1,14 @@
1
+using System.ComponentModel.DataAnnotations.Schema;
2
+using UnivateProperties_API.Model.Properties;
3
+using UnivateProperties_API.Model.Timeshare;
4
+
5
+namespace UnivateProperties_API.Model.Misc
6
+{
7
+    public class Carousel : BaseEntity
8
+    {        
9
+        public int PropertyId { get; set; }        
10
+        public int TimeshareId { get; set; }
11
+        public string Header { get; set; }
12
+        public string Image { get; set; }    
13
+    }
14
+}

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

@@ -0,0 +1,113 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using UnivateProperties_API.Containers.Property;
6
+using UnivateProperties_API.Context;
7
+using UnivateProperties_API.Model.Misc;
8
+
9
+namespace UnivateProperties_API.Repository.Misc
10
+{
11
+    public class CarouselRepository : IRepository<Carousel>
12
+    {
13
+        private readonly DataContext dBContext;
14
+
15
+        public CarouselRepository(DataContext _dBContext)
16
+        {
17
+            dBContext = _dBContext;
18
+        }
19
+
20
+        public List<Carousel> Get(Func<Carousel, bool> where)
21
+        {
22
+            var CarouselList = dBContext.Carousel.Where(where).ToList();
23
+
24
+            foreach (var item in CarouselList)
25
+            {
26
+                if (!string.IsNullOrEmpty(item.Image) && !item.Image.StartsWith("data:image"))
27
+                    item.Image = ImageFormatter.ImageToBase64(item.Image);
28
+            }
29
+
30
+            return CarouselList;
31
+        }
32
+
33
+        public List<Carousel> GetAll()
34
+        {            
35
+            var CarouselList = dBContext.Carousel.ToList();
36
+
37
+            foreach (var item in CarouselList)
38
+            {
39
+                if (!string.IsNullOrEmpty(item.Image) && !item.Image.StartsWith("data:image"))
40
+                    item.Image = ImageFormatter.ImageToBase64(item.Image);
41
+            }
42
+
43
+            return CarouselList;
44
+        }
45
+
46
+        public Carousel GetDetailed(Func<Carousel, bool> first)
47
+        {
48
+            return dBContext.Carousel.FirstOrDefault(first);
49
+        }
50
+
51
+        public List<Carousel> GetDetailedAll()
52
+        {
53
+            return dBContext.Carousel.ToList();
54
+        }
55
+
56
+        public void Insert(Carousel item)
57
+        {
58
+            dBContext.Carousel.Add(item);
59
+            Save();
60
+        }
61
+
62
+        public void Insert(IEnumerable<Carousel> items)
63
+        {
64
+            foreach (var item in items)
65
+            {
66
+                dBContext.Carousel.Add(item);
67
+                Save();
68
+            }
69
+        }
70
+
71
+        public void Remove(Carousel item)
72
+        {
73
+            dBContext.Carousel.Remove(item);
74
+            Save();
75
+        }
76
+
77
+        public void Remove(IEnumerable<Carousel> items)
78
+        {
79
+            foreach (var item in items)
80
+            {
81
+                dBContext.Carousel.Remove(item);
82
+                Save();
83
+            }
84
+        }
85
+
86
+        public void RemoveAtId(int item)
87
+        {
88
+            var Carousel = Get(x => x.Id == item).FirstOrDefault();
89
+            if (Carousel != null)
90
+            {
91
+                dBContext.Carousel.Remove(Carousel);
92
+                Save();
93
+            }
94
+        }
95
+
96
+        public void Save()
97
+        {
98
+            dBContext.SaveChanges();
99
+        }
100
+
101
+        public void Update(Carousel item)
102
+        {
103
+            dBContext.Entry(item).State = EntityState.Modified;
104
+            Save();
105
+        }
106
+
107
+        public int NewId()
108
+        {
109
+            // Not sure if properties need it
110
+            return 0;
111
+        }
112
+    }
113
+}

+ 2
- 0
UnivateProperties_API/Repository/Properties/IPropertyImageRepository.cs Dosyayı Görüntüle

@@ -1,4 +1,5 @@
1 1
 using System.Collections.Generic;
2
+using UnivateProperties_API.Containers.Property;
2 3
 using UnivateProperties_API.Model.Properties;
3 4
 
4 5
 namespace UnivateProperties_API.Repository.Properties
@@ -6,5 +7,6 @@ namespace UnivateProperties_API.Repository.Properties
6 7
     public interface IPropertyImageRepository : IRepository<PropertyImage>
7 8
     {
8 9
         List<string> GetImages(int PropertyId);
10
+        void Update(NewPropertyImages propertyImages);
9 11
     }
10 12
 }

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

@@ -16,5 +16,6 @@ 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 20
     }
20 21
 }

+ 52
- 1
UnivateProperties_API/Repository/Properties/PropertyImageRepository.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.Property;
6 7
 using UnivateProperties_API.Context;
@@ -18,7 +19,15 @@ namespace UnivateProperties_API.Repository.Properties
18 19
         }
19 20
         public List<PropertyImage> Get(Func<PropertyImage, bool> where)
20 21
         {
21
-            return dBContext.PropertyImages.Where(where).ToList();
22
+            var images = dBContext.PropertyImages.Where(where).ToList();
23
+
24
+            foreach (PropertyImage img in images)
25
+            {
26
+                if (!img.Image.StartsWith("data:image"))
27
+                    img.Image = ImageFormatter.ImageToBase64(img.Image);                
28
+            }
29
+
30
+            return images;
22 31
         }
23 32
 
24 33
         public List<PropertyImage> GetAll()
@@ -111,5 +120,47 @@ namespace UnivateProperties_API.Repository.Properties
111 120
             // Not sure if properties need it
112 121
             return 0;
113 122
         }
123
+
124
+        public void Update(NewPropertyImages propertyImages)
125
+        {
126
+            if (propertyImages.Images != null)
127
+            {
128
+                var lastID = dBContext.GetMaxID("PropertyImages");
129
+
130
+                bool saveFiles = false;
131
+                var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
132
+                if (!string.IsNullOrEmpty(loc))
133
+                {
134
+                    saveFiles = true;
135
+                    loc += string.Format("\\{0}", propertyImages.PropertyId);
136
+                    if (Directory.Exists(loc))
137
+                    {
138
+                        Directory.CreateDirectory(loc);
139
+                    }
140
+                }
141
+
142
+                foreach (var image in propertyImages.Images)
143
+                {
144
+                    lastID++;
145
+                    var newImage = new PropertyImage
146
+                    {
147
+                        Id = lastID,
148
+                        PropertyId = propertyImages.PropertyId
149
+                    };
150
+                    if (saveFiles)
151
+                    {
152
+                        string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
153
+                        newImage.Image = path;
154
+                    }
155
+                    else
156
+                    {
157
+                        newImage.Image = image.Image;
158
+                    }
159
+                    dBContext.PropertyImages.Add(newImage);
160
+                }
161
+
162
+                Save();
163
+            }
164
+        }
114 165
     }
115 166
 }

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

@@ -65,7 +65,7 @@ namespace UnivateProperties_API.Repository.Properties
65 65
             property.Province = dBContext.Provinces.Find(property.ProvinceId);
66 66
             property.City = dBContext.Cities.Find(property.CityId);
67 67
             property.Suburb = dBContext.Suburbs.Find(property.SuburbId);
68
-            property.DisplayData = new List<PropertyDetailGroup>();
68
+            property.DisplayData = new List<PropertyDetailGroup>();            
69 69
 
70 70
             if (detailed)
71 71
             {
@@ -145,6 +145,8 @@ namespace UnivateProperties_API.Repository.Properties
145 145
             if (property.AgentId > 0)
146 146
                 propertyDetails.UserId = (dBContext.Agents.Where(p => p.Id == property.AgentId).FirstOrDefault().UserId).Value;
147 147
 
148
+            propertyDetails.NewImages = new List<NewImage>();
149
+
148 150
             return propertyDetails;
149 151
         }
150 152
 
@@ -213,7 +215,98 @@ namespace UnivateProperties_API.Repository.Properties
213 215
                     property[prop] = item[prop];
214 216
             }
215 217
 
216
-            dBContext.Entry(property).State = EntityState.Modified;
218
+            property.PropertyUserFields = null;
219
+            property.PropertyImages = null;
220
+
221
+            dBContext.Entry(property).State = EntityState.Modified;            
222
+
223
+            #region Insert New UDFs
224
+
225
+            var lastFieldID = dBContext.GetMaxID("PropertyUserFields");
226
+
227
+            foreach (var propGroup in item.PropertyOverviewFields)
228
+            {
229
+                foreach (var field in propGroup.Fields)
230
+                {
231
+                    if (field.ItemId == 0)
232
+                    {
233
+                        lastFieldID++;
234
+                        var propertyField = new PropertyUserField()
235
+                        {
236
+                            Id = lastFieldID,
237
+                            PropertyId = property.Id,
238
+                            UserDefinedFieldId = field.Id,
239
+                            Value = field.Value
240
+                        };
241
+                        dBContext.Add(propertyField);                        
242
+                    }
243
+                    else
244
+                    {
245
+                        var propertyField = dBContext.PropertyUserFields.Where(p => p.Id == field.ItemId).FirstOrDefault();
246
+                        if (propertyField != null)
247
+                        {
248
+                            if (string.IsNullOrEmpty(field.Value))
249
+                                propertyField.IsDeleted = true;
250
+                            else
251
+                                propertyField.Value = field.Value;
252
+
253
+                            dBContext.Entry(propertyField).State = EntityState.Modified;                            
254
+                        }
255
+                    }
256
+                }
257
+            }
258
+
259
+            foreach (var propGroup in item.PropertyFields)
260
+            {
261
+                foreach (var field in propGroup.Fields)
262
+                {
263
+                    if (field.ItemId == 0)
264
+                    {
265
+                        lastFieldID++;
266
+                        var propertyField = new PropertyUserField()
267
+                        {
268
+                            Id = lastFieldID,
269
+                            PropertyId = property.Id,
270
+                            UserDefinedFieldId = field.Id,
271
+                            Value = field.Value
272
+                        };
273
+                        dBContext.Add(propertyField);                        
274
+                    }
275
+                    else
276
+                    {
277
+                        var propertyField = dBContext.PropertyUserFields.Where(p => p.Id == field.ItemId).FirstOrDefault();
278
+                        if (propertyField != null)
279
+                        {
280
+                            if (string.IsNullOrEmpty(field.Value))
281
+                                propertyField.IsDeleted = true;
282
+                            else
283
+                                propertyField.Value = field.Value;
284
+
285
+                            dBContext.Entry(propertyField).State = EntityState.Modified;                            
286
+                        }
287
+                    }
288
+                }
289
+            }
290
+            #endregion
291
+
292
+            #region Update Images            
293
+
294
+            if (item.PropertyImages != null)
295
+            {
296
+                foreach (var image in item.PropertyImages)
297
+                {
298
+                    var propImage = dBContext.PropertyImages.Where(pi => pi.Id == image.Id).FirstOrDefault();
299
+                    if (propImage != null)
300
+                    {
301
+                        propImage.IsDefault = image.IsDefault;
302
+                        propImage.IsDeleted = image.IsDeleted;
303
+                        dBContext.Entry(propImage).State = EntityState.Modified;
304
+                    }
305
+                }
306
+            }
307
+
308
+            #endregion 
309
+
217 310
             Save();
218 311
         }
219 312
 
@@ -626,6 +719,16 @@ namespace UnivateProperties_API.Repository.Properties
626 719
                     Save();
627 720
                 }
628 721
             }
629
-        }        
722
+        }
723
+
724
+        public bool MayEdit(int id)
725
+        {
726
+            var hasBidItems = (from b in dBContext.BidItems
727
+                               where b.PropertyId == id
728
+                               && b.StatusId == 2
729
+                               select b).FirstOrDefault();
730
+
731
+            return (hasBidItems == null) ? true : false;
732
+        }                
630 733
     }
631 734
 }

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

@@ -91,7 +91,7 @@ namespace UnivateProperties_API.Repository.Properties
91 91
                     var item = savedValues.Find(x => x.UserDefinedFieldId == field.ID);
92 92
                     if (item != null)
93 93
                     {
94
-                        field.Value = item.Value;
94
+                        field.Value = item.Value ?? "";
95 95
                         field.ItemID = item.Id;
96 96
                     }
97 97
                 }

+ 14
- 0
UnivateProperties_API/Repository/Region/CityRepository.cs Dosyayı Görüntüle

@@ -110,5 +110,19 @@ namespace UnivateProperties_API.Repository.Region
110 110
             id += 1;
111 111
             return id;
112 112
         }
113
+
114
+        public List<City> GetByProperty(int propertyId)
115
+        {
116
+            var prop = dBContext.Properties.Where(p => p.Id == propertyId).FirstOrDefault();
117
+            if (prop != null)
118
+            {
119
+                var Cities = dBContext.Cities.Where(s => s.ProvinceId == prop.ProvinceId).ToList();
120
+                return Cities;
121
+            }
122
+            else
123
+            {
124
+                return null;
125
+            }
126
+        }
113 127
     }
114 128
 }

+ 1
- 0
UnivateProperties_API/Repository/Region/ICityRepository.cs Dosyayı Görüntüle

@@ -6,5 +6,6 @@ namespace UnivateProperties_API.Repository.Region
6 6
     public interface ICityRepository : IRepository<City>
7 7
     {
8 8
         List<City> GetBy(string province);
9
+        List<City> GetByProperty(int propertyId);
9 10
     }
10 11
 }

+ 3
- 0
UnivateProperties_API/Repository/Region/ISuburbRepository.cs Dosyayı Görüntüle

@@ -1,4 +1,5 @@
1 1
 using System.Collections.Generic;
2
+using UnivateProperties_API.Containers.Regions;
2 3
 using UnivateProperties_API.Model.Region;
3 4
 
4 5
 namespace UnivateProperties_API.Repository.Region
@@ -6,5 +7,7 @@ namespace UnivateProperties_API.Repository.Region
6 7
     public interface ISuburbRepository : IRepository<Suburb>
7 8
     {
8 9
         List<Suburb> GetBy(string province, string city);
10
+        List<SuburbSearch> GetSearchList();
11
+        List<Suburb> GetByProperty(int propertyId);
9 12
     }
10 13
 }

+ 33
- 0
UnivateProperties_API/Repository/Region/SuburbRepository.cs Dosyayı Görüntüle

@@ -2,6 +2,7 @@
2 2
 using System;
3 3
 using System.Collections.Generic;
4 4
 using System.Linq;
5
+using UnivateProperties_API.Containers.Regions;
5 6
 using UnivateProperties_API.Context;
6 7
 using UnivateProperties_API.Model.Region;
7 8
 
@@ -111,5 +112,37 @@ namespace UnivateProperties_API.Repository.Region
111 112
             id += 1;
112 113
             return id;
113 114
         }
115
+
116
+        public List<SuburbSearch> GetSearchList()
117
+        {
118
+            var suburbs = dBContext.Suburbs.Include("City").ToList();
119
+            List<SuburbSearch> searchList = new List<SuburbSearch>();
120
+            
121
+            foreach (var sub in suburbs)
122
+            {
123
+                searchList.Add(new SuburbSearch()
124
+                {
125
+                    Id = sub.Id,
126
+                    Suburb = sub.Description,
127
+                    Display = string.Format("{0} - {1}", sub.Description, sub.City.Description)
128
+                });
129
+            }
130
+
131
+            return searchList;
132
+        }
133
+
134
+        public List<Suburb> GetByProperty(int propertyId)
135
+        {
136
+            var prop = dBContext.Properties.Where(p => p.Id == propertyId).FirstOrDefault();
137
+            if (prop != null)
138
+            {
139
+                var Suburbs = dBContext.Suburbs.Where(s => s.CityId == prop.CityId).ToList();
140
+                return Suburbs;
141
+            }
142
+            else
143
+            {
144
+                return null;
145
+            }
146
+        }
114 147
     }
115 148
 }

+ 5
- 0
UnivateProperties_API/Startup.cs Dosyayı Görüntüle

@@ -14,6 +14,7 @@ using UnivateProperties_API.Context;
14 14
 using UnivateProperties_API.Helpers;
15 15
 using UnivateProperties_API.Model.Banks;
16 16
 using UnivateProperties_API.Model.Communication;
17
+using UnivateProperties_API.Model.Misc;
17 18
 using UnivateProperties_API.Model.ProcessFlow;
18 19
 using UnivateProperties_API.Model.Properties;
19 20
 using UnivateProperties_API.Model.Region;
@@ -23,6 +24,7 @@ using UnivateProperties_API.Repository;
23 24
 using UnivateProperties_API.Repository.Banks;
24 25
 using UnivateProperties_API.Repository.Communication;
25 26
 using UnivateProperties_API.Repository.Logging;
27
+using UnivateProperties_API.Repository.Misc;
26 28
 using UnivateProperties_API.Repository.ProccessFlow;
27 29
 using UnivateProperties_API.Repository.Properties;
28 30
 using UnivateProperties_API.Repository.Region;
@@ -141,6 +143,9 @@ namespace UnivateProperties_API
141 143
             #region Logs 
142 144
             services.AddTransient<ISearchLogRepository, SearchLogRepository>();
143 145
             #endregion
146
+            #region Misc
147
+            services.AddTransient<IRepository<Carousel>, CarouselRepository>();
148
+            #endregion
144 149
             services.Configure<MvcOptions>(options =>
145 150
             {
146 151
                 options.Filters.Add(new CorsAuthorizationFilterFactory("MyPolicy"));

+ 1
- 1
UnivateProperties_API/UnivateProperties_API.csproj Dosyayı Görüntüle

@@ -16,7 +16,7 @@
16 16
     <PackageReference Include="Microsoft.AspNetCore.App" />
17 17
     <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
18 18
     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
19
-    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
19
+    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.4" />
20 20
     <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.4" />
21 21
     <PackageReference Include="System.Drawing.Common" Version="4.6.0" />
22 22
   </ItemGroup>

Loading…
İptal
Kaydet