Просмотр исходного кода

Added campaign landing pages

master
30117125 3 лет назад
Родитель
Сommit
19798bb9ec

+ 5
- 1
.gitignore Просмотреть файл

@@ -337,4 +337,8 @@ ASALocalRun/
337 337
 .localhistory/
338 338
 
339 339
 # BeatPulse healthcheck temp database
340
-healthchecksdb
340
+healthchecksdb
341
+/UnivateProperties_API/Migrations/20210407084329_campaignProperties.cs
342
+/UnivateProperties_API/Migrations/20210407084329_campaignProperties.Designer.cs
343
+/UnivateProperties_API/Migrations/20210407091039_campaignProperties1.cs
344
+/UnivateProperties_API/Migrations/20210407091039_campaignProperties1.Designer.cs

+ 1
- 0
UnivateProperties_API/Context/DataContext.cs Просмотреть файл

@@ -105,6 +105,7 @@ namespace UnivateProperties_API.Context
105 105
         public DbSet<CampaignItem> CampaignItems { get; set; }  
106 106
         public DbSet<CampaignPlaceHolder> CampaignPlaceHolders { get; set; }
107 107
         public DbSet<CampaignItemPlaceHolder> CampaignItemPlaceHolders { get; set; }
108
+        public DbSet<UploadCampaign> CampaignUploads { get; set; }
108 109
         #endregion
109 110
 
110 111
         public override int SaveChanges()

+ 65
- 2
UnivateProperties_API/Controllers/Campaigns/CampaignController.cs Просмотреть файл

@@ -1,5 +1,11 @@
1
-using Microsoft.AspNetCore.Mvc;
1
+using Microsoft.AspNetCore.Http;
2
+using Microsoft.AspNetCore.Mvc;
3
+using System;
2 4
 using System.Collections.Generic;
5
+using System.IO;
6
+using System.Linq;
7
+using System.Net;
8
+using System.Threading.Tasks;
3 9
 using System.Transactions;
4 10
 using UnivateProperties_API.Containers.Campaigns;
5 11
 using UnivateProperties_API.Model.Campaigns;
@@ -66,7 +72,57 @@ namespace UnivateProperties_API.Controllers.Campaigns
66 72
                 return CreatedAtAction(nameof(Get), new { id = campaign.Id }, campaign);
67 73
             }
68 74
         }
69
-        
75
+
76
+        [HttpPost("FileUpload")]
77
+        public async Task<IActionResult> Post(IFormCollection files)
78
+        {
79
+            //string url = "http://localhost:8080";
80
+            //string url = "http://training.provision-sa.com:122";
81
+            string url = "https://www.univateproperties.co.za";
82
+            string fileName = "";
83
+            try
84
+            {
85
+                long size = files.Files.Sum(f => f.Length);
86
+                //string path = Path.Combine(@"C:\Users\7675\Desktop", "Uploads");
87
+                //string path = Path.Combine(@"C:\inetpub\wwwroot\UniVatePropertiesNew", "lp");
88
+                string path = Path.Combine(@"C:\inetpub\wwwroot\UniVateProperties", "lp");
89
+                foreach (var formFile in files.Files)
90
+                {
91
+                    if (formFile.Length > 0)
92
+                    {
93
+                        fileName = formFile.FileName;
94
+                        string fullPath = Path.Combine(path, fileName);
95
+                        using (var stream = new FileStream(fullPath, FileMode.Create))
96
+                        {
97
+                            await formFile.CopyToAsync(stream);
98
+                        }
99
+                    }
100
+                }
101
+                UploadCampaign camp = new UploadCampaign();
102
+                camp.FileName = fileName;
103
+                camp.FileLink = url + "/lp/" + fileName;
104
+                _Repo.addUploadCampaign(camp);
105
+
106
+                return Ok(new
107
+                {
108
+                    archives = files.Files.Count,
109
+                    link = url + "/lp/" + fileName,
110
+                    size,
111
+                    path
112
+                });
113
+            }
114
+            catch (Exception ex)
115
+            {
116
+                return StatusCode((int)HttpStatusCode.InternalServerError, ex);
117
+            }
118
+        }
119
+
120
+        [HttpGet("GetUploaded")]
121
+        public IActionResult GetUploaded()
122
+        {
123
+            return new OkObjectResult(_Repo.GetUploadedCampaigns());
124
+        }
125
+
70 126
         [HttpPut]
71 127
         public IActionResult Put(Campaign campaign)
72 128
         {
@@ -82,6 +138,13 @@ namespace UnivateProperties_API.Controllers.Campaigns
82 138
             return new NoContentResult();
83 139
         }
84 140
 
141
+        [HttpDelete("DeleteUploaded/{id}")]
142
+        public IActionResult DeleteUploaded(int id)
143
+        {
144
+            _Repo.RemoveUploadedAtId(id);
145
+            return new OkResult();
146
+        }
147
+
85 148
         [HttpDelete("{id}")]
86 149
         public IActionResult Delete(int id)
87 150
         {

+ 4
- 1
UnivateProperties_API/Controllers/InfoController.cs Просмотреть файл

@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http;
6 6
 using Microsoft.AspNetCore.Mvc;
7 7
 using UnivateProperties_API.Containers.Info;
8 8
 using UnivateProperties_API.Model;
9
+using UnivateProperties_API.Model.Properties;
9 10
 
10 11
 namespace UnivateProperties_API.Controllers
11 12
 {
@@ -39,11 +40,13 @@ namespace UnivateProperties_API.Controllers
39 40
                 .Assembly.GetTypes()
40 41
                 .Where(t => t.IsSubclassOf(typeof(BaseEntity)) && !t.IsAbstract)
41 42
                 .Select(t => (BaseEntity)Activator.CreateInstance(t));
42
-            foreach(var item in exporters)
43
+            foreach (var item in exporters)
43 44
             {
44 45
                 ClassDto cls = new ClassDto();
45 46
                 list.Add(new ClassDto() { FullName = item.GetType().FullName.ToString(), Name = item.GetType().Name });
46 47
             }
48
+
49
+
47 50
             return list;
48 51
         }
49 52
     }

+ 1804
- 0
UnivateProperties_API/Migrations/20210409063434_campaignType.Designer.cs
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 37
- 0
UnivateProperties_API/Migrations/20210409063434_campaignType.cs Просмотреть файл

@@ -0,0 +1,37 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class campaignType : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+            migrationBuilder.AddColumn<bool>(
10
+                name: "IsTimeshare",
11
+                table: "Campaigns",
12
+                nullable: false,
13
+                defaultValue: false);
14
+
15
+            migrationBuilder.CreateIndex(
16
+                name: "IX_CampaignItems_PropertyId",
17
+                table: "CampaignItems",
18
+                column: "PropertyId");
19
+
20
+        }
21
+
22
+        protected override void Down(MigrationBuilder migrationBuilder)
23
+        {
24
+            migrationBuilder.DropForeignKey(
25
+                name: "FK_CampaignItems_Properties_PropertyId",
26
+                table: "CampaignItems");
27
+
28
+            migrationBuilder.DropIndex(
29
+                name: "IX_CampaignItems_PropertyId",
30
+                table: "CampaignItems");
31
+
32
+            migrationBuilder.DropColumn(
33
+                name: "IsTimeshare",
34
+                table: "Campaigns");
35
+        }
36
+    }
37
+}

+ 1825
- 0
UnivateProperties_API/Migrations/20210413100140_uploadcampaign.Designer.cs
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 35
- 0
UnivateProperties_API/Migrations/20210413100140_uploadcampaign.cs Просмотреть файл

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

+ 1827
- 0
UnivateProperties_API/Migrations/20210413105321_uploadcampaign1.Designer.cs
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 22
- 0
UnivateProperties_API/Migrations/20210413105321_uploadcampaign1.cs Просмотреть файл

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

+ 84
- 0
UnivateProperties_API/Migrations/DataContextModelSnapshot.cs Просмотреть файл

@@ -87,6 +87,8 @@ namespace UnivateProperties_API.Migrations
87 87
 
88 88
                     b.Property<bool>("IsDeleted");
89 89
 
90
+                    b.Property<bool>("IsTimeshare");
91
+
90 92
                     b.Property<string>("ItemBody");
91 93
 
92 94
                     b.Property<int>("ItemsPerRow");
@@ -124,12 +126,16 @@ namespace UnivateProperties_API.Migrations
124 126
 
125 127
                     b.Property<string>("ModifiedBy");
126 128
 
129
+                    b.Property<int>("PropertyId");
130
+
127 131
                     b.Property<int>("WeekId");
128 132
 
129 133
                     b.HasKey("Id");
130 134
 
131 135
                     b.HasIndex("CampaignId");
132 136
 
137
+                    b.HasIndex("PropertyId");
138
+
133 139
                     b.HasIndex("WeekId");
134 140
 
135 141
                     b.ToTable("CampaignItems");
@@ -153,12 +159,16 @@ namespace UnivateProperties_API.Migrations
153 159
 
154 160
                     b.Property<string>("PlaceHolder");
155 161
 
162
+                    b.Property<int?>("PropertyCampaignItemId");
163
+
156 164
                     b.Property<string>("Value");
157 165
 
158 166
                     b.HasKey("Id");
159 167
 
160 168
                     b.HasIndex("CampaignItemId");
161 169
 
170
+                    b.HasIndex("PropertyCampaignItemId");
171
+
162 172
                     b.ToTable("CampaignItemPlaceHolders");
163 173
                 });
164 174
 
@@ -195,6 +205,58 @@ namespace UnivateProperties_API.Migrations
195 205
                     b.ToTable("CampaignPlaceHolders");
196 206
                 });
197 207
 
208
+            modelBuilder.Entity("UnivateProperties_API.Model.Campaigns.PropertyCampaignItem", b =>
209
+                {
210
+                    b.Property<int>("Id")
211
+                        .ValueGeneratedOnAdd()
212
+                        .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
213
+
214
+                    b.Property<int>("CampaignId");
215
+
216
+                    b.Property<DateTime>("Created");
217
+
218
+                    b.Property<string>("Image");
219
+
220
+                    b.Property<bool>("IsDeleted");
221
+
222
+                    b.Property<DateTime>("Modified");
223
+
224
+                    b.Property<string>("ModifiedBy");
225
+
226
+                    b.Property<int>("PropertyId");
227
+
228
+                    b.HasKey("Id");
229
+
230
+                    b.HasIndex("CampaignId");
231
+
232
+                    b.HasIndex("PropertyId");
233
+
234
+                    b.ToTable("PropertyCampaignItem");
235
+                });
236
+
237
+            modelBuilder.Entity("UnivateProperties_API.Model.Campaigns.UploadCampaign", b =>
238
+                {
239
+                    b.Property<int>("Id")
240
+                        .ValueGeneratedOnAdd()
241
+                        .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
242
+
243
+                    b.Property<DateTime>("Created");
244
+
245
+                    b.Property<string>("FileLink");
246
+
247
+                    b.Property<string>("FileName");
248
+
249
+                    b.Property<bool>("IsDeleted");
250
+
251
+                    b.Property<DateTime>("Modified");
252
+
253
+                    b.Property<string>("ModifiedBy");
254
+
255
+                    b.HasKey("Id");
256
+
257
+                    b.ToTable("CampaignUploads");
258
+                });
259
+
198 260
             modelBuilder.Entity("UnivateProperties_API.Model.Communication.Email", b =>
199 261
                 {
200 262
                     b.Property<int>("Id")
@@ -1486,6 +1548,11 @@ namespace UnivateProperties_API.Migrations
1486 1548
                         .HasForeignKey("CampaignId")
1487 1549
                         .OnDelete(DeleteBehavior.Cascade);
1488 1550
 
1551
+                    b.HasOne("UnivateProperties_API.Model.Properties.Property", "Property")
1552
+                        .WithMany()
1553
+                        .HasForeignKey("PropertyId")
1554
+                        .OnDelete(DeleteBehavior.Cascade);
1555
+
1489 1556
                     b.HasOne("UnivateProperties_API.Model.Timeshare.TimeshareWeek", "Week")
1490 1557
                         .WithMany()
1491 1558
                         .HasForeignKey("WeekId")
@@ -1498,6 +1565,10 @@ namespace UnivateProperties_API.Migrations
1498 1565
                         .WithMany("CampaignItemPlaceHolder")
1499 1566
                         .HasForeignKey("CampaignItemId")
1500 1567
                         .OnDelete(DeleteBehavior.Cascade);
1568
+
1569
+                    b.HasOne("UnivateProperties_API.Model.Campaigns.PropertyCampaignItem")
1570
+                        .WithMany("CampaignItemPlaceHolder")
1571
+                        .HasForeignKey("PropertyCampaignItemId");
1501 1572
                 });
1502 1573
 
1503 1574
             modelBuilder.Entity("UnivateProperties_API.Model.Campaigns.CampaignPlaceHolder", b =>
@@ -1508,6 +1579,19 @@ namespace UnivateProperties_API.Migrations
1508 1579
                         .OnDelete(DeleteBehavior.Cascade);
1509 1580
                 });
1510 1581
 
1582
+            modelBuilder.Entity("UnivateProperties_API.Model.Campaigns.PropertyCampaignItem", b =>
1583
+                {
1584
+                    b.HasOne("UnivateProperties_API.Model.Campaigns.Campaign", "Campaign")
1585
+                        .WithMany("PropertyItems")
1586
+                        .HasForeignKey("CampaignId")
1587
+                        .OnDelete(DeleteBehavior.Cascade);
1588
+
1589
+                    b.HasOne("UnivateProperties_API.Model.Properties.Property", "Property")
1590
+                        .WithMany()
1591
+                        .HasForeignKey("PropertyId")
1592
+                        .OnDelete(DeleteBehavior.Cascade);
1593
+                });
1594
+
1511 1595
             modelBuilder.Entity("UnivateProperties_API.Model.Communication.Email", b =>
1512 1596
                 {
1513 1597
                     b.HasOne("UnivateProperties_API.Model.Communication.SMTPAccount", "Sender")

+ 2
- 0
UnivateProperties_API/Model/Campaigns/Campaign.cs Просмотреть файл

@@ -16,6 +16,7 @@ namespace UnivateProperties_API.Model.Campaigns
16 16
         public string ItemBody { get; set; }
17 17
         public int ItemsPerRow { get; set; }
18 18
         //public CampaignItem Items { get; set; }
19
+        public bool IsTimeshare { get; set; }        
19 20
 
20 21
         [NotMapped]
21 22
         public bool IsActive
@@ -29,6 +30,7 @@ namespace UnivateProperties_API.Model.Campaigns
29 30
             }
30 31
         }
31 32
 
33
+        public virtual ICollection<PropertyCampaignItem> PropertyItems { get; set; }
32 34
         public virtual ICollection<CampaignItem> Items { get; set; }
33 35
         public virtual ICollection<CampaignPlaceHolder> PlaceHolders { get; set; }
34 36
     }

+ 4
- 2
UnivateProperties_API/Model/Campaigns/CampaignItem.cs Просмотреть файл

@@ -1,5 +1,6 @@
1 1
 using System.Collections.Generic;
2 2
 using System.ComponentModel.DataAnnotations.Schema;
3
+using UnivateProperties_API.Model.Properties;
3 4
 using UnivateProperties_API.Model.Timeshare;
4 5
 
5 6
 namespace UnivateProperties_API.Model.Campaigns
@@ -7,12 +8,13 @@ namespace UnivateProperties_API.Model.Campaigns
7 8
     public class CampaignItem : BaseEntity
8 9
     {
9 10
         [ForeignKey("Campaign")]
10
-        public int CampaignId { get; set; }
11
-        [ForeignKey("Week")]
11
+        public int CampaignId { get; set; }        
12 12
         public int WeekId { get; set; }
13
+        public int PropertyId { get; set; }
13 14
         public string Image { get; set; }
14 15
         
15 16
         public virtual TimeshareWeek Week { get; set; }
17
+        public virtual Property Property { get; set; }
16 18
         public virtual Campaign Campaign { get; set; }
17 19
 
18 20
         public virtual ICollection<CampaignItemPlaceHolder> CampaignItemPlaceHolder { get; set; }

+ 29
- 0
UnivateProperties_API/Model/Campaigns/PropertyCampaignItem.cs Просмотреть файл

@@ -0,0 +1,29 @@
1
+using System.Collections.Generic;
2
+using System.ComponentModel.DataAnnotations.Schema;
3
+using UnivateProperties_API.Model.Properties;
4
+
5
+namespace UnivateProperties_API.Model.Campaigns
6
+{
7
+    public class PropertyCampaignItem : BaseEntity
8
+    {
9
+        [ForeignKey("Campaign")]
10
+        public int CampaignId { get; set; }
11
+        [ForeignKey("Property")]
12
+        public int PropertyId { get; set; }
13
+        public string Image { get; set; }
14
+
15
+        public virtual Property Property { get; set; }
16
+        public virtual Campaign Campaign { get; set; }
17
+
18
+        public virtual ICollection<CampaignItemPlaceHolder> CampaignItemPlaceHolder { get; set; }
19
+
20
+        [NotMapped]
21
+        public string Reference
22
+        {
23
+            get
24
+            {
25
+                return Property != null ? Property.PropertyRef : "";
26
+            }
27
+        }
28
+    }
29
+}

+ 8
- 0
UnivateProperties_API/Model/Campaigns/UploadCampaign.cs Просмотреть файл

@@ -0,0 +1,8 @@
1
+namespace UnivateProperties_API.Model.Campaigns
2
+{
3
+    public class UploadCampaign : BaseEntity
4
+    {
5
+        public string FileName { get; set; }
6
+        public string FileLink { get; set; }
7
+    }
8
+}

+ 6
- 0
UnivateProperties_API/Model/Properties/Property.cs Просмотреть файл

@@ -11,6 +11,12 @@ namespace UnivateProperties_API.Model.Properties
11 11
 {
12 12
     public class Property : BaseEntity
13 13
     {
14
+
15
+        public Property()
16
+        {
17
+            
18
+        }
19
+
14 20
         private int? _StatusID;
15 21
         #region Properties        
16 22
         [ForeignKey("PropertyType")]

+ 170
- 9
UnivateProperties_API/Repository/Campaigns/CampaignRepository.cs Просмотреть файл

@@ -1,13 +1,17 @@
1
-using Microsoft.EntityFrameworkCore;
1
+using Microsoft.AspNetCore.Http;
2
+using Microsoft.EntityFrameworkCore;
2 3
 using Newtonsoft.Json;
3 4
 using System;
4 5
 using System.Collections.Generic;
6
+using System.IO;
5 7
 using System.Linq;
6 8
 using System.Threading.Tasks;
7 9
 using UnivateProperties_API.Containers.Campaigns;
8 10
 using UnivateProperties_API.Context;
9 11
 using UnivateProperties_API.Helpers;
10 12
 using UnivateProperties_API.Model.Campaigns;
13
+using UnivateProperties_API.Model.Properties;
14
+using UnivateProperties_API.Model.Timeshare;
11 15
 
12 16
 namespace UnivateProperties_API.Repository.Campaigns
13 17
 {
@@ -17,7 +21,10 @@ namespace UnivateProperties_API.Repository.Campaigns
17 21
         int InsertFromDTO(CampaignDTO campaign);
18 22
         string GetCampaignHTML(int CampaignId);
19 23
         List<CampaignItem> GetCampaignItems(int CampaignId);
20
-        List<CampaignPlaceHolder> GetCampaignPlaceHolders(int CampaignId);        
24
+        List<CampaignPlaceHolder> GetCampaignPlaceHolders(int CampaignId);
25
+        void addUploadCampaign(UploadCampaign campaignName);
26
+        List<UploadCampaign> GetUploadedCampaigns();
27
+        void RemoveUploadedAtId(int id);
21 28
     }
22 29
 
23 30
     public class CampaignRepository : ICampaignRepository
@@ -83,18 +90,28 @@ namespace UnivateProperties_API.Repository.Campaigns
83 90
             {
84 91
                 var url = _dbContext.Defaults.Where(d => d.Id == "URL").FirstOrDefault();
85 92
                 html = campaign.Body;
86
-                string temp = campaign.ItemBody;                
87
-
93
+                string temp = campaign.ItemBody;
94
+                TimeshareWeek week = new TimeshareWeek();
95
+                Property property = new Property();
88 96
                 itemCounter = 0;
89 97
                 foreach (var item in campaign.Items)
90 98
                 {
91 99
                     itemCounter++;
92
-                    var week = _dbContext.Weeks.Where(w => w.Id == item.WeekId).FirstOrDefault();
100
+                    if (item.WeekId != 0)
101
+                    {
102
+                        week = _dbContext.Weeks.Where(w => w.Id == item.WeekId).FirstOrDefault();
103
+                    }
104
+                    else
105
+                    {
106
+                        property = _dbContext.Properties.Where(p => p.Id == item.PropertyId).FirstOrDefault();
107
+                    }
93 108
 
94 109
                     string curItem = temp;
95 110
                     foreach(var place in campaign.PlaceHolders)
96 111
                     {
97
-                        var value = week[place.BoundTo];
112
+                        //var value = property[place.BoundTo];
113
+                        var value = week.Id == 0 ? property[place.BoundTo] : week[place.BoundTo];
114
+
98 115
                         if (!string.IsNullOrEmpty(place.Format))
99 116
                         {
100 117
                             string format = place.Format;
@@ -133,7 +150,7 @@ namespace UnivateProperties_API.Repository.Campaigns
133 150
                                 curItem = curItem.Replace(place.Name.ToString(), string.Format("{0:" + format + "}", value));
134 151
                         }
135 152
                         else
136
-                            curItem = curItem.Replace(place.Name.ToString(), value.ToString());
153
+                            curItem = curItem.Replace(place.Name.ToString(), value != null ? value.ToString() : place.Name.ToString() + " (NO DATA)");
137 154
                     }
138 155
 
139 156
                     var cutsomPlaceHolders = _dbContext.CampaignItemPlaceHolders.Where(c => c.CampaignItemId == item.Id).ToList();
@@ -143,7 +160,22 @@ namespace UnivateProperties_API.Repository.Campaigns
143 160
                     }
144 161
 
145 162
                     curItem = curItem.Replace("[image]", item.Image);
146
-                    curItem = curItem.Replace("[link]", string.Format("{0}resort/{1}/{2}", url?.Value ?? "http://localhost:8080/#/", item.Week.ResortCode, item.Week.UnitNumber));                    
163
+                    if (item.Week != null)
164
+                    {
165
+                        curItem = curItem.Replace("[link]", string.Format("{0}resort/{1}/{2}", url?.Value ?? "http://localhost:8080/#/", item.Week.ResortCode, item.Week.UnitNumber));
166
+                    }
167
+                    else
168
+                    {
169
+                        if (_dbContext.PropertyTypes.Where(x => x.Id == item.Property.PropertyTypeId).FirstOrDefault().UsageType == PropertyUsageType.Commercial)
170
+                        {
171
+                            curItem = curItem.Replace("[link]", string.Format("{0}property/commercial/property/{1}", url?.Value ?? "http://localhost:8080/#/", item.Property.Id));
172
+                        }
173
+                        else
174
+                        {
175
+                            curItem = curItem.Replace("[link]", string.Format("{0}property/residential/property/{1}", url?.Value ?? "http://localhost:8080/#/", item.Property.Id));                            
176
+                        }
177
+                    }
178
+                                      
147 179
 
148 180
                     tableItems = tableItems.Replace(string.Format("[ITEM{0}]", itemCounter), curItem);
149 181
                 }
@@ -178,10 +210,16 @@ namespace UnivateProperties_API.Repository.Campaigns
178 210
             }
179 211
             else
180 212
             {
213
+               
181 214
                 item.Items = (from i in _dbContext.CampaignItems
182
-                              where i.CampaignId == item.Id
215
+                              where i.CampaignId == item.Id && i.WeekId != 0
183 216
                               select new CampaignItem() { Id = i.Id, CampaignId = i.CampaignId, Image = i.Image, WeekId = i.WeekId, Week = i.Week, CampaignItemPlaceHolder = new List<CampaignItemPlaceHolder>()}).ToList();
184 217
 
218
+                item.Items = (from i in _dbContext.CampaignItems
219
+                              where i.CampaignId == item.Id && i.WeekId == 0
220
+                              select new CampaignItem() { Id = i.Id, CampaignId = i.CampaignId, Image = i.Image, PropertyId = i.PropertyId, Property = i.Property, CampaignItemPlaceHolder = new List<CampaignItemPlaceHolder>() }).ToList();
221
+
222
+
185 223
                 item.PlaceHolders = (from i in _dbContext.CampaignPlaceHolders
186 224
                            where i.CampaignId == item.Id
187 225
                            select new CampaignPlaceHolder(){Id = i.Id, CampaignId = i.CampaignId, Name = i.Name, BoundTo = i.BoundTo, BoundToClass = i.BoundToClass, BoundToClassDisplay = i.BoundToClassDisplay }).ToList();   
@@ -383,8 +421,131 @@ namespace UnivateProperties_API.Repository.Campaigns
383 421
             _dbContext.SaveChanges();
384 422
         }
385 423
 
424
+        public List<UploadCampaign> GetUploadedCampaigns()
425
+        {
426
+            return _dbContext.CampaignUploads.Where(x => x.IsDeleted == false).ToList();
427
+        }
428
+
429
+        public void addUploadCampaign(UploadCampaign campaign)
430
+        {
431
+            var camp = _dbContext.CampaignUploads.Where(x => x.FileName == campaign.FileName).FirstOrDefault();
432
+
433
+            if (camp == null)
434
+            { 
435
+                _dbContext.CampaignUploads.Add(campaign);
436
+                Save();
437
+            }
438
+            
439
+        }
440
+
441
+        public void RemoveUploadedAtId(int id)
442
+        {
443
+            var camp = _dbContext.CampaignUploads.Where(x => x.Id == id).FirstOrDefault();
444
+
445
+            _dbContext.CampaignUploads.Remove(camp);
446
+            Save();
447
+        }
448
+
386 449
         public void Update(Campaign item)
387 450
         {
451
+            //var savedItem = _dbContext.Campaigns.Where(x => x.Id == item.Id).FirstOrDefault();
452
+
453
+            //if (savedItem != null)
454
+            //{
455
+
456
+            //    if (savedItem.Name != item.Name)
457
+            //    {
458
+            //        savedItem.Name = item.Name;
459
+            //    }
460
+
461
+            //    if (savedItem.StartDate != item.StartDate)
462
+            //    {
463
+            //        savedItem.StartDate = item.StartDate;
464
+            //    }
465
+
466
+            //    if (savedItem.EndDate != item.EndDate)
467
+            //    {
468
+            //        savedItem.EndDate = item.EndDate;
469
+            //    }
470
+
471
+            //    if (savedItem.Subject != item.Subject)
472
+            //    {
473
+            //        savedItem.Subject = item.Subject;
474
+            //    }
475
+
476
+            //    if (savedItem.ItemsPerRow != item.ItemsPerRow)
477
+            //    {
478
+            //        savedItem.ItemsPerRow = item.ItemsPerRow;
479
+            //    }
480
+
481
+            //    if (savedItem.Body != item.Body)
482
+            //    {
483
+            //        savedItem.Body = item.Body;
484
+            //    }
485
+
486
+            //    if (savedItem.ItemBody != item.ItemBody)
487
+            //    {
488
+            //        savedItem.ItemBody = item.ItemBody;
489
+            //    }
490
+
491
+            //    if (_dbContext.CampaignPlaceHolders.Where(x => x.CampaignId == savedItem.Id).ToList().Count > 0)
492
+            //    {
493
+            //        if (_dbContext.CampaignPlaceHolders.Where(x => x.CampaignId == savedItem.Id).ToList().Count < item.PlaceHolders.Count)
494
+            //        {
495
+            //            var holders = _dbContext.CampaignPlaceHolders.Where(x => x.CampaignId == item.Id).ToList();
496
+            //            foreach (var savedPhItem in holders)
497
+            //            {
498
+            //                _dbContext.Remove(savedPhItem);
499
+            //            }
500
+            //            Save();
501
+            //            foreach (CampaignPlaceHolder ph in item.PlaceHolders)
502
+            //            {
503
+            //                ph.CampaignId = item.Id;
504
+            //                _dbContext.Add(ph);
505
+            //            }
506
+            //            Save();
507
+            //        }
508
+            //    }
509
+            //    else
510
+            //    {
511
+            //        foreach (CampaignPlaceHolder ph in item.PlaceHolders)
512
+            //        {
513
+            //            ph.CampaignId = item.Id;
514
+            //            _dbContext.Add(ph);
515
+            //        }
516
+            //        Save();
517
+            //    }
518
+
519
+            //    if (savedItem.Items != null)
520
+            //    {
521
+            //        if (savedItem.Items.Count < item.Items.Count)
522
+            //        {
523
+            //            var savedItems = _dbContext.CampaignItems.Where(x => x.CampaignId == item.Id).ToList();
524
+            //            foreach (var savedCamItem in savedItems)
525
+            //            {
526
+            //                _dbContext.Remove(savedCamItem);
527
+            //            }
528
+            //            Save();
529
+            //            foreach (CampaignItem ci in item.Items)
530
+            //            {
531
+            //                ci.CampaignId = item.Id;
532
+            //                _dbContext.Add(ci);
533
+            //            }
534
+            //            Save();
535
+            //        }
536
+            //    }
537
+            //    else
538
+            //    {
539
+            //        foreach (CampaignItem ci in item.Items)
540
+            //        {
541
+            //            ci.CampaignId = item.Id;
542
+            //            _dbContext.Add(ci);
543
+            //        }
544
+            //        Save();
545
+            //    }
546
+
547
+            //}
548
+            //_dbContext.Update(savedItem);
388 549
             _dbContext.Entry(item).State = EntityState.Modified;
389 550
             Save();
390 551
         }

+ 4
- 0
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Просмотреть файл

@@ -989,6 +989,10 @@ namespace UnivateProperties_API.Repository.Properties
989 989
                 var agent = dBContext.Agents.Where(x => x.UserId == user.Id).FirstOrDefault();
990 990
                 props = dBContext.Properties.Include("Owner").Include("PropertyType").Where(x => x.AgencyId == agent.AgencyId).ToList();
991 991
             }
992
+            else if (user.Role.ToUpper() == "DESIGNER")
993
+            {
994
+                props = dBContext.Properties.Include("Owner").Include("PropertyType").ToList();
995
+            }
992 996
             else
993 997
             {
994 998
                 var indiv = dBContext.Individuals.Where(i => i.UserId == user.Id).FirstOrDefault();

+ 2
- 0
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs Просмотреть файл

@@ -1168,6 +1168,8 @@ namespace UnivateProperties_API.Repository.Timeshare
1168 1168
             if (sellItem.CustomOwner)
1169 1169
             {
1170 1170
                 indiv.WeekId = week.Id;
1171
+                _dbContext.NonRegIndividuals.Update(indiv);
1172
+                Save();
1171 1173
             }
1172 1174
             return week.Id;
1173 1175
         }

+ 2
- 2
UnivateProperties_API/appsettings.json Просмотреть файл

@@ -10,8 +10,8 @@
10 10
   "AllowedHosts": "*",
11 11
   "ConnectionStrings": {
12 12
     //"DefaultConnection": "Data Source=localhost;Initial Catalog=UniVateDemo;Persist Security Info=True;Integrated Security=SSPI;Pooling=false;",
13
-    //"DefaultConnection": "Data Source=localhost;Initial Catalog=UniVateDemo;Persist Security Info=True;User Id=sa;Password=What123!;Pooling=false;",
14
-    "DefaultConnection": "Data Source=localhost;Initial Catalog=UniVate;Persist Security Info=True;User Id=Provision;Password=J%Xvk8xGeT;Pooling=false;",
13
+    "DefaultConnection": "Data Source=localhost;Initial Catalog=UniVateDemo;Persist Security Info=True;User Id=sa;Password=What123!;Pooling=false;",
14
+    //"DefaultConnection": "Data Source=localhost;Initial Catalog=UniVate;Persist Security Info=True;User Id=Provision;Password=J%Xvk8xGeT;Pooling=false;",
15 15
     "TenderConnection": "http://www.unipoint-consoft.co.za/nph-srep.exe?cluvavail.sch&CLUB=LPA&RESORT=ALL&SUMMARY=N&HEAD=N",
16 16
     "ReservationsURL": "https://www.pvsl.co.za:85/ReservationsWebService.asmx", //Please note that ReservationsWebService must be in this case. 
17 17
     "ReservationsUserCode": "UniInt",

Загрузка…
Отмена
Сохранить