ソースを参照

Landing pages

master
George Williams 4年前
コミット
c418fba720

+ 43
- 0
UnivateProperties_API/Containers/Campaigns/CampaignDTO.cs ファイルの表示

@@ -0,0 +1,43 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+
6
+namespace UnivateProperties_API.Containers.Campaigns
7
+{
8
+    public class CampaignDTO
9
+    {
10
+        public DateTime StartDate { get; set; }
11
+        public DateTime EndDate { get; set; }
12
+        public string Name { get; set; }
13
+        public string Subject { get; set; }
14
+        public string Body { get; set; }
15
+        public string ItemBody { get; set; }  
16
+        public int ItemsPerRow { get; set; }
17
+        public List<CampaignPlaceholderDTO> PlaceHolders { get; set; }
18
+        public List<CampaignWeeksDTO> Weeks { get; set; }
19
+        public List<CampaignWeeksPlaceHolderDTO> WeekPlaceHolders { get; set; }
20
+    }
21
+
22
+    public class CampaignPlaceholderDTO
23
+    {
24
+        public string Name { get; set; }
25
+        public string BoundTo { get; set; }
26
+        public string BoundToClassDisplay { get; set; }
27
+        public string BoundToClass { get; set; }
28
+        public string Format { get; set; }
29
+    }
30
+
31
+    public class CampaignWeeksDTO
32
+    {       
33
+        public int WeekId { get; set; }
34
+        public string Image { get; set; }        
35
+    }
36
+
37
+    public class CampaignWeeksPlaceHolderDTO
38
+    {
39
+        public int WeekId { get; set; }
40
+        public string Name { get; set; }
41
+        public string Value { get; set; }
42
+    }
43
+}

+ 1
- 0
UnivateProperties_API/Containers/Timeshare/WeekDto.cs ファイルの表示

@@ -96,5 +96,6 @@ namespace UnivateProperties_API.Containers.Timeshare
96 96
         public bool ReferedByAgent { get; set; }
97 97
 
98 98
         public string Display => $"{Resort.Display}  ({ArrivalDate.ToShortDateString()} - {DepartureDate.ToShortDateString()})";
99
+        public string WeekUni => $"{Resort.ResortCode} - {WeekNumber} - {UnitNumber}";
99 100
     }
100 101
 }

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

@@ -3,6 +3,7 @@ using Npgsql;
3 3
 using System.Linq;
4 4
 using UnivateProperties_API.Model;
5 5
 using UnivateProperties_API.Model.Banks;
6
+using UnivateProperties_API.Model.Campaigns;
6 7
 using UnivateProperties_API.Model.Communication;
7 8
 using UnivateProperties_API.Model.Financial;
8 9
 using UnivateProperties_API.Model.Logging;
@@ -82,12 +83,21 @@ namespace UnivateProperties_API.Context
82 83
         #region Misc
83 84
         public DbSet<Location> Location { get; set; }
84 85
         public DbSet<Carousel> Carousel { get; set; }
86
+        public DbSet<PlaceHolderFormat> PlaceHolderFormats { get; set; }
87
+        public DbSet<Default> Defaults { get; set; }
85 88
         #endregion
86 89
 
87 90
         #region Payments
88 91
         public DbSet<Payment> Payments { get; set; }
89 92
         #endregion
90 93
 
94
+        #region Campaign
95
+        public DbSet<Campaign> Campaigns { get; set; }
96
+        public DbSet<CampaignItem> CampaignItems { get; set; }  
97
+        public DbSet<CampaignPlaceHolder> CampaignPlaceHolders { get; set; }
98
+        public DbSet<CampaignItemPlaceHolder> CampaignItemPlaceHolders { get; set; }
99
+        #endregion
100
+
91 101
         public override int SaveChanges()
92 102
         {
93 103
             foreach (var item in ChangeTracker
@@ -186,6 +196,11 @@ namespace UnivateProperties_API.Context
186 196
             modelBuilder.Entity<Template>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
187 197
             modelBuilder.Entity<Carousel>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
188 198
             modelBuilder.Entity<PlaceHolder>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
199
+            modelBuilder.Entity<Campaign>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
200
+            modelBuilder.Entity<CampaignItem>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
201
+            modelBuilder.Entity<CampaignItemPlaceHolder>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
202
+            modelBuilder.Entity<CampaignPlaceHolder>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
203
+            modelBuilder.Entity<PlaceHolderFormat>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
189 204
         }
190 205
 
191 206
     

+ 92
- 0
UnivateProperties_API/Controllers/Campaigns/CampaignController.cs ファイルの表示

@@ -0,0 +1,92 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Collections.Generic;
3
+using System.Transactions;
4
+using UnivateProperties_API.Containers.Campaigns;
5
+using UnivateProperties_API.Model.Campaigns;
6
+using UnivateProperties_API.Repository;
7
+using UnivateProperties_API.Repository.Campaigns;
8
+
9
+namespace UnivateProperties_API.Controllers.Campaigns
10
+{
11
+    [Route("api/[controller]")]
12
+    [ApiController]
13
+    public class CampaignController : ControllerBase
14
+    {
15
+
16
+        private readonly ICampaignRepository _Repo;
17
+
18
+        public CampaignController(ICampaignRepository _repo)
19
+        {
20
+            _Repo = _repo;
21
+        }
22
+
23
+        [HttpGet]
24
+        public IActionResult Get()
25
+        {
26
+            return new OkObjectResult(_Repo.GetAll());
27
+        }
28
+        
29
+        [HttpGet("{id}")]
30
+        public IActionResult Get(int id)
31
+        {
32
+            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
33
+        }
34
+
35
+        [HttpGet("GetDTO/{id}")]
36
+        public IActionResult GetDTO(int id)
37
+        {
38
+            return new OkObjectResult(_Repo.GetDTO(x => x.Id == id));
39
+        }
40
+
41
+        [HttpGet("GetLandingPage/{id}")]
42
+        public IActionResult GetLandingPage(int id)
43
+        {
44
+            return new OkObjectResult(_Repo.GetCampaignHTML(id));
45
+        }
46
+
47
+        [HttpGet("GetCampaignItems/{id}")]
48
+        public IActionResult GetCampaignItems(int id)
49
+        {
50
+            return new OkObjectResult(_Repo.GetCampaignItems(id));
51
+        }
52
+
53
+        [HttpGet("GetCampaignPlaceHolders/{id}")]
54
+        public IActionResult GetCampaignPlaceHolders(int id)
55
+        {
56
+            return new OkObjectResult(_Repo.GetCampaignPlaceHolders(id));
57
+        }
58
+
59
+        [HttpPost]
60
+        public IActionResult Post([FromBody] Campaign campaign)
61
+        {
62
+            using (var scope = new TransactionScope())
63
+            {
64
+                _Repo.Insert(campaign);
65
+                scope.Complete();
66
+                return CreatedAtAction(nameof(Get), new { id = campaign.Id }, campaign);
67
+            }
68
+        }
69
+        
70
+        [HttpPut]
71
+        public IActionResult Put(Campaign campaign)
72
+        {
73
+            if (campaign != null)
74
+            {
75
+                using (var scope = new TransactionScope())
76
+                {
77
+                    _Repo.Update(campaign);
78
+                    scope.Complete();
79
+                    return new OkResult();
80
+                }
81
+            }
82
+            return new NoContentResult();
83
+        }
84
+
85
+        [HttpDelete("{id}")]
86
+        public IActionResult Delete(int id)
87
+        {
88
+            _Repo.RemoveAtId(id);
89
+            return new OkResult();
90
+        }
91
+    }
92
+}

+ 29
- 0
UnivateProperties_API/Controllers/Misc/PlaceHolderFormatController.cs ファイルの表示

@@ -0,0 +1,29 @@
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.Misc;
8
+using UnivateProperties_API.Repository;
9
+
10
+namespace UnivateProperties_API.Controllers.Misc
11
+{
12
+    [Route("api/[controller]")]
13
+    [ApiController]
14
+    public class PlaceHolderFormatController : ControllerBase
15
+    {
16
+        private readonly IRepository<PlaceHolderFormat> _Repo;
17
+
18
+        public PlaceHolderFormatController(IRepository<PlaceHolderFormat> _repo)
19
+        {
20
+            _Repo = _repo;
21
+        }
22
+
23
+        [HttpGet]
24
+        public IActionResult Get()
25
+        {
26
+            return new OkObjectResult(_Repo.GetAll());
27
+        }
28
+    }
29
+}

+ 3
- 5
UnivateProperties_API/Controllers/ProcessFlow/BidController.cs ファイルの表示

@@ -49,13 +49,11 @@ namespace UnivateProperties_API.Controllers.ProcessFlow
49 49
         [HttpPost]
50 50
         public IActionResult Post([FromBody] BidItemNew item)
51 51
         {
52
-            using (var scope = new TransactionScope())
52
+            using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
53 53
             {
54
-                _Repo.InsertNew(item);
54
+                _Repo.InsertNew(item);                
55 55
                 scope.Complete();
56
-                //return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
57
-                var bid = _Repo.Get(x => x.Id == item.Id);
58
-                return new OkObjectResult(bid);
56
+                return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
59 57
             }
60 58
         }
61 59
 

+ 32
- 0
UnivateProperties_API/Helpers/MyCommon.cs ファイルの表示

@@ -133,5 +133,37 @@ namespace UnivateProperties_API.Helpers
133 133
             }
134 134
             return new string(chars);
135 135
         }
136
+
137
+        public static string DateSuffixed(DateTime date)
138
+        {
139
+            var dt = date;
140
+
141
+            string suffix;
142
+            List<int> thNumbers = new List<int>() { 11, 12, 13 };
143
+
144
+
145
+            if (thNumbers.Contains(dt.Day))
146
+            {
147
+                suffix = "th";
148
+            }
149
+            else if (dt.Day % 10 == 1)
150
+            {
151
+                suffix = "st";
152
+            }
153
+            else if (dt.Day % 10 == 2)
154
+            {
155
+                suffix = "nd";
156
+            }
157
+            else if (dt.Day % 10 == 3)
158
+            {
159
+                suffix = "rd";
160
+            }
161
+            else
162
+            {
163
+                suffix = "th";
164
+            }
165
+
166
+            return suffix;
167
+        }
136 168
     }
137 169
 }

+ 35
- 0
UnivateProperties_API/Model/Campaigns/Campaign.cs ファイルの表示

@@ -0,0 +1,35 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.ComponentModel.DataAnnotations.Schema;
4
+using System.Linq;
5
+using System.Threading.Tasks;
6
+
7
+namespace UnivateProperties_API.Model.Campaigns
8
+{
9
+    public class Campaign : BaseEntity
10
+    {
11
+        public DateTime StartDate { get; set; }
12
+        public DateTime EndDate { get; set; }
13
+        public string Name { get; set; }
14
+        public string Subject { get; set; }
15
+        public string Body { get; set; }
16
+        public string ItemBody { get; set; }
17
+        public int ItemsPerRow { get; set; }
18
+        //public CampaignItem Items { get; set; }
19
+
20
+        [NotMapped]
21
+        public bool IsActive
22
+        {
23
+            get
24
+            {
25
+                if (EndDate.Date >= DateTime.Now.Date)                
26
+                    return true;                
27
+                else
28
+                    return false;
29
+            }
30
+        }
31
+
32
+        public virtual ICollection<CampaignItem> Items { get; set; }
33
+        public virtual ICollection<CampaignPlaceHolder> PlaceHolders { get; set; }
34
+    }
35
+}

+ 29
- 0
UnivateProperties_API/Model/Campaigns/CampaignItem.cs ファイルの表示

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

+ 14
- 0
UnivateProperties_API/Model/Campaigns/CampaignItemPlaceHolder.cs ファイルの表示

@@ -0,0 +1,14 @@
1
+using System.ComponentModel.DataAnnotations.Schema;
2
+
3
+namespace UnivateProperties_API.Model.Campaigns
4
+{
5
+    public class CampaignItemPlaceHolder : BaseEntity
6
+    {
7
+        [ForeignKey("CampaignItem")]
8
+        public int CampaignItemId { get; set; }
9
+        public string PlaceHolder { get; set; }
10
+        public string Value { get; set; }
11
+
12
+        public virtual CampaignItem CampaignItem { get; set; }
13
+    }
14
+}

+ 17
- 0
UnivateProperties_API/Model/Campaigns/CampaignPlaceHolder.cs ファイルの表示

@@ -0,0 +1,17 @@
1
+using System.ComponentModel.DataAnnotations.Schema;
2
+
3
+namespace UnivateProperties_API.Model.Campaigns
4
+{
5
+    public class CampaignPlaceHolder : BaseEntity
6
+    {
7
+        public string Name { get; set; }
8
+        public string BoundToClass { get; set; }
9
+        public string BoundToClassDisplay { get; set; }
10
+        public string BoundTo { get; set; }
11
+        public string Format { get; set; }
12
+        [ForeignKey("Campaign")]
13
+        public int CampaignId { get; set; }
14
+
15
+        public virtual Campaign Campaign { get; set; }
16
+    }
17
+}

+ 12
- 0
UnivateProperties_API/Model/Misc/Default.cs ファイルの表示

@@ -0,0 +1,12 @@
1
+using System.ComponentModel.DataAnnotations;
2
+
3
+namespace UnivateProperties_API.Model.Misc
4
+{
5
+    public class Default 
6
+    {
7
+        [Key]
8
+        public string Id { get; set; }
9
+
10
+        public string Value { get; set; }
11
+    }
12
+}

+ 13
- 0
UnivateProperties_API/Model/Misc/PlaceHolderFormat.cs ファイルの表示

@@ -0,0 +1,13 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+
6
+namespace UnivateProperties_API.Model.Misc
7
+{
8
+    public class PlaceHolderFormat: BaseEntity
9
+    {
10
+        public string DisplayName { get; set; }
11
+        public string Format { get; set; }
12
+    }
13
+}

+ 17
- 1
UnivateProperties_API/Model/Properties/Property.cs ファイルの表示

@@ -11,6 +11,7 @@ namespace UnivateProperties_API.Model.Properties
11 11
 {
12 12
     public class Property : BaseEntity
13 13
     {
14
+        private int? _StatusID;
14 15
         #region Properties        
15 16
         [ForeignKey("PropertyType")]
16 17
         public int PropertyTypeId { get; set; }
@@ -33,7 +34,21 @@ namespace UnivateProperties_API.Model.Properties
33 34
         public string VirtualTour { get; set; }
34 35
         public string Video { get; set; }
35 36
         [ForeignKey("Status")]
36
-        public int? StatusId { get; set; }
37
+        public int? StatusId 
38
+        { 
39
+            get
40
+            {
41
+                return _StatusID;
42
+            }
43
+            set
44
+            {
45
+                _StatusID = value;
46
+                if (value != null)
47
+                {
48
+                    StatusDate = DateTime.Now;
49
+                }
50
+            }
51
+        }
37 52
         [ForeignKey("Owner")]
38 53
         public int? OwnerId { get; set; }
39 54
         [ForeignKey("Agent")]
@@ -41,6 +56,7 @@ namespace UnivateProperties_API.Model.Properties
41 56
         [ForeignKey("Agency")]
42 57
         public int? AgencyId { get; set; }
43 58
         public DateTime DateAvailable { get; set; }
59
+        public DateTime StatusDate { get; set; }
44 60
 
45 61
         public virtual PropertyType PropertyType { get; set; }
46 62
         public virtual Province Province { get; set; }

+ 417
- 0
UnivateProperties_API/Repository/Campaigns/CampaignRepository.cs ファイルの表示

@@ -0,0 +1,417 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using Newtonsoft.Json;
3
+using System;
4
+using System.Collections.Generic;
5
+using System.Linq;
6
+using System.Threading.Tasks;
7
+using UnivateProperties_API.Containers.Campaigns;
8
+using UnivateProperties_API.Context;
9
+using UnivateProperties_API.Helpers;
10
+using UnivateProperties_API.Model.Campaigns;
11
+
12
+namespace UnivateProperties_API.Repository.Campaigns
13
+{
14
+    public interface ICampaignRepository : IRepository<Campaign>
15
+    {
16
+        CampaignDTO GetDTO(Func<Campaign, bool> where);
17
+        int InsertFromDTO(CampaignDTO campaign);
18
+        string GetCampaignHTML(int CampaignId);
19
+        List<CampaignItem> GetCampaignItems(int CampaignId);
20
+        List<CampaignPlaceHolder> GetCampaignPlaceHolders(int CampaignId);        
21
+    }
22
+
23
+    public class CampaignRepository : ICampaignRepository
24
+    {
25
+        private readonly DataContext _dbContext;
26
+
27
+        public CampaignRepository(DataContext dbContext)
28
+        {
29
+            _dbContext = dbContext;
30
+        }
31
+
32
+        public List<Campaign> Get(Func<Campaign, bool> where)
33
+        {
34
+            return _dbContext.Campaigns.Where(where).ToList();
35
+        }
36
+
37
+        public List<Campaign> GetAll()
38
+        {
39
+            return _dbContext.Campaigns.OrderByDescending(c => c.Created).ToList();
40
+        }
41
+
42
+        public string GetCampaignHTML(int CampaignId)
43
+        {
44
+            var campaign = _dbContext.Campaigns.Where(c => c.Id == CampaignId).Include("PlaceHolders").Include("Items").FirstOrDefault();
45
+            string html = "";
46
+
47
+            string tableItems = "<table align=center>";
48
+            int rows;
49
+            if (campaign.Items.Count % campaign.ItemsPerRow == 0)
50
+            {
51
+                rows = campaign.Items.Count / campaign.ItemsPerRow;
52
+            }
53
+            else
54
+            {
55
+                int remainder = campaign.Items.Count % campaign.ItemsPerRow;
56
+                int evenItems = campaign.Items.Count - remainder;
57
+                rows = evenItems / campaign.ItemsPerRow;
58
+                rows += remainder;
59
+            }
60
+
61
+            int itemCounter = 0;
62
+            for (int r = 0; r < rows; r++)
63
+            {
64
+                tableItems += "<tr>";
65
+                for(int c = 0; c < campaign.ItemsPerRow; c++)
66
+                {
67
+                    itemCounter++;
68
+
69
+                    if (itemCounter > campaign.Items.Count)
70
+                        tableItems += "<td></td>";
71
+                    else
72
+                        tableItems += string.Format("<td>[ITEM{0}]</td>", itemCounter);
73
+
74
+                }
75
+                tableItems += "</tr>";
76
+            }
77
+
78
+            tableItems += "</table>";
79
+
80
+            if(campaign != null)
81
+            {
82
+                var url = _dbContext.Defaults.Where(d => d.Id == "URL").FirstOrDefault();
83
+                html = campaign.Body;
84
+                string temp = campaign.ItemBody;                
85
+
86
+                itemCounter = 0;
87
+                foreach (var item in campaign.Items)
88
+                {
89
+                    itemCounter++;
90
+                    var week = _dbContext.Weeks.Where(w => w.Id == item.WeekId).FirstOrDefault();
91
+
92
+                    string curItem = temp;
93
+                    foreach(var place in campaign.PlaceHolders)
94
+                    {
95
+                        var value = week[place.BoundTo];
96
+                        if (!string.IsNullOrEmpty(place.Format))
97
+                        {
98
+                            string format = place.Format;
99
+                            if (format.Contains("|"))
100
+                            {
101
+                                string special = format.Substring(format.IndexOf('|'), format.Length - format.IndexOf('|')).Replace("|", "");
102
+                                format = format.Substring(0, format.IndexOf('|'));
103
+
104
+                                if (special == "DaySuffix")
105
+                                {
106
+                                    if (DateTime.TryParse(value.ToString(), out DateTime dateValue))
107
+                                    {
108
+                                        string suffix = MyCommon.DateSuffixed(dateValue);
109
+                                        string[] formatParts = format.Split(" ");
110
+                                        string replaceValue = "";
111
+
112
+                                        foreach(var s in formatParts)
113
+                                        {
114
+                                            string tempFormat = "{0:" + s + "}";
115
+                                            replaceValue += string.Format(tempFormat, dateValue);
116
+                                            if (s.ToLower().Contains("d"))
117
+                                                replaceValue += "<sup>" + suffix + "</sup> ";
118
+                                            else
119
+                                                replaceValue += " ";
120
+                                        }
121
+
122
+                                        curItem = curItem.Replace(place.Name.ToString(), replaceValue.Trim());
123
+                                    }
124
+                                    else
125
+                                    {
126
+                                        curItem = curItem.Replace(place.Name.ToString(), "ERROR-Date format on non date field");
127
+                                    }                                    
128
+                                }
129
+                            }
130
+                            else 
131
+                                curItem = curItem.Replace(place.Name.ToString(), string.Format("{0:" + format + "}", value));
132
+                        }
133
+                        else
134
+                            curItem = curItem.Replace(place.Name.ToString(), value.ToString());
135
+                    }
136
+
137
+                    var cutsomPlaceHolders = _dbContext.CampaignItemPlaceHolders.Where(c => c.CampaignItemId == item.Id).ToList();
138
+                    foreach (var custom in cutsomPlaceHolders)
139
+                    {
140
+                        curItem = curItem.Replace(custom.PlaceHolder, custom.Value);
141
+                    }
142
+
143
+                    curItem = curItem.Replace("[image]", item.Image);
144
+                    curItem = curItem.Replace("[link]", string.Format("{0}resort/{1}/{2}", url?.Value ?? "http://localhost:8080/#/", item.Week.ResortCode, item.Week.UnitNumber));                    
145
+
146
+                    tableItems = tableItems.Replace(string.Format("[ITEM{0}]", itemCounter), curItem);
147
+                }
148
+
149
+                html = html.Replace("[items]", tableItems);
150
+            }
151
+
152
+            return html;
153
+        }
154
+
155
+        public List<CampaignItem> GetCampaignItems(int CampaignId)
156
+        {
157
+            return _dbContext.CampaignItems.Where(c => c.CampaignId == CampaignId).ToList();
158
+        }
159
+
160
+        public List<CampaignPlaceHolder> GetCampaignPlaceHolders(int CampaignId)
161
+        {
162
+            return _dbContext.CampaignPlaceHolders.Where(c => c.CampaignId == CampaignId).ToList();
163
+        }
164
+
165
+        public Campaign GetDetailed(Func<Campaign, bool> first)
166
+        {
167
+            var item = _dbContext.Campaigns.FirstOrDefault(first);
168
+
169
+            if (item == null)
170
+            {
171
+                item = new Campaign
172
+                {
173
+                    Items = new List<CampaignItem>(),
174
+                    PlaceHolders = new List<CampaignPlaceHolder>()
175
+                };
176
+            }
177
+            else
178
+            {
179
+                item.Items = (from i in _dbContext.CampaignItems
180
+                              where i.CampaignId == item.Id
181
+                              select new CampaignItem() { Id = i.Id, CampaignId = i.CampaignId, Image = i.Image, WeekId = i.WeekId, Week = i.Week, CampaignItemPlaceHolder = new List<CampaignItemPlaceHolder>()}).ToList();
182
+
183
+                item.PlaceHolders = (from i in _dbContext.CampaignPlaceHolders
184
+                           where i.CampaignId == item.Id
185
+                           select new CampaignPlaceHolder(){Id = i.Id, CampaignId = i.CampaignId, Name = i.Name, BoundTo = i.BoundTo, BoundToClass = i.BoundToClass, BoundToClassDisplay = i.BoundToClassDisplay }).ToList();   
186
+                
187
+                foreach(var week in item.Items)
188
+                {
189
+                    var placeholders = (from p in _dbContext.CampaignItemPlaceHolders
190
+                                        where p.CampaignItemId == week.Id
191
+                                        select new CampaignItemPlaceHolder() { Id = p.Id, PlaceHolder = p.PlaceHolder, Value = p.Value, CampaignItemId = p.CampaignItemId }).ToList();
192
+                    week.CampaignItemPlaceHolder = placeholders;
193
+                }
194
+
195
+            }
196
+
197
+            var sItem = JsonConvert.SerializeObject(item, Formatting.None);
198
+
199
+            return item;
200
+        }
201
+
202
+        public List<Campaign> GetDetailedAll()
203
+        {
204
+            return GetAll();
205
+        }
206
+
207
+        public CampaignDTO GetDTO(Func<Campaign, bool> where)
208
+        {
209
+            var item = _dbContext.Campaigns.Include("Items").Include("PlaceHolders").Where(where).FirstOrDefault();
210
+            var dto = new CampaignDTO
211
+            {
212
+                PlaceHolders = new List<CampaignPlaceholderDTO>(),
213
+                Weeks = new List<CampaignWeeksDTO>(),
214
+                WeekPlaceHolders = new List<CampaignWeeksPlaceHolderDTO>()
215
+            };
216
+
217
+            if (item != null)
218
+            {
219
+                dto.Name = item.Name;
220
+                dto.StartDate = item.StartDate;
221
+                dto.EndDate = item.EndDate;
222
+                dto.Subject = item.Subject;
223
+                dto.Body = item.Body;
224
+                dto.ItemBody = item.ItemBody;
225
+
226
+                foreach (var p in item.PlaceHolders)
227
+                {
228
+                    dto.PlaceHolders.Add(new CampaignPlaceholderDTO()
229
+                    {
230
+                        Name = p.Name,
231
+                        BoundTo = p.BoundTo,
232
+                        BoundToClass = p.BoundToClass,
233
+                        BoundToClassDisplay = p.BoundToClassDisplay
234
+                    });
235
+                }
236
+
237
+                foreach (var i in item.Items)
238
+                {
239
+                    dto.Weeks.Add(new CampaignWeeksDTO()
240
+                    {
241
+                        Image = i.Image,
242
+                        WeekId = i.WeekId
243
+                    });
244
+                }
245
+            }
246
+
247
+            return dto;
248
+        }
249
+
250
+        public void Insert(Campaign item)
251
+        {
252
+            item.Id = NewId();
253
+
254
+            int last = _dbContext.GetMaxID("CampaignPlaceHolders") + 1;
255
+            if (item.PlaceHolders.Count > 0)
256
+            {
257
+                foreach (var ph in item.PlaceHolders)
258
+                {
259
+                    ph.CampaignId = item.Id;
260
+                    ph.Id = last;
261
+                    last++;
262
+                }
263
+            }
264
+
265
+            last = _dbContext.GetMaxID("CampaignItems") + 1;
266
+            int lastCustom = _dbContext.GetMaxID("CampaignItemPlaceHolders") + 1;
267
+            if (item.Items.Count > 0)
268
+            {
269
+                foreach (var i in item.Items)
270
+                {
271
+                    i.CampaignId = item.Id;
272
+                    i.Id = last;
273
+                    last++;
274
+                    if (i.CampaignItemPlaceHolder != null)
275
+                    {
276
+                        foreach (var c in i.CampaignItemPlaceHolder)
277
+                        {
278
+                            c.Id = lastCustom;
279
+                            lastCustom++;
280
+                        }
281
+                    }
282
+                }
283
+            }
284
+
285
+            _dbContext.Add(item);
286
+            Save();
287
+        }
288
+
289
+        public void Insert(IEnumerable<Campaign> items)
290
+        {
291
+            foreach (var item in items)
292
+            {
293
+                _dbContext.Add(item);
294
+            }
295
+            Save();
296
+        }
297
+
298
+        public int InsertFromDTO(CampaignDTO campaign)
299
+        {
300
+            var cam = new Campaign
301
+            {
302
+                Id = NewId(),
303
+                Name = campaign.Name,
304
+                StartDate = campaign.StartDate,
305
+                EndDate = campaign.EndDate,
306
+                Subject = campaign.Subject,
307
+                Body = campaign.Body,
308
+                ItemBody = campaign.ItemBody,
309
+                ItemsPerRow = campaign.ItemsPerRow
310
+            };
311
+
312
+            int lastID = _dbContext.GetMaxID("CampaignPlaceHolders") + 1;
313
+
314
+            if (campaign.PlaceHolders.Count > 0)
315
+            {
316
+                cam.PlaceHolders = new List<CampaignPlaceHolder>();
317
+                foreach (var place in campaign.PlaceHolders)
318
+                {
319
+                    lastID++;
320
+                    cam.PlaceHolders.Add(new CampaignPlaceHolder()
321
+                    {
322
+                        Id = lastID,
323
+                        CampaignId = cam.Id,
324
+                        Name = place.Name,
325
+                        BoundTo = place.BoundTo,
326
+                        BoundToClass = place.BoundToClass,
327
+                        BoundToClassDisplay = place.BoundToClassDisplay
328
+                    });
329
+                }
330
+            }
331
+
332
+            if (campaign.Weeks.Count > 0)
333
+            {                
334
+                lastID = _dbContext.GetMaxID("CampaignItems") + 1;
335
+                cam.Items = new List<CampaignItem>();
336
+                foreach (var week in campaign.Weeks)
337
+                {
338
+                    lastID++;
339
+                    cam.Items.Add(new CampaignItem()
340
+                    {
341
+                        CampaignId = cam.Id,
342
+                        Id = lastID,
343
+                        WeekId = week.WeekId,
344
+                        Image = week.Image
345
+                    });
346
+                }
347
+            }
348
+
349
+            if (campaign.WeekPlaceHolders.Count > 0)
350
+            {
351
+                lastID = _dbContext.GetMaxID("CampaignItemPlaceHolders") + 1;                
352
+                foreach (var wph in campaign.WeekPlaceHolders)
353
+                {
354
+                    var week = cam.Items.Where(w => w.WeekId == wph.WeekId).FirstOrDefault();
355
+
356
+                    if (week.CampaignItemPlaceHolder == null)
357
+                        week.CampaignItemPlaceHolder = new List<CampaignItemPlaceHolder>();
358
+
359
+                    CampaignItemPlaceHolder campaignItemPlaceHolder = new CampaignItemPlaceHolder
360
+                    {
361
+                        CampaignItemId = week.Id,
362
+                        PlaceHolder = wph.Name,
363
+                        Value = wph.Value
364
+                    };
365
+                    week.CampaignItemPlaceHolder.Add(campaignItemPlaceHolder);
366
+                }
367
+            }
368
+
369
+            _dbContext.Add(cam);
370
+            Save();
371
+            return cam.Id;
372
+        }
373
+
374
+        public int NewId()
375
+        {
376
+            return _dbContext.GetMaxID("Campaigns") + 1;
377
+        }
378
+
379
+        public void Remove(Campaign item)
380
+        {
381
+            var i = _dbContext.Campaigns.Find(item);
382
+            _dbContext.Campaigns.Remove(i);
383
+            Save();
384
+        }
385
+
386
+        public void Remove(IEnumerable<Campaign> items)
387
+        {
388
+            foreach (var item in items)
389
+            {
390
+                var i = _dbContext.Campaigns.Find(item);
391
+                _dbContext.Campaigns.Remove(i);
392
+            }
393
+            Save();
394
+        }
395
+
396
+        public void RemoveAtId(int item)
397
+        {
398
+            var i = _dbContext.Campaigns.Where(c => c.Id == item).FirstOrDefault();
399
+            if (i != null)
400
+            {
401
+                _dbContext.Campaigns.Remove(i);
402
+            }
403
+            Save();
404
+        }
405
+
406
+        public void Save()
407
+        {
408
+            _dbContext.SaveChanges();
409
+        }
410
+
411
+        public void Update(Campaign item)
412
+        {
413
+            _dbContext.Entry(item).State = EntityState.Modified;
414
+            Save();
415
+        }
416
+    }
417
+}

+ 10
- 8
UnivateProperties_API/Repository/Communication/TemplateRepository.cs ファイルの表示

@@ -45,6 +45,14 @@ namespace UnivateProperties_API.Repository.Communication
45 45
         public void Insert(Template item)
46 46
         {
47 47
             item.Id = NewId();
48
+
49
+            int maxIDPlaceHolder = _dbContext.GetMaxID("PlaceHolders") + 1;
50
+            foreach (var p in item.PlaceHolders)
51
+            {
52
+                p.Id = maxIDPlaceHolder;
53
+                maxIDPlaceHolder++;
54
+            }
55
+
48 56
             _dbContext.Add(item);
49 57
             Save();
50 58
         }
@@ -118,14 +126,8 @@ namespace UnivateProperties_API.Repository.Communication
118 126
         }
119 127
 
120 128
         public int NewId()
121
-        {
122
-            int id = 0;
123
-            if (_dbContext.Templates.Count() > 0)
124
-            {
125
-                id = _dbContext.Templates.Max(x => x.Id);
126
-            }
127
-            id += 1;
128
-            return id;
129
+        {            
130
+            return _dbContext.GetMaxID("Templates") + 1;
129 131
         }
130 132
 
131 133
         public List<TemplateDto> GetSimpleAll()

+ 79
- 0
UnivateProperties_API/Repository/Misc/PlaceHolderFormatRepository.cs ファイルの表示

@@ -0,0 +1,79 @@
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.Misc;
7
+
8
+namespace UnivateProperties_API.Repository.Misc
9
+{
10
+    public class PlaceHolderFormatRepository : IRepository<PlaceHolderFormat>
11
+    {
12
+        private readonly DataContext dBContext;
13
+
14
+        public PlaceHolderFormatRepository(DataContext _dataContext)
15
+        {
16
+            dBContext = _dataContext;
17
+        }
18
+
19
+        public List<PlaceHolderFormat> Get(Func<PlaceHolderFormat, bool> where)
20
+        {
21
+            throw new NotImplementedException();
22
+        }
23
+
24
+        public List<PlaceHolderFormat> GetAll()
25
+        {
26
+            return dBContext.PlaceHolderFormats.ToList();
27
+        }
28
+
29
+        public PlaceHolderFormat GetDetailed(Func<PlaceHolderFormat, bool> first)
30
+        {
31
+            throw new NotImplementedException();
32
+        }
33
+
34
+        public List<PlaceHolderFormat> GetDetailedAll()
35
+        {
36
+            throw new NotImplementedException();
37
+        }
38
+
39
+        public void Insert(PlaceHolderFormat item)
40
+        {
41
+            throw new NotImplementedException();
42
+        }
43
+
44
+        public void Insert(IEnumerable<PlaceHolderFormat> items)
45
+        {
46
+            throw new NotImplementedException();
47
+        }
48
+
49
+        public int NewId()
50
+        {
51
+            throw new NotImplementedException();
52
+        }
53
+
54
+        public void Remove(PlaceHolderFormat item)
55
+        {
56
+            throw new NotImplementedException();
57
+        }
58
+
59
+        public void Remove(IEnumerable<PlaceHolderFormat> items)
60
+        {
61
+            throw new NotImplementedException();
62
+        }
63
+
64
+        public void RemoveAtId(int item)
65
+        {
66
+            throw new NotImplementedException();
67
+        }
68
+
69
+        public void Save()
70
+        {
71
+            throw new NotImplementedException();
72
+        }
73
+
74
+        public void Update(PlaceHolderFormat item)
75
+        {
76
+            throw new NotImplementedException();
77
+        }
78
+    }
79
+}

+ 29
- 3
UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs ファイルの表示

@@ -188,15 +188,15 @@ namespace UnivateProperties_API.Repository.ProccessFlow
188 188
         {            
189 189
             var week = _dbContext.Weeks.Include("Owner").Where(x => x.Id == item.TimeshareWeekId).FirstOrDefault();
190 190
             var property = _dbContext.Properties.Include("Owner").Where(x => x.Id == item.PropertyId).FirstOrDefault();
191
-            BidItem bid = new BidItem();
192
-            bid.Id = _dbContext.GetMaxID("BidItems") + 1;
191
+            BidItem bid = new BidItem();            
193 192
 
194 193
             foreach (string prop in bid.GetAllProperties())
195 194
             {
196 195
                 if (prop != "Item" && prop != "Display")
197 196
                     bid[prop] = item[prop];
198 197
             }
199
-            
198
+            bid.Id = _dbContext.GetMaxID("BidItems") + 1;
199
+
200 200
             var status = _dbContext.Status.Where(x => x.Code == "E1").FirstOrDefault();
201 201
             if (status != null)            
202 202
                 bid.StatusId = status.Id;
@@ -247,6 +247,13 @@ namespace UnivateProperties_API.Repository.ProccessFlow
247 247
                 {
248 248
                     if (property != null)
249 249
                     {
250
+                        var propertyStatus = _dbContext.Status.Where(s => s.Code == "P4").FirstOrDefault();
251
+                        if (propertyStatus != null)
252
+                        {
253
+                            property.StatusId = propertyStatus.Id;
254
+                            _dbContext.Update(property);
255
+                        }
256
+
250 257
                         TemplateRepository templateRepository = new TemplateRepository(_dbContext);
251 258
                         var template = _dbContext.Templates.FirstOrDefault(x => x.Name == "PropertyOfferMade-Owner");
252 259
                         if (template != null)
@@ -331,6 +338,16 @@ namespace UnivateProperties_API.Repository.ProccessFlow
331 338
                 item.StatusId = status.Id;
332 339
             }
333 340
 
341
+            if (item.Property != null)
342
+            {
343
+                var propertyStatus = _dbContext.Status.Where(p => p.Code == "P5").FirstOrDefault();
344
+                if (propertyStatus != null)
345
+                {
346
+                    item.Property.StatusId = propertyStatus.Id;
347
+                    item.Property.Published = false;
348
+                }
349
+            }
350
+
334 351
             _dbContext.Entry(item).State = EntityState.Modified;
335 352
             Save();
336 353
 
@@ -358,6 +375,15 @@ namespace UnivateProperties_API.Repository.ProccessFlow
358 375
 
359 376
             bid.DeclinedReason = item.Comment;
360 377
 
378
+            if (bid.Property != null)
379
+            {
380
+                var propertyStatus = _dbContext.Status.Where(p => p.Code == "P3").FirstOrDefault();
381
+                if (propertyStatus != null)
382
+                {
383
+                    bid.Property.StatusId = propertyStatus.Id;
384
+                }
385
+            }
386
+
361 387
             _dbContext.Entry(bid).State = EntityState.Modified;
362 388
             Save();
363 389
 

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

@@ -677,8 +677,7 @@ namespace UnivateProperties_API.Repository.Properties
677 677
 
678 678
         public void Insert(PropertyContainer items)
679 679
         {
680
-            Property property = new Property();
681
-
680
+            Property property = new Property();            
682 681
             PropertyType pt = dBContext.PropertyTypes.Find(items.PropertyTypeId);
683 682
             if (pt != null)
684 683
             {
@@ -713,7 +712,8 @@ namespace UnivateProperties_API.Repository.Properties
713 712
             items.PropertyUserFields = null;
714 713
 
715 714
             var individual = dBContext.Individuals.Where(i => i.UserId == items.UserId).FirstOrDefault();
716
-            var agent = dBContext.Agents.Where(a => a.UserId == items.UserId).FirstOrDefault();            
715
+            var agent = dBContext.Agents.Where(a => a.UserId == items.UserId).FirstOrDefault();
716
+            var status = dBContext.Status.Where(a => a.Code == "P1").FirstOrDefault();
717 717
 
718 718
             foreach( string prop in property.GetAllProperties())
719 719
             {
@@ -729,6 +729,11 @@ namespace UnivateProperties_API.Repository.Properties
729 729
                 property.AgentId = agent.Id;
730 730
             }
731 731
 
732
+            property.Id = dBContext.GetMaxID("Properties") + 1;
733
+
734
+            if (status != null)
735
+                property.StatusId = status.Id;
736
+
732 737
             property.Video = property.Video.Replace("https://www.youtube.com/watch?v=", "");
733 738
 
734 739
             if (images != null)

+ 8
- 3
UnivateProperties_API/Startup.cs ファイルの表示

@@ -13,6 +13,7 @@ using System.Threading.Tasks;
13 13
 using UnivateProperties_API.Context;
14 14
 using UnivateProperties_API.Helpers;
15 15
 using UnivateProperties_API.Model.Banks;
16
+using UnivateProperties_API.Model.Campaigns;
16 17
 using UnivateProperties_API.Model.Communication;
17 18
 using UnivateProperties_API.Model.Financial;
18 19
 using UnivateProperties_API.Model.Misc;
@@ -23,6 +24,7 @@ using UnivateProperties_API.Model.Timeshare;
23 24
 using UnivateProperties_API.Model.Users;
24 25
 using UnivateProperties_API.Repository;
25 26
 using UnivateProperties_API.Repository.Banks;
27
+using UnivateProperties_API.Repository.Campaigns;
26 28
 using UnivateProperties_API.Repository.Communication;
27 29
 using UnivateProperties_API.Repository.Financial;
28 30
 using UnivateProperties_API.Repository.Logging;
@@ -38,7 +40,7 @@ namespace UnivateProperties_API
38 40
     public class Startup
39 41
     {
40 42
         public Startup(IConfiguration configuration)
41
-        {
43
+        {            
42 44
             Configuration = configuration;
43 45
         }
44 46
 
@@ -112,8 +114,7 @@ namespace UnivateProperties_API
112 114
             services.AddTransient<IRepository<PropertyUserField>, PropertyUserFieldRepository>();
113 115
             services.AddTransient<IRepository<UserDefinedField>, UserDefinedFieldRepository>();
114 116
             services.AddTransient<IUserDefinedGroupRepository, UserDefinedGroupRepository>();
115
-            services.AddTransient<IRepository<Payment>, PaymentRepository>();
116
-
117
+            services.AddTransient<IRepository<Payment>, PaymentRepository>();            
117 118
             #endregion Property
118 119
             #region Region
119 120
             services.AddTransient<IRepository<Province>, ProvinceRepository>();
@@ -148,6 +149,10 @@ namespace UnivateProperties_API
148 149
             #endregion
149 150
             #region Misc
150 151
             services.AddTransient<ICarouselRepository, CarouselRepository>();
152
+            services.AddTransient<IRepository<PlaceHolderFormat>, PlaceHolderFormatRepository>();
153
+            #endregion
154
+            #region Campaign 
155
+            services.AddTransient<ICampaignRepository, CampaignRepository>();
151 156
             #endregion
152 157
             services.Configure<MvcOptions>(options =>
153 158
             {

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