Lene 4年前
コミット
04ec2e435e
21個のファイルの変更6845行の追加81行の削除
  1. 20
    1
      UnivateProperties_API/Containers/Property/PropertyContainer.cs
  2. 1
    0
      UnivateProperties_API/Context/DataContext.cs
  3. 57
    0
      UnivateProperties_API/Controllers/Financial/FeesController.cs
  4. 13
    2
      UnivateProperties_API/Controllers/Properties/PropertyController.cs
  5. 6
    0
      UnivateProperties_API/Controllers/Properties/PropertyFieldsController.cs
  6. 1590
    0
      UnivateProperties_API/Migrations/20200910134303_ListingFees.Designer.cs
  7. 31
    0
      UnivateProperties_API/Migrations/20200910134303_ListingFees.cs
  8. 1592
    0
      UnivateProperties_API/Migrations/20200910135810_ListingFees1.Designer.cs
  9. 23
    0
      UnivateProperties_API/Migrations/20200910135810_ListingFees1.cs
  10. 1592
    0
      UnivateProperties_API/Migrations/20200910140429_ListingFees2.Designer.cs
  11. 17
    0
      UnivateProperties_API/Migrations/20200910140429_ListingFees2.cs
  12. 1598
    0
      UnivateProperties_API/Migrations/20200910140623_ListingFees3.Designer.cs
  13. 43
    0
      UnivateProperties_API/Migrations/20200910140623_ListingFees3.cs
  14. 23
    0
      UnivateProperties_API/Migrations/DataContextModelSnapshot.cs
  15. 11
    0
      UnivateProperties_API/Model/Financial/ListingFee.cs
  16. 57
    0
      UnivateProperties_API/Repository/Financial/ListingRepository.cs
  17. 2
    0
      UnivateProperties_API/Repository/Properties/IPropertyRepository.cs
  18. 2
    0
      UnivateProperties_API/Repository/Properties/IUserDefinedGroupRepository.cs
  19. 127
    78
      UnivateProperties_API/Repository/Properties/PropertyRepository.cs
  20. 39
    0
      UnivateProperties_API/Repository/Properties/UserDefinedGroupRepository.cs
  21. 1
    0
      UnivateProperties_API/Startup.cs

+ 20
- 1
UnivateProperties_API/Containers/Property/PropertyContainer.cs ファイルの表示

@@ -7,7 +7,9 @@ using UnivateProperties_API.Model.Properties;
7 7
 namespace UnivateProperties_API.Containers.Property
8 8
 {
9 9
     public class PropertyContainer : Model.Properties.Property
10
-    {
10
+    {        
11
+        public string StatusString { get; set; }
12
+        public string SalesTypeString { get; set; }
11 13
         public int UserId { get; set; }
12 14
         public string PropertyUsageType { get; set; }
13 15
         public List<NewImage> NewImages { get; set; }
@@ -47,4 +49,21 @@ namespace UnivateProperties_API.Containers.Property
47 49
         public int PropertyId { get; set; }
48 50
         public List<PropertyImage> Images { get; set; }
49 51
     }
52
+
53
+    public class PropertyAdminContainer
54
+    {
55
+        public int Id { get; set; }
56
+        public string Owner { get; set; }
57
+        public string Property { get; set; }
58
+        public string Reference { get; set; }
59
+        public string Unit { get; set; }
60
+        public string Size { get; set; }
61
+        public decimal Price { get; set; }
62
+        public string Region { get; set; }
63
+        public string Town { get; set; }
64
+        public string Suburb { get; set; }
65
+        public string Status { get; set; }
66
+        public string Type { get; set; }
67
+        public bool IsPublished { get; set; }
68
+    }
50 69
 }

+ 1
- 0
UnivateProperties_API/Context/DataContext.cs ファイルの表示

@@ -89,6 +89,7 @@ namespace UnivateProperties_API.Context
89 89
 
90 90
         #region Payments
91 91
         public DbSet<Payment> Payments { get; set; }
92
+        public DbSet<ListingFee> ListingFees { get; set; }
92 93
         #endregion
93 94
 
94 95
         #region Campaign

+ 57
- 0
UnivateProperties_API/Controllers/Financial/FeesController.cs ファイルの表示

@@ -0,0 +1,57 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+using Microsoft.AspNetCore.Http;
6
+using Microsoft.AspNetCore.Mvc;
7
+using UnivateProperties_API.Model.Financial;
8
+using UnivateProperties_API.Repository.Financial;
9
+
10
+namespace UnivateProperties_API.Controllers.Financial
11
+{
12
+    [Route("api/[controller]")]
13
+    [ApiController]
14
+    public class FeesController : ControllerBase
15
+    {
16
+        private readonly IListingRepository _repo;
17
+
18
+        public FeesController(IListingRepository rp)
19
+        {
20
+            _repo = rp;
21
+        }
22
+
23
+        // GET: api/Fees/listingFee
24
+        [HttpGet("listingFee")]
25
+        public IActionResult Get()
26
+        {
27
+            return new OkObjectResult(_repo.GetListingFee());
28
+        }
29
+
30
+        // POST: api/Fees
31
+        [HttpPost("listingFee")]
32
+        public IActionResult Post([FromBody] ListingFee fee)
33
+        {
34
+            var feeObj = _repo.insertListingFee(fee);
35
+            if (feeObj != null)
36
+            {
37
+                return new OkObjectResult(fee);
38
+            }
39
+            else
40
+            {
41
+                return new NoContentResult();
42
+            }
43
+        }
44
+
45
+        // PUT: api/Fees/5
46
+        [HttpPut("{id}")]
47
+        public void Put(int id, [FromBody] string value)
48
+        {
49
+        }
50
+
51
+        // DELETE: api/ApiWithActions/5
52
+        [HttpDelete("{id}")]
53
+        public void Delete(int id)
54
+        {
55
+        }
56
+    }
57
+}

+ 13
- 2
UnivateProperties_API/Controllers/Properties/PropertyController.cs ファイルの表示

@@ -63,6 +63,17 @@ namespace UnivateProperties_API.Controllers.Properties
63 63
             return new OkObjectResult(_Repo.MayEdit(id));
64 64
         }
65 65
 
66
+        [HttpGet("GetAdminProperties/{userId}")]
67
+        public IActionResult GetAdminProperties(int userId)
68
+        {
69
+            return new OkObjectResult(_Repo.GetAdminProperties(userId));
70
+        }
71
+
72
+        [HttpGet("GetPropertyStatuses")]
73
+        public IActionResult GetPropertyStatuses()
74
+        {
75
+            return new OkObjectResult(_Repo.GetStatuses());
76
+        }
66 77
         #endregion
67 78
 
68 79
         [HttpGet("search")]
@@ -125,14 +136,14 @@ namespace UnivateProperties_API.Controllers.Properties
125 136
         }
126 137
         
127 138
         [HttpPut("PublishProperty")]
128
-        public IActionResult PublishProperty([FromBody] PropertyDisplay property)
139
+        public IActionResult PublishProperty([FromBody] PropertyAdminContainer property)
129 140
         {
130 141
             _Repo.PublishProperty(property.Id);
131 142
             return new NoContentResult();
132 143
         }
133 144
 
134 145
         [HttpPut("UnpublishProperty")]
135
-        public IActionResult UnpublishProperty(PropertyDisplay property)
146
+        public IActionResult UnpublishProperty(PropertyAdminContainer property)
136 147
         {
137 148
             _Repo.UnpublishProperty(property.Id);
138 149
             return new NoContentResult();

+ 6
- 0
UnivateProperties_API/Controllers/Properties/PropertyFieldsController.cs ファイルの表示

@@ -37,6 +37,12 @@ namespace UnivateProperties_API.Controllers.Properties
37 37
         {
38 38
             return new OkObjectResult(_Repo.GetFieldList(propertyType, name, id));
39 39
         }
40
+
41
+        [HttpGet("GetSavedPropertyUserFields/{id}")]
42
+        public IActionResult GetSavedPropertyUserFields(int id)
43
+        {
44
+            return new OkObjectResult(_Repo.GetSavedList(id));
45
+        }
40 46
     }
41 47
 
42 48
 

+ 1590
- 0
UnivateProperties_API/Migrations/20200910134303_ListingFees.Designer.cs
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 31
- 0
UnivateProperties_API/Migrations/20200910134303_ListingFees.cs ファイルの表示

@@ -0,0 +1,31 @@
1
+using Microsoft.EntityFrameworkCore.Metadata;
2
+using Microsoft.EntityFrameworkCore.Migrations;
3
+
4
+namespace UnivateProperties_API.Migrations
5
+{
6
+    public partial class ListingFees : Migration
7
+    {
8
+        protected override void Up(MigrationBuilder migrationBuilder)
9
+        {
10
+            migrationBuilder.CreateTable(
11
+                name: "ListingFees",
12
+                columns: table => new
13
+                {
14
+                    Id = table.Column<int>(nullable: false)
15
+                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
16
+                    Amount = table.Column<double>(nullable: false),
17
+                    Name = table.Column<string>(nullable: true)
18
+                },
19
+                constraints: table =>
20
+                {
21
+                    table.PrimaryKey("PK_ListingFees", x => x.Id);
22
+                });
23
+        }
24
+
25
+        protected override void Down(MigrationBuilder migrationBuilder)
26
+        {
27
+            migrationBuilder.DropTable(
28
+                name: "ListingFees");
29
+        }
30
+    }
31
+}

+ 1592
- 0
UnivateProperties_API/Migrations/20200910135810_ListingFees1.Designer.cs
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 23
- 0
UnivateProperties_API/Migrations/20200910135810_ListingFees1.cs ファイルの表示

@@ -0,0 +1,23 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class ListingFees1 : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+            migrationBuilder.AddColumn<bool>(
10
+                name: "IsDeleted",
11
+                table: "ListingFees",
12
+                nullable: false,
13
+                defaultValue: false);
14
+        }
15
+
16
+        protected override void Down(MigrationBuilder migrationBuilder)
17
+        {
18
+            migrationBuilder.DropColumn(
19
+                name: "IsDeleted",
20
+                table: "ListingFees");
21
+        }
22
+    }
23
+}

+ 1592
- 0
UnivateProperties_API/Migrations/20200910140429_ListingFees2.Designer.cs
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 17
- 0
UnivateProperties_API/Migrations/20200910140429_ListingFees2.cs ファイルの表示

@@ -0,0 +1,17 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class ListingFees2 : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+
10
+        }
11
+
12
+        protected override void Down(MigrationBuilder migrationBuilder)
13
+        {
14
+
15
+        }
16
+    }
17
+}

+ 1598
- 0
UnivateProperties_API/Migrations/20200910140623_ListingFees3.Designer.cs
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 43
- 0
UnivateProperties_API/Migrations/20200910140623_ListingFees3.cs ファイルの表示

@@ -0,0 +1,43 @@
1
+using System;
2
+using Microsoft.EntityFrameworkCore.Migrations;
3
+
4
+namespace UnivateProperties_API.Migrations
5
+{
6
+    public partial class ListingFees3 : Migration
7
+    {
8
+        protected override void Up(MigrationBuilder migrationBuilder)
9
+        {
10
+            migrationBuilder.AddColumn<DateTime>(
11
+                name: "Created",
12
+                table: "ListingFees",
13
+                nullable: false,
14
+                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
15
+
16
+            migrationBuilder.AddColumn<DateTime>(
17
+                name: "Modified",
18
+                table: "ListingFees",
19
+                nullable: false,
20
+                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
21
+
22
+            migrationBuilder.AddColumn<string>(
23
+                name: "ModifiedBy",
24
+                table: "ListingFees",
25
+                nullable: true);
26
+        }
27
+
28
+        protected override void Down(MigrationBuilder migrationBuilder)
29
+        {
30
+            migrationBuilder.DropColumn(
31
+                name: "Created",
32
+                table: "ListingFees");
33
+
34
+            migrationBuilder.DropColumn(
35
+                name: "Modified",
36
+                table: "ListingFees");
37
+
38
+            migrationBuilder.DropColumn(
39
+                name: "ModifiedBy",
40
+                table: "ListingFees");
41
+        }
42
+    }
43
+}

+ 23
- 0
UnivateProperties_API/Migrations/DataContextModelSnapshot.cs ファイルの表示

@@ -352,6 +352,29 @@ namespace UnivateProperties_API.Migrations
352 352
                     b.ToTable("Templates");
353 353
                 });
354 354
 
355
+            modelBuilder.Entity("UnivateProperties_API.Model.Financial.ListingFee", b =>
356
+                {
357
+                    b.Property<int>("Id")
358
+                        .ValueGeneratedOnAdd()
359
+                        .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
360
+
361
+                    b.Property<double>("Amount");
362
+
363
+                    b.Property<DateTime>("Created");
364
+
365
+                    b.Property<bool>("IsDeleted");
366
+
367
+                    b.Property<DateTime>("Modified");
368
+
369
+                    b.Property<string>("ModifiedBy");
370
+
371
+                    b.Property<string>("Name");
372
+
373
+                    b.HasKey("Id");
374
+
375
+                    b.ToTable("ListingFees");
376
+                });
377
+
355 378
             modelBuilder.Entity("UnivateProperties_API.Model.Financial.Payment", b =>
356 379
                 {
357 380
                     b.Property<int>("Id")

+ 11
- 0
UnivateProperties_API/Model/Financial/ListingFee.cs ファイルの表示

@@ -0,0 +1,11 @@
1
+using System.ComponentModel.DataAnnotations;
2
+using System.ComponentModel.DataAnnotations.Schema;
3
+
4
+namespace UnivateProperties_API.Model.Financial
5
+{
6
+    public class ListingFee : BaseEntity
7
+    {
8
+        public double Amount {get; set;}
9
+        public string Name { get; set; }
10
+    }
11
+}

+ 57
- 0
UnivateProperties_API/Repository/Financial/ListingRepository.cs ファイルの表示

@@ -0,0 +1,57 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+using UnivateProperties_API.Context;
6
+using UnivateProperties_API.Model.Financial;
7
+
8
+namespace UnivateProperties_API.Repository.Financial
9
+{
10
+    public interface IListingRepository
11
+    {
12
+        ListingFee insertListingFee(ListingFee fee);
13
+        ListingFee GetListingFee();
14
+    }
15
+
16
+    public class ListingRepository : IListingRepository
17
+    {
18
+        private readonly DataContext _dbContext;
19
+
20
+        public ListingRepository(DataContext db)
21
+        {
22
+            _dbContext = db;
23
+        }
24
+
25
+        public ListingFee insertListingFee(ListingFee fee)
26
+        {
27
+            var hasFee = _dbContext.ListingFees.FirstOrDefault();
28
+            if (fee != null)
29
+            {
30
+                if (hasFee == null)
31
+                {
32
+                    _dbContext.ListingFees.Add(fee);
33
+                    _dbContext.SaveChanges();
34
+                    return fee;
35
+                }
36
+                else
37
+                {
38
+                    fee.Id = 1;
39
+                    _dbContext.ListingFees.Update(fee);
40
+                    _dbContext.SaveChanges();
41
+                    return fee;
42
+                }
43
+                
44
+            }
45
+            else
46
+            {
47
+                return null;
48
+            }
49
+            
50
+        }
51
+
52
+        public ListingFee GetListingFee()
53
+        {
54
+            return _dbContext.ListingFees.FirstOrDefault();
55
+        }
56
+    }
57
+}

+ 2
- 0
UnivateProperties_API/Repository/Properties/IPropertyRepository.cs ファイルの表示

@@ -14,6 +14,8 @@ namespace UnivateProperties_API.Repository.Properties
14 14
         List<PropertyType> GetPropertyTypes(Func<PropertyType, bool> where);
15 15
         List<PropertyList> GetPropertyList(int By);
16 16
         List<PropertyList> GetPropertyList();
17
+        List<PropertyAdminContainer> GetAdminProperties(int UserId);
18
+        List<string> GetStatuses();
17 19
         void Insert(PropertyContainer items);
18 20
         PropertyContainer GetDetailed(int id, bool detailed);
19 21
         void Update(PropertyContainer item);

+ 2
- 0
UnivateProperties_API/Repository/Properties/IUserDefinedGroupRepository.cs ファイルの表示

@@ -11,5 +11,7 @@ namespace UnivateProperties_API.Repository.Properties
11 11
         List<Group> GetFieldList(string propertyType, string name, int propertyID);
12 12
 
13 13
         List<Group> GetFieldListByPropType(string propertyType);
14
+
15
+        List<Group> GetSavedList(int PropertyId);
14 16
     }
15 17
 }

+ 127
- 78
UnivateProperties_API/Repository/Properties/PropertyRepository.cs ファイルの表示

@@ -27,10 +27,7 @@ namespace UnivateProperties_API.Repository.Properties
27 27
         public List<Property> Get(Func<Property, bool> where)
28 28
         {
29 29
             return dBContext.Properties
30
-                .Include("PropertyType")
31
-                .Include("Province")
32
-                .Include("City")
33
-                .Include("Suburb")
30
+                .Include("PropertyType")                
34 31
                 .Where(where).ToList();
35 32
         }
36 33
 
@@ -145,11 +142,16 @@ namespace UnivateProperties_API.Repository.Properties
145 142
 
146 143
             var propertyDetails = new PropertyContainer();
147 144
 
145
+            propertyDetails.SalesTypeString = property.IsSale ? "Sale" : "Rental";            
146
+
148 147
             foreach (string prop in property.GetAllProperties())
149 148
             {
150 149
                 if (prop != "Item" && prop != "Display")
151 150
                     propertyDetails[prop] = property[prop];
152
-            }            
151
+            }
152
+
153
+            if (property.StatusId != null)
154
+                propertyDetails.StatusString = dBContext.Status.Where(s => s.Id == property.StatusId).FirstOrDefault()?.Description;
153 155
 
154 156
             propertyDetails.PropertyUsageType = propertyType.UsageType == PropertyUsageType.Commercial ? "Commercial" : "Residential";
155 157
 
@@ -209,7 +211,7 @@ namespace UnivateProperties_API.Repository.Properties
209 211
 
210 212
         public void Update(Property item)
211 213
         {
212
-            if (item.Video.StartsWith("http"))
214
+            if (!string.IsNullOrEmpty(item.Video) && item.Video.StartsWith("http"))
213 215
                 item.Video = item.Video.Replace("https://www.youtube.com/watch?v=", "");
214 216
 
215 217
             dBContext.Entry(item).State = EntityState.Modified;
@@ -218,7 +220,7 @@ namespace UnivateProperties_API.Repository.Properties
218 220
 
219 221
         public void Update(PropertyContainer item)
220 222
         {
221
-            if (item.Video.StartsWith("http"))
223
+            if (!string.IsNullOrEmpty(item.Video) && item.Video.StartsWith("http"))
222 224
                 item.Video = item.Video.Replace("https://www.youtube.com/watch?v=", "");
223 225
 
224 226
             var property = new Property();
@@ -231,84 +233,82 @@ namespace UnivateProperties_API.Repository.Properties
231 233
             property.PropertyUserFields = null;
232 234
             property.PropertyImages = null;
233 235
 
236
+            if (!string.IsNullOrEmpty(item.StatusString))
237
+            {
238
+                property.StatusId = dBContext.Status.Where(s => s.Description == item.StatusString && s.StatusType == StatusType.Property).FirstOrDefault()?.Id;
239
+            }
240
+
234 241
             dBContext.Entry(property).State = EntityState.Modified;            
235 242
 
236 243
             #region Insert New UDFs
237
-
238
-            foreach (var propGroup in item.PropertyOverviewFields)
244
+          
245
+            foreach (var propGroup in item.PropertyFields)
239 246
             {
240 247
                 foreach (var field in propGroup.Fields)
241 248
                 {
242
-                    if (field.ItemId == 0)
243
-                    {                        
244
-                        var propertyField = new PropertyUserField()
245
-                        {                            
246
-                            PropertyId = property.Id,
247
-                            UserDefinedFieldId = field.Id,
248
-                            Value = field.Value
249
-                        };
250
-                        dBContext.Add(propertyField);                        
251
-                    }
252
-                    else
249
+                    if (field.Value != null)
253 250
                     {
254
-                        var propertyField = dBContext.PropertyUserFields.Where(p => p.Id == field.ItemId).FirstOrDefault();
255
-                        if (propertyField != null)
251
+                        var propField = dBContext.PropertyUserFields.Where(u => u.PropertyId == property.Id && u.UserDefinedFieldId == field.Id).FirstOrDefault();
252
+                        if (propField == null)
256 253
                         {
257
-                            if (string.IsNullOrEmpty(field.Value))
258
-                                propertyField.IsDeleted = true;
259
-                            else
260
-                                propertyField.Value = field.Value;
261
-
262
-                            dBContext.Entry(propertyField).State = EntityState.Modified;                            
254
+                            propField = new PropertyUserField()
255
+                            {
256
+                                PropertyId = property.Id,
257
+                                UserDefinedFieldId = field.Id,
258
+                                Value = field.Value
259
+                            };
260
+                            dBContext.Add(propField);
263 261
                         }
264
-                    }
265
-                }
266
-            }
267
-
268
-            foreach (var propGroup in item.PropertyFields)
269
-            {
270
-                foreach (var field in propGroup.Fields)
271
-                {
272
-                    if (field.ItemId == 0)
273
-                    {                        
274
-                        var propertyField = new PropertyUserField()
275
-                        {                            
276
-                            PropertyId = property.Id,
277
-                            UserDefinedFieldId = field.Id,
278
-                            Value = field.Value
279
-                        };
280
-                        dBContext.Add(propertyField);                        
281
-                    }
282
-                    else
283
-                    {
284
-                        var propertyField = dBContext.PropertyUserFields.Where(p => p.Id == field.ItemId).FirstOrDefault();
285
-                        if (propertyField != null)
262
+                        else
286 263
                         {
287
-                            if (string.IsNullOrEmpty(field.Value))
288
-                                propertyField.IsDeleted = true;
289
-                            else
290
-                                propertyField.Value = field.Value;
291
-
292
-                            dBContext.Entry(propertyField).State = EntityState.Modified;                            
264
+                            propField.Value = field.Value;
265
+                            dBContext.Entry(propField).State = EntityState.Modified;
293 266
                         }
294
-                    }
267
+                    }                    
295 268
                 }
296 269
             }
297 270
             #endregion
298 271
 
299 272
             #region Update Images            
300 273
 
301
-            if (item.PropertyImages != null)
274
+            if (item.NewImages != null)
302 275
             {
303
-                foreach (var image in item.PropertyImages)
276
+                var imgList = dBContext.PropertyImages.Where(p => p.PropertyId == property.Id).ToList();
277
+                foreach (var image in imgList)
278
+                {
279
+                    dBContext.Remove(image);
280
+                }
281
+
282
+                bool saveFiles = false;
283
+                var loc = dBContext.Location.FirstOrDefault()?.PropertyImageLocation;
284
+                if (!string.IsNullOrEmpty(loc))
304 285
                 {
305
-                    var propImage = dBContext.PropertyImages.Where(pi => pi.Id == image.Id).FirstOrDefault();
306
-                    if (propImage != null)
286
+                    saveFiles = true;
287
+                    loc += string.Format("\\{0}", property.Id);
288
+                    if (Directory.Exists(loc))
307 289
                     {
308
-                        propImage.IsDefault = image.IsDefault;
309
-                        propImage.IsDeleted = image.IsDeleted;
310
-                        dBContext.Entry(propImage).State = EntityState.Modified;
290
+                        Directory.CreateDirectory(loc);
291
+                    }
292
+                }
293
+
294
+                property.PropertyImages = new List<PropertyImage>();
295
+                var lastID = dBContext.PropertyImages.Max(i => i.Id) + 1;
296
+                foreach (var image in item.NewImages)
297
+                {
298
+                    var propImage = new PropertyImage
299
+                    {
300
+                        PropertyId = property.Id,
301
+                        Image = image.Image,
302
+                        IsDefault = image.IsDefault
303
+                    };
304
+
305
+                    if (saveFiles)
306
+                    {
307
+                        string path = ImageFormatter.Base64ToImage(propImage.Image, loc, lastID.ToString());
308
+                        propImage.Image = path;
311 309
                     }
310
+                    property.PropertyImages.Add(propImage);
311
+                    lastID++;
312 312
                 }
313 313
             }
314 314
 
@@ -502,8 +502,7 @@ namespace UnivateProperties_API.Repository.Properties
502 502
         private List<PropertyDisplay> GetDisplayDetails(List<Property> props)
503 503
         {
504 504
             var properties = new List<PropertyDisplay>();
505
-            //Removed publish check for now
506
-            //props = props.Where(p => p.Published).ToList();
505
+            props = props.Where(p => p.Published).ToList();
507 506
             foreach (var item in props)
508 507
             {
509 508
                 PropertyDisplay display = new PropertyDisplay
@@ -583,9 +582,7 @@ namespace UnivateProperties_API.Repository.Properties
583 582
 
584 583
         public List<PropertyDisplay> GetLatestDisplay()
585 584
         {
586
-            //Removed Published Check for now
587
-            //List<Property> props = GetAll().Where(x => x.Published).OrderByDescending(x => x.DatePublished).Take(3).ToList();
588
-            List<Property> props = GetAll().OrderByDescending(x => x.Created).Take(3).ToList();
585
+            List<Property> props = GetAll().Where(x => x.Published).OrderByDescending(x => x.DatePublished).Take(3).ToList();
589 586
             return GetDisplayDetails(props);
590 587
         }
591 588
 
@@ -621,10 +618,8 @@ namespace UnivateProperties_API.Repository.Properties
621 618
         }
622 619
 
623 620
         public List<PropertyList> GetPropertyList()
624
-        {
625
-            //Removed Published check for now
626
-            //return SetPropertyList(dBContext.Properties.Where(x => x.Published).ToList());
627
-            return SetPropertyList(dBContext.Properties.ToList());
621
+        {           
622
+            return SetPropertyList(dBContext.Properties.Where(x => x.Published).ToList());
628 623
         }
629 624
 
630 625
         private List<PropertyList> SetPropertyList(List<Property> properties)
@@ -708,8 +703,7 @@ namespace UnivateProperties_API.Repository.Properties
708 703
             items.PropertyUserFields = null;
709 704
 
710 705
             var individual = dBContext.Individuals.Where(i => i.UserId == items.UserId).FirstOrDefault();
711
-            var agent = dBContext.Agents.Where(a => a.UserId == items.UserId).FirstOrDefault();
712
-            var status = dBContext.Status.Where(a => a.Code == "P1").FirstOrDefault();
706
+            var agent = dBContext.Agents.Where(a => a.UserId == items.UserId).FirstOrDefault();            
713 707
 
714 708
             foreach( string prop in property.GetAllProperties())
715 709
             {
@@ -725,8 +719,10 @@ namespace UnivateProperties_API.Repository.Properties
725 719
                 property.AgentId = agent.Id;
726 720
             }            
727 721
 
728
-            if (status != null)
729
-                property.StatusId = status.Id;
722
+            if (property.IsSale)            
723
+                property.StatusId = dBContext.Status.Where(s => s.Description == "For Sale" && s.StatusType == StatusType.Property).FirstOrDefault()?.Id;
724
+            else
725
+                property.StatusId = dBContext.Status.Where(s => s.Description == "For Rent" && s.StatusType == StatusType.Property).FirstOrDefault()?.Id;
730 726
 
731 727
             if (!string.IsNullOrEmpty(property.Video))
732 728
                 property.Video = property.Video.Replace("https://www.youtube.com/watch?v=", "");
@@ -844,6 +840,59 @@ namespace UnivateProperties_API.Repository.Properties
844 840
                 property.DatePublished = DateTime.MinValue;
845 841
                 Update(property);
846 842
             }
847
-        }        
843
+        }
844
+
845
+        public List<PropertyAdminContainer> GetAdminProperties(int UserId)
846
+        {
847
+            var user = dBContext.Users.Where(u => u.Id == UserId).FirstOrDefault();
848
+            List<PropertyAdminContainer> returnProps = new List<PropertyAdminContainer>();
849
+            List<Property> props;
850
+            if ((user.Role.ToUpper() == "SUPER ADMIN"))
851
+            {
852
+                props = dBContext.Properties.Include("Owner").Include("PropertyType").ToList();
853
+            }
854
+            else
855
+            {
856
+                var indiv = dBContext.Individuals.Where(i => i.UserId == user.Id).FirstOrDefault();
857
+                props = dBContext.Properties.Include("Owner").Include("PropertyType").Where(p => p.OwnerId == indiv.Id).ToList();
858
+            }
859
+
860
+            foreach (var prop in props)
861
+            {
862
+                var propAdmin = new PropertyAdminContainer()
863
+                {
864
+                    Id = prop.Id,
865
+                    Owner = prop.Owner?.FullName,
866
+                    Property = prop.PropertyName,
867
+                    Reference = prop.PropertyRef,
868
+                    Unit = prop.Unit,
869
+                    Size = (from u in dBContext.PropertyUserFields
870
+                            join f in dBContext.UserDefinedFields on u.UserDefinedFieldId equals f.Id
871
+                            where u.PropertyId == prop.Id
872
+                            && f.FieldName == "Floor Size"
873
+                            select u.Value).FirstOrDefault(),
874
+                    Price = prop.Price,
875
+                    Region = prop.Province,
876
+                    Town = prop.City,
877
+                    Suburb = prop.Suburb,
878
+                    IsPublished = prop.Published,
879
+                    Type = prop.PropertyType.UsageType.ToString()
880
+                };
881
+                
882
+                if (prop.StatusId != null)
883
+                {
884
+                    propAdmin.Status = dBContext.Status.Where(s => s.Id == prop.StatusId).FirstOrDefault()?.Description;
885
+                }
886
+
887
+                returnProps.Add(propAdmin);
888
+            }
889
+
890
+            return returnProps;
891
+        }
892
+
893
+        public List<string> GetStatuses()
894
+        {
895
+            return dBContext.Status.Where(s => s.StatusType == StatusType.Property).Select(s => s.Description).ToList();
896
+        }
848 897
     }
849 898
 }

+ 39
- 0
UnivateProperties_API/Repository/Properties/UserDefinedGroupRepository.cs ファイルの表示

@@ -201,5 +201,44 @@ namespace UnivateProperties_API.Repository.Properties
201 201
             // Not sure if properties need it
202 202
             return 0;
203 203
         }
204
+
205
+        public List<Group> GetSavedList(int PropertyId)
206
+        {
207
+            var prop = dBContext.Properties.Include("PropertyType").Where(p => p.Id == PropertyId).FirstOrDefault();
208
+            var all = GetFieldListByPropType(prop.PropertyType.PropertyUsageType);
209
+
210
+            var groups = (from g in dBContext.UserDefinedGroups
211
+                          where g.UsageType == prop.PropertyType.UsageType
212
+                          || g.UsageType == PropertyUsageType.Both
213
+                          orderby g.Rank
214
+                          select g).ToList();
215
+
216
+            foreach (UserDefinedGroup uGroup in groups)
217
+            {
218
+                var groupFields = (from f in dBContext.PropertyUserFields
219
+                                   join uf in dBContext.UserDefinedFields on f.UserDefinedFieldId equals uf.Id
220
+                                   join g in dBContext.UserDefinedGroups on uf.GroupId equals g.Id
221
+                                   where f.PropertyId == PropertyId
222
+                                   && g.Id == uGroup.Id
223
+                                   orderby g.Rank, uf.Rank
224
+                                   select new { uf.FieldName, f.Value, f.Description }).ToList();
225
+
226
+                foreach (var val in groupFields)
227
+                {
228
+                    foreach (var iGroup in all)
229
+                    {
230
+                        foreach (var field in iGroup.Fields)
231
+                        {
232
+                            if (field.Name == val.FieldName)
233
+                            {
234
+                                field.Value = val.Value;
235
+                            }
236
+                        }
237
+                    }
238
+                }
239
+            }
240
+
241
+            return all;
242
+        }
204 243
     }
205 244
 }

+ 1
- 0
UnivateProperties_API/Startup.cs ファイルの表示

@@ -158,6 +158,7 @@ namespace UnivateProperties_API
158 158
             #endregion
159 159
             #region Financial 
160 160
             services.AddTransient<IPaygateRepository, PaygateRepository>();
161
+            services.AddTransient<IListingRepository, ListingRepository>(); 
161 162
             #endregion
162 163
             #region Misc
163 164
             services.AddTransient<ICarouselRepository, CarouselRepository>();

読み込み中…
キャンセル
保存