Lene Scholtz 5 роки тому
джерело
коміт
ddf44c4589
27 змінених файлів з 1965 додано та 93 видалено
  1. 1
    0
      UnivateProperties_API/Containers/Communication/PlaceHolderDto.cs
  2. 17
    12
      UnivateProperties_API/Containers/Property/ImageFormatter.cs
  3. 7
    0
      UnivateProperties_API/Containers/Property/PropertyContainer.cs
  4. 1
    0
      UnivateProperties_API/Containers/Property/PropertyList.cs
  5. 2
    0
      UnivateProperties_API/Containers/Regions/SuburbSearch.cs
  6. 4
    1
      UnivateProperties_API/Containers/Timeshare/WeekDto.cs
  7. 2
    2
      UnivateProperties_API/Context/DataContext.cs
  8. 11
    0
      UnivateProperties_API/Controllers/Communication/TemplateController.cs
  9. 1
    1
      UnivateProperties_API/Controllers/Misc/CarouselController.cs
  10. 5
    5
      UnivateProperties_API/Controllers/Properties/PropertyController.cs
  11. 29
    0
      UnivateProperties_API/Controllers/Timeshare/TimeshareWeekController.cs
  12. 26
    0
      UnivateProperties_API/Helpers/MyCommon.cs
  13. 1294
    0
      UnivateProperties_API/Migrations/20191112124547_templateMod.Designer.cs
  14. 113
    0
      UnivateProperties_API/Migrations/20191112124547_templateMod.cs
  15. 29
    0
      UnivateProperties_API/Migrations/DataContextModelSnapshot.cs
  16. 66
    0
      UnivateProperties_API/Model/Communication/Email.cs
  17. 2
    0
      UnivateProperties_API/Model/Communication/SMTPAccount.cs
  18. 7
    0
      UnivateProperties_API/Model/Communication/Template.cs
  19. 38
    11
      UnivateProperties_API/Model/Timeshare/TimeshareWeek.cs
  20. 57
    2
      UnivateProperties_API/Repository/Communication/TemplateRepository.cs
  21. 61
    2
      UnivateProperties_API/Repository/Misc/CarouselRepository.cs
  22. 1
    0
      UnivateProperties_API/Repository/Misc/ICarouselRepository.cs
  23. 54
    16
      UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs
  24. 3
    1
      UnivateProperties_API/Repository/Properties/IPropertyRepository.cs
  25. 64
    23
      UnivateProperties_API/Repository/Properties/PropertyRepository.cs
  26. 17
    4
      UnivateProperties_API/Repository/Region/SuburbRepository.cs
  27. 53
    13
      UnivateProperties_API/Repository/Timeshare/WeekRepository.cs

+ 1
- 0
UnivateProperties_API/Containers/Communication/PlaceHolderDto.cs Переглянути файл

@@ -2,6 +2,7 @@
2 2
 {
3 3
     public class PlaceHolderDto
4 4
     {
5
+        public int Id { get; set; }
5 6
         public string Name { get; set; }
6 7
         public string BoundToClass { get; set; }
7 8
         public string BoundToClassDisplay { get; set; }

+ 17
- 12
UnivateProperties_API/Containers/Property/ImageFormatter.cs Переглянути файл

@@ -35,25 +35,30 @@ namespace UnivateProperties_API.Containers.Property
35 35
 
36 36
         public static string ImageToBase64(string Path)
37 37
         {
38
-            using (Image image = Image.FromFile(Path))
38
+            if (File.Exists(Path))
39 39
             {
40
-                using (MemoryStream m = new MemoryStream())
40
+                using (Image image = Image.FromFile(Path))
41 41
                 {
42
-                    image.Save(m, image.RawFormat);
43
-                    byte[] imageBytes = m.ToArray();
42
+                    using (MemoryStream m = new MemoryStream())
43
+                    {
44
+                        image.Save(m, image.RawFormat);
45
+                        byte[] imageBytes = m.ToArray();
44 46
 
45
-                    string base64String = Convert.ToBase64String(imageBytes);
47
+                        string base64String = Convert.ToBase64String(imageBytes);
46 48
 
47
-                    if (Path.EndsWith(".jpg") || Path.EndsWith(".jpeg"))
48
-                        base64String = "data:image/jpeg;base64," + base64String;
49
-                    if (Path.EndsWith(".gif"))
50
-                        base64String = "data:image/gif;base64," + base64String;
51
-                    if (base64String.EndsWith(".png"))
52
-                        base64String = "data:image/png;base64," + base64String;
49
+                        if (Path.EndsWith(".jpg") || Path.EndsWith(".jpeg"))
50
+                            base64String = "data:image/jpeg;base64," + base64String;
51
+                        if (Path.EndsWith(".gif"))
52
+                            base64String = "data:image/gif;base64," + base64String;
53
+                        if (base64String.EndsWith(".png"))
54
+                            base64String = "data:image/png;base64," + base64String;
53 55
 
54
-                    return base64String;
56
+                        return base64String;
57
+                    }
55 58
                 }
56 59
             }
60
+            else
61
+                return "";
57 62
         }
58 63
     }
59 64
 }

+ 7
- 0
UnivateProperties_API/Containers/Property/PropertyContainer.cs Переглянути файл

@@ -2,6 +2,7 @@
2 2
 using System.Collections.Generic;
3 3
 using System.Linq;
4 4
 using System.Threading.Tasks;
5
+using UnivateProperties_API.Model.Properties;
5 6
 
6 7
 namespace UnivateProperties_API.Containers.Property
7 8
 {
@@ -40,4 +41,10 @@ namespace UnivateProperties_API.Containers.Property
40 41
         public string Image { get; set;  }
41 42
         public bool IsDefault { get; set; }
42 43
     }
44
+
45
+    public class PropertyImageContainer
46
+    {
47
+        public int PropertyId { get; set; }
48
+        public List<PropertyImage> Images { get; set; }
49
+    }
43 50
 }

+ 1
- 0
UnivateProperties_API/Containers/Property/PropertyList.cs Переглянути файл

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

+ 2
- 0
UnivateProperties_API/Containers/Regions/SuburbSearch.cs Переглянути файл

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

+ 4
- 1
UnivateProperties_API/Containers/Timeshare/WeekDto.cs Переглянути файл

@@ -56,7 +56,10 @@ namespace UnivateProperties_API.Containers.Timeshare
56 56
             Owner = $"{week.Owner?.Name} {week.Owner?.Surname}";
57 57
             Resort = new ResortDto(week.ResortCode, week.ResortName);
58 58
             Region = new RegionDto(week.Region != null ? week.Region.Id : 0, week.Region?.Code, week.Region?.Description);
59
-            Status = new StatusDto(week.Status.Id, week.Status?.Code, week.Status?.Description);
59
+            if(week.Status != null)
60
+            {
61
+                Status = new StatusDto(week.Status.Id, week.Status.Code, week.Status.Description);
62
+            }            
60 63
             Bedrooms = week.Bedrooms;
61 64
             MaxSleep = week.MaxSleep;
62 65
             UnitNumber = week.UnitNumber;

+ 2
- 2
UnivateProperties_API/Context/DataContext.cs Переглянути файл

@@ -181,8 +181,8 @@ namespace UnivateProperties_API.Context
181 181
             modelBuilder.Entity<BidItem>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
182 182
             modelBuilder.Entity<ProcessFlow>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
183 183
             modelBuilder.Entity<Template>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
184
-
185
-            
184
+            modelBuilder.Entity<Carousel>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
185
+            modelBuilder.Entity<PlaceHolder>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
186 186
         }
187 187
 
188 188
     

+ 11
- 0
UnivateProperties_API/Controllers/Communication/TemplateController.cs Переглянути файл

@@ -70,5 +70,16 @@ namespace UnivateProperties_API.Controllers.Communication
70 70
             _Repo.RemoveAtId(id);
71 71
             return new OkResult();
72 72
         }
73
+
74
+        //[HttpPost("sendTemplate/{id}")]
75
+        //public IActionResult SendTemplate(int id)
76
+        //{
77
+        //    using ( var scope = new TransactionScope())
78
+        //    {
79
+        //        (_Repo as TemplateRepository).SendEmailTemplate(id);
80
+        //        scope.Complete();
81
+        //        return new OkResult();
82
+        //    }
83
+        //}
73 84
     }
74 85
 }

+ 1
- 1
UnivateProperties_API/Controllers/Misc/CarouselController.cs Переглянути файл

@@ -25,7 +25,7 @@ namespace UnivateProperties_API.Controllers.Misc
25 25
         [HttpGet("{id}")]
26 26
         public IActionResult Get(int id)
27 27
         {
28
-            return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
28
+            return new OkObjectResult(_Repo.GetCarousel(id));
29 29
         }        
30 30
 
31 31
         [HttpPost]

+ 5
- 5
UnivateProperties_API/Controllers/Properties/PropertyController.cs Переглянути файл

@@ -88,20 +88,20 @@ namespace UnivateProperties_API.Controllers.Properties
88 88
         [HttpPost]
89 89
         public IActionResult Post([FromBody] PropertyContainer property)
90 90
         {
91
-            using (var scope = new TransactionScope())
91
+            using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
92 92
             {
93 93
                 _Repo.Insert(property);
94
-                scope.Complete();
94
+                scope.Complete();                
95 95
                 return CreatedAtAction(nameof(Get), new { id = property.Id }, property);
96
-            }
97
-        }       
96
+            }            
97
+        }      
98 98
 
99 99
         [HttpPut]
100 100
         public IActionResult Put([FromBody] PropertyContainer property)
101 101
         {
102 102
             if (property != null)
103 103
             {
104
-                using (var scope = new TransactionScope())
104
+                using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
105 105
                 {
106 106
                     _Repo.Update(property);
107 107
                     scope.Complete();

+ 29
- 0
UnivateProperties_API/Controllers/Timeshare/TimeshareWeekController.cs Переглянути файл

@@ -104,5 +104,34 @@ namespace UnivateProperties_API.Controllers.Timeshare
104 104
             _Repo.RemoveAtId(id);
105 105
             return new OkResult();
106 106
         }
107
+
108
+        [HttpPost("verifyweek/{id}")]
109
+        public IActionResult Post(int id)
110
+        {
111
+            using (var scope = new TransactionScope())
112
+            {
113
+                (_Repo as WeekRepository).VerifyWeek(id);
114
+                scope.Complete();
115
+                return new OkResult();
116
+            }
117
+        }
118
+
119
+        [HttpPost("publishweek/{id}")]
120
+        public IActionResult Publishweek(int id)
121
+        {
122
+            using (var scope = new TransactionScope())
123
+            {
124
+                (_Repo as WeekRepository).VerifyWeek(id);
125
+                scope.Complete();
126
+                return new OkResult();
127
+            }
128
+        }
129
+
130
+        [HttpGet("getTenderWeeks")]
131
+        public IActionResult GetTenderWeeks()
132
+        {
133
+            var item = (_Repo as WeekRepository).GetTenderWeeks();
134
+            return new OkObjectResult(item);
135
+        }
107 136
     }
108 137
 }

+ 26
- 0
UnivateProperties_API/Helpers/MyCommon.cs Переглянути файл

@@ -1,13 +1,39 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3
+using System.IO;
3 4
 using System.Linq;
5
+using System.Net;
6
+using System.Text;
4 7
 using System.Text.RegularExpressions;
5 8
 using UnivateProperties_API.Helpers.Attributes;
9
+using UnivateProperties_API.Model.Timeshare;
6 10
 
7 11
 namespace UnivateProperties_API.Helpers
8 12
 {
9 13
     public static class MyCommon
10 14
     {
15
+        public static bool PostToConsoft(TimeshareWeek week)
16
+        {
17
+            bool flag = false;
18
+            try
19
+            {
20
+                var search = $"http://www.unipoint-consoft.co.za/nph-srep.exe?cluvbank_test.sch&CLUB=LPA&TYPE=BANK&RESORT={week.ResortCode}&UNIT={week.UnitNumber}&MODULE={week.WeekNumber}&YEAR={week.ArrivalDate.Year}&BANKTO=UV";
21
+                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(search);
22
+                request.Method = "GET";
23
+                WebResponse response = request.GetResponse();
24
+                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
25
+                {
26
+                    string result = reader.ReadToEnd();
27
+                    flag = result.ToLower().Contains("success");
28
+                }
29
+            }
30
+            catch (Exception)
31
+            {
32
+
33
+            }
34
+            return flag;
35
+        }
36
+
11 37
         public static List<string> GetVisibleColumns<T>(T item) where T : new()
12 38
         {
13 39
             List<string> list = new List<string>();

+ 1294
- 0
UnivateProperties_API/Migrations/20191112124547_templateMod.Designer.cs
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 113
- 0
UnivateProperties_API/Migrations/20191112124547_templateMod.cs Переглянути файл

@@ -0,0 +1,113 @@
1
+using Microsoft.EntityFrameworkCore.Migrations;
2
+
3
+namespace UnivateProperties_API.Migrations
4
+{
5
+    public partial class templateMod : Migration
6
+    {
7
+        protected override void Up(MigrationBuilder migrationBuilder)
8
+        {
9
+            migrationBuilder.AddColumn<int>(
10
+                name: "SenderId",
11
+                table: "Templates",
12
+                nullable: true);
13
+
14
+            migrationBuilder.AddColumn<int>(
15
+                name: "TemplateId",
16
+                table: "Individuals",
17
+                nullable: true);
18
+
19
+            migrationBuilder.AddColumn<int>(
20
+                name: "TemplateId",
21
+                table: "Agents",
22
+                nullable: true);
23
+
24
+            migrationBuilder.AddColumn<bool>(
25
+                name: "Default",
26
+                table: "Accounts",
27
+                nullable: false,
28
+                defaultValue: false);
29
+
30
+            migrationBuilder.CreateIndex(
31
+                name: "IX_Templates_SenderId",
32
+                table: "Templates",
33
+                column: "SenderId");
34
+
35
+            migrationBuilder.CreateIndex(
36
+                name: "IX_Individuals_TemplateId",
37
+                table: "Individuals",
38
+                column: "TemplateId");
39
+
40
+            migrationBuilder.CreateIndex(
41
+                name: "IX_Agents_TemplateId",
42
+                table: "Agents",
43
+                column: "TemplateId");
44
+
45
+            migrationBuilder.AddForeignKey(
46
+                name: "FK_Agents_Templates_TemplateId",
47
+                table: "Agents",
48
+                column: "TemplateId",
49
+                principalTable: "Templates",
50
+                principalColumn: "Id",
51
+                onDelete: ReferentialAction.Restrict);
52
+
53
+            migrationBuilder.AddForeignKey(
54
+                name: "FK_Individuals_Templates_TemplateId",
55
+                table: "Individuals",
56
+                column: "TemplateId",
57
+                principalTable: "Templates",
58
+                principalColumn: "Id",
59
+                onDelete: ReferentialAction.Restrict);
60
+
61
+            migrationBuilder.AddForeignKey(
62
+                name: "FK_Templates_Accounts_SenderId",
63
+                table: "Templates",
64
+                column: "SenderId",
65
+                principalTable: "Accounts",
66
+                principalColumn: "Id",
67
+                onDelete: ReferentialAction.Restrict);
68
+        }
69
+
70
+        protected override void Down(MigrationBuilder migrationBuilder)
71
+        {
72
+            migrationBuilder.DropForeignKey(
73
+                name: "FK_Agents_Templates_TemplateId",
74
+                table: "Agents");
75
+
76
+            migrationBuilder.DropForeignKey(
77
+                name: "FK_Individuals_Templates_TemplateId",
78
+                table: "Individuals");
79
+
80
+            migrationBuilder.DropForeignKey(
81
+                name: "FK_Templates_Accounts_SenderId",
82
+                table: "Templates");
83
+
84
+            migrationBuilder.DropIndex(
85
+                name: "IX_Templates_SenderId",
86
+                table: "Templates");
87
+
88
+            migrationBuilder.DropIndex(
89
+                name: "IX_Individuals_TemplateId",
90
+                table: "Individuals");
91
+
92
+            migrationBuilder.DropIndex(
93
+                name: "IX_Agents_TemplateId",
94
+                table: "Agents");
95
+
96
+            migrationBuilder.DropColumn(
97
+                name: "SenderId",
98
+                table: "Templates");
99
+
100
+            migrationBuilder.DropColumn(
101
+                name: "TemplateId",
102
+                table: "Individuals");
103
+
104
+            migrationBuilder.DropColumn(
105
+                name: "TemplateId",
106
+                table: "Agents");
107
+
108
+            migrationBuilder.DropColumn(
109
+                name: "Default",
110
+                table: "Accounts");
111
+        }
112
+    }
113
+}

+ 29
- 0
UnivateProperties_API/Migrations/DataContextModelSnapshot.cs Переглянути файл

@@ -148,6 +148,8 @@ namespace UnivateProperties_API.Migrations
148 148
 
149 149
                     b.Property<DateTime>("Created");
150 150
 
151
+                    b.Property<bool>("Default");
152
+
151 153
                     b.Property<string>("DisplayName");
152 154
 
153 155
                     b.Property<bool>("IsDeleted");
@@ -210,10 +212,14 @@ namespace UnivateProperties_API.Migrations
210 212
 
211 213
                     b.Property<string>("Name");
212 214
 
215
+                    b.Property<int?>("SenderId");
216
+
213 217
                     b.Property<string>("Subject");
214 218
 
215 219
                     b.HasKey("Id");
216 220
 
221
+                    b.HasIndex("SenderId");
222
+
217 223
                     b.ToTable("Templates");
218 224
                 });
219 225
 
@@ -903,12 +909,16 @@ namespace UnivateProperties_API.Migrations
903 909
 
904 910
                     b.Property<string>("Telephone");
905 911
 
912
+                    b.Property<int?>("TemplateId");
913
+
906 914
                     b.Property<int?>("UserId");
907 915
 
908 916
                     b.HasKey("Id");
909 917
 
910 918
                     b.HasIndex("AgencyId");
911 919
 
920
+                    b.HasIndex("TemplateId");
921
+
912 922
                     b.HasIndex("UserId");
913 923
 
914 924
                     b.ToTable("Agents");
@@ -949,6 +959,8 @@ namespace UnivateProperties_API.Migrations
949 959
 
950 960
                     b.Property<string>("Telephone");
951 961
 
962
+                    b.Property<int?>("TemplateId");
963
+
952 964
                     b.Property<int?>("UserId");
953 965
 
954 966
                     b.HasKey("Id");
@@ -957,6 +969,8 @@ namespace UnivateProperties_API.Migrations
957 969
 
958 970
                     b.HasIndex("BankAccountId");
959 971
 
972
+                    b.HasIndex("TemplateId");
973
+
960 974
                     b.HasIndex("UserId");
961 975
 
962 976
                     b.HasIndex("Telephone", "CellNumber", "Email")
@@ -1065,6 +1079,13 @@ namespace UnivateProperties_API.Migrations
1065 1079
                         .OnDelete(DeleteBehavior.Cascade);
1066 1080
                 });
1067 1081
 
1082
+            modelBuilder.Entity("UnivateProperties_API.Model.Communication.Template", b =>
1083
+                {
1084
+                    b.HasOne("UnivateProperties_API.Model.Communication.SMTPAccount", "Sender")
1085
+                        .WithMany()
1086
+                        .HasForeignKey("SenderId");
1087
+                });
1088
+
1068 1089
             modelBuilder.Entity("UnivateProperties_API.Model.Misc.Address", b =>
1069 1090
                 {
1070 1091
                     b.HasOne("UnivateProperties_API.Model.Users.Individual", "Owner")
@@ -1231,6 +1252,10 @@ namespace UnivateProperties_API.Migrations
1231 1252
                         .WithMany("Agents")
1232 1253
                         .HasForeignKey("AgencyId");
1233 1254
 
1255
+                    b.HasOne("UnivateProperties_API.Model.Communication.Template")
1256
+                        .WithMany("AgentBCC")
1257
+                        .HasForeignKey("TemplateId");
1258
+
1234 1259
                     b.HasOne("UnivateProperties_API.Model.Users.User", "User")
1235 1260
                         .WithMany()
1236 1261
                         .HasForeignKey("UserId");
@@ -1246,6 +1271,10 @@ namespace UnivateProperties_API.Migrations
1246 1271
                         .WithMany()
1247 1272
                         .HasForeignKey("BankAccountId");
1248 1273
 
1274
+                    b.HasOne("UnivateProperties_API.Model.Communication.Template")
1275
+                        .WithMany("IndividualBCC")
1276
+                        .HasForeignKey("TemplateId");
1277
+
1249 1278
                     b.HasOne("UnivateProperties_API.Model.Users.User", "User")
1250 1279
                         .WithMany()
1251 1280
                         .HasForeignKey("UserId");

+ 66
- 0
UnivateProperties_API/Model/Communication/Email.cs Переглянути файл

@@ -3,6 +3,9 @@ using System;
3 3
 using System.ComponentModel.DataAnnotations.Schema;
4 4
 using System.Net.Mail;
5 5
 using System.Text;
6
+using UnivateProperties_API.Model.Users;
7
+using System.Collections;
8
+using System.Collections.Generic;
6 9
 
7 10
 namespace UnivateProperties_API.Model.Communication
8 11
 {
@@ -30,6 +33,43 @@ namespace UnivateProperties_API.Model.Communication
30 33
             Body = body;
31 34
             Subject = subject;
32 35
         }
36
+
37
+        public Email(Template template, Person sendTo, List<BaseEntity> args)
38
+        {
39
+            if(sendTo != null && MyCommon.IsValidEmail(sendTo.Email))
40
+            {
41
+                if (template.SenderId != null)
42
+                {
43
+                    SenderId = template.SenderId.Value;
44
+                }
45
+                Sender = template.Sender;
46
+                To = sendTo.Email;
47
+                ToDisplay = sendTo.FullName;
48
+                BCC = ConcatEmails(template.AgentBCC, template.IndividualBCC);
49
+                IsBodyHtml = true;
50
+                Body = template.Body;
51
+                Subject = template.Subject;
52
+                foreach(var item in template.PlaceHolders)
53
+                {
54
+                    foreach(var obj in args)
55
+                    {
56
+                        if(obj.GetType() == Type.GetType(item.BoundToClass))
57
+                        {
58
+                            string replaceValue = (string)obj[item.BoundTo];
59
+                            if(Body.Contains(item.Name))
60
+                            {
61
+                                Body = Body.Replace(item.Name, replaceValue);
62
+                            }
63
+                            if(Subject.Contains(item.Name))
64
+                            {
65
+                                Subject = Subject.Replace(item.Name, replaceValue);
66
+                            }
67
+                        }
68
+                    }
69
+                }
70
+            }
71
+            
72
+        }
33 73
         #endregion Constructor
34 74
 
35 75
         #region Properties
@@ -137,6 +177,32 @@ namespace UnivateProperties_API.Model.Communication
137 177
             mail.From = mail.Sender;
138 178
             return mail;
139 179
         }
180
+
181
+        private string ConcatEmails(ICollection<Agent> agents, ICollection<Individual> individuals)
182
+        {
183
+            string value = string.Empty;
184
+            if (agents != null && agents.Count > 0)
185
+            {
186
+                foreach(var item in agents)
187
+                {
188
+                    if(MyCommon.IsValidEmail(item.Email))
189
+                    {
190
+                        value += $"{item.Email};";
191
+                    }
192
+                }
193
+            }
194
+            if (individuals != null && individuals.Count > 0)
195
+            {
196
+                foreach (var item in individuals)
197
+                {
198
+                    if (MyCommon.IsValidEmail(item.Email))
199
+                    {
200
+                        value += $"{item.Email};";
201
+                    }
202
+                }
203
+            }
204
+            return value;
205
+        }
140 206
         #endregion Methods
141 207
     }
142 208
 }

+ 2
- 0
UnivateProperties_API/Model/Communication/SMTPAccount.cs Переглянути файл

@@ -33,11 +33,13 @@ namespace UnivateProperties_API.Model.Communication
33 33
         #region Properties
34 34
         public string Address { get; set; }
35 35
         public string DisplayName { get; set; }
36
+        public bool Default { get; set; }
36 37
         [ForeignKey("SMTPHost")]
37 38
         public int SMTPHostId { get; set; }
38 39
 
39 40
         public virtual SMTPHost SMTPHost { get; set; }
40 41
         public virtual ICollection<Email> Emails { get; set; }
42
+        public virtual ICollection<Template> Templates { get; set; }
41 43
         #endregion Properties
42 44
     }
43 45
 }

+ 7
- 0
UnivateProperties_API/Model/Communication/Template.cs Переглянути файл

@@ -1,4 +1,6 @@
1 1
 using System.Collections.Generic;
2
+using System.ComponentModel.DataAnnotations.Schema;
3
+using UnivateProperties_API.Model.Users;
2 4
 
3 5
 namespace UnivateProperties_API.Model.Communication
4 6
 {
@@ -9,8 +11,13 @@ namespace UnivateProperties_API.Model.Communication
9 11
         public string Name { get; set; }
10 12
         public string Subject { get; set; }
11 13
         public string Body { get; set; }
14
+        [ForeignKey("Sender")]
15
+        public int? SenderId { get; set; }
12 16
 
13 17
         public virtual ICollection<PlaceHolder> PlaceHolders { get; set; }
18
+        public virtual SMTPAccount Sender { get; set; }
19
+        public virtual ICollection<Agent> AgentBCC { get; set; }
20
+        public virtual ICollection<Individual> IndividualBCC { get; set; }
14 21
         #endregion
15 22
     }
16 23
 }

+ 38
- 11
UnivateProperties_API/Model/Timeshare/TimeshareWeek.cs Переглянути файл

@@ -10,21 +10,48 @@ namespace UnivateProperties_API.Model.Timeshare
10 10
 {
11 11
     public class TimeshareWeek : BaseEntity
12 12
     {
13
-        TimeshareWeek()
13
+        public TimeshareWeek()
14 14
         {
15
-
16 15
         }
17 16
 
18
-        TimeshareWeek(WeekDto week)
17
+        public TimeshareWeek(bool referedByAgent, int? agentId, int? agencyId, int ownerId, bool agentAsRep, bool otherResort, string otherResortName, string resortCode, string resortName, int regionId, string season, string module, int bedrooms, int maxSleep, string unitNumber, string weekNumber, double levyAmount, bool currentYearBanked, string bankedWith, bool leviesPaidInFull, bool weekPlacedForRental, double originalPurchasePrice, DateTime originalPurchaseDate, DateTime arrivalDate, DateTime departureDate, double sellPrice, double agentCommision, string mandate, int statusId, Status status, Province region, Individual owner, Agent agent, Agency agency, ICollection<BidItem> bidItems, ICollection<ProcessFlow.ProcessFlow> processFlows)
19 18
         {
20
-            ReferedByAgent = week.ReferedByAgent;
21
-            AgentAsRep = false;
22
-            ResortCode = week.Resort.ResortCode;
23
-            ResortName = week.Resort.ResortName;
24
-            RegionId = week.Region.Id;
25
-            Bedrooms = week.Bedrooms;
26
-            MaxSleep = week.MaxSleep;
27
-            UnitNumber = week.UnitNumber;
19
+            ReferedByAgent = referedByAgent;
20
+            AgentId = agentId;
21
+            AgencyId = agencyId;
22
+            OwnerId = ownerId;
23
+            AgentAsRep = agentAsRep;
24
+            OtherResort = otherResort;
25
+            OtherResortName = otherResortName;
26
+            ResortCode = resortCode;
27
+            ResortName = resortName;
28
+            RegionId = regionId;
29
+            Season = season;
30
+            Module = module;
31
+            Bedrooms = bedrooms;
32
+            MaxSleep = maxSleep;
33
+            UnitNumber = unitNumber;
34
+            WeekNumber = weekNumber;
35
+            LevyAmount = levyAmount;
36
+            CurrentYearBanked = currentYearBanked;
37
+            BankedWith = bankedWith;
38
+            LeviesPaidInFull = leviesPaidInFull;
39
+            WeekPlacedForRental = weekPlacedForRental;
40
+            OriginalPurchasePrice = originalPurchasePrice;
41
+            OriginalPurchaseDate = originalPurchaseDate;
42
+            ArrivalDate = arrivalDate;
43
+            DepartureDate = departureDate;
44
+            SellPrice = sellPrice;
45
+            AgentCommision = agentCommision;
46
+            Mandate = mandate;
47
+            StatusId = statusId;
48
+            Status = status;
49
+            Region = region;
50
+            Owner = owner;
51
+            Agent = agent;
52
+            Agency = agency;
53
+            BidItems = bidItems;
54
+            ProcessFlows = processFlows;
28 55
         }
29 56
 
30 57
         #region Properties

+ 57
- 2
UnivateProperties_API/Repository/Communication/TemplateRepository.cs Переглянути файл

@@ -4,7 +4,10 @@ using System.Collections.Generic;
4 4
 using System.Linq;
5 5
 using UnivateProperties_API.Containers.Communication;
6 6
 using UnivateProperties_API.Context;
7
+using UnivateProperties_API.Model;
7 8
 using UnivateProperties_API.Model.Communication;
9
+using UnivateProperties_API.Model.Timeshare;
10
+using UnivateProperties_API.Model.Users;
8 11
 
9 12
 namespace UnivateProperties_API.Repository.Communication
10 13
 {
@@ -84,10 +87,31 @@ namespace UnivateProperties_API.Repository.Communication
84 87
 
85 88
         public void Update(Template item)
86 89
         {
90
+            var itemList = _dbContext.PlaceHolders.Where(x => x.TemplateId == item.Id).ToList();
91
+            CheckListChange(itemList, item.PlaceHolders.ToList());
87 92
             _dbContext.Entry(item).State = EntityState.Modified;
88 93
             Save();
89 94
         }
90 95
 
96
+        private void CheckListChange(List<PlaceHolder> holderOld, List<PlaceHolder> holderNew)
97
+        {
98
+            foreach (var item in holderOld)
99
+            {
100
+                if (!holderNew.Any(x => x.Id == item.Id))
101
+                {
102
+                    var i = _dbContext.PlaceHolders.FirstOrDefault(x => x.Id == item.Id);
103
+                    if (item != null)
104
+                    {
105
+                        _dbContext.PlaceHolders.Remove(i);
106
+                    }
107
+                }
108
+            }
109
+            foreach (var item in holderNew.Where(x => x.Id == 0))
110
+            {
111
+                _dbContext.Add(item);
112
+            }
113
+        }
114
+
91 115
         public void Save()
92 116
         {
93 117
             _dbContext.SaveChanges();
@@ -107,7 +131,7 @@ namespace UnivateProperties_API.Repository.Communication
107 131
         public List<TemplateDto> GetSimpleAll()
108 132
         {
109 133
             List<TemplateDto> list = new List<TemplateDto>();
110
-            foreach(var item in GetAll())
134
+            foreach (var item in GetAll())
111 135
             {
112 136
                 list.Add(new TemplateDto()
113 137
                 {
@@ -124,10 +148,11 @@ namespace UnivateProperties_API.Repository.Communication
124 148
         private List<PlaceHolderDto> GetPlaceHolders(int id)
125 149
         {
126 150
             List<PlaceHolderDto> list = new List<PlaceHolderDto>();
127
-            foreach(var item in _dbContext.PlaceHolders.Where(x => x.TemplateId == id).ToList())
151
+            foreach (var item in _dbContext.PlaceHolders.Where(x => x.TemplateId == id).ToList())
128 152
             {
129 153
                 list.Add(new PlaceHolderDto()
130 154
                 {
155
+                    Id = item.Id,
131 156
                     Name = item.Name,
132 157
                     BoundTo = item.BoundTo,
133 158
                     BoundToClass = item.BoundToClass,
@@ -136,5 +161,35 @@ namespace UnivateProperties_API.Repository.Communication
136 161
             }
137 162
             return list;
138 163
         }
164
+
165
+        public void SendEmailTemplate(Template template, Person sendTo, List<BaseEntity> args)
166
+        {
167
+            if (template != null)
168
+            {
169
+                if (template.SenderId == null)
170
+                {
171
+                    var acc = _dbContext.Accounts.FirstOrDefault(x => x.Default);
172
+                    if (acc != null)
173
+                    {
174
+                        template.SenderId = acc.Id;
175
+                        template.Sender = acc;
176
+                    }
177
+                }
178
+                else template.Sender = _dbContext.Accounts.FirstOrDefault(x => x.Id == template.SenderId);
179
+                template.PlaceHolders = _dbContext.PlaceHolders.Where(x => x.TemplateId == template.Id).ToList();
180
+                if (sendTo != null)
181
+                {
182
+                    try
183
+                    {
184
+                        Email email = new Email(template, sendTo, args);
185
+                        EmailRepository emailRepo = new EmailRepository(_dbContext);
186
+                        emailRepo.Insert(email);
187
+                    }
188
+                    catch (Exception)
189
+                    {
190
+                    }
191
+                }
192
+            }
193
+        }
139 194
     }
140 195
 }

+ 61
- 2
UnivateProperties_API/Repository/Misc/CarouselRepository.cs Переглянути файл

@@ -1,6 +1,7 @@
1 1
 using Microsoft.EntityFrameworkCore;
2 2
 using System;
3 3
 using System.Collections.Generic;
4
+using System.IO;
4 5
 using System.Linq;
5 6
 using UnivateProperties_API.Containers.Misc;
6 7
 using UnivateProperties_API.Containers.Property;
@@ -56,8 +57,32 @@ namespace UnivateProperties_API.Repository.Misc
56 57
 
57 58
         public void Insert(Carousel item)
58 59
         {
59
-            dBContext.Carousel.Add(item);
60
+            string image = item.Image;
61
+            item.Image = "";
62
+            dBContext.Add(item);
60 63
             Save();
64
+
65
+            bool saveFiles = false;
66
+            var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
67
+            var lastID = item.Id;
68
+            item.Id = lastID;
69
+            if (!string.IsNullOrEmpty(loc))
70
+            {
71
+                saveFiles = true;
72
+                loc = loc.Replace("Properties", "Carousel");
73
+                if (Directory.Exists(loc))
74
+                {
75
+                    Directory.CreateDirectory(loc);
76
+                }
77
+            }
78
+            if (saveFiles)
79
+            {
80
+                string path = ImageFormatter.Base64ToImage(image, loc, lastID.ToString());
81
+                item.Image = path;
82
+            }
83
+
84
+            Update(item);
85
+            
61 86
         }
62 87
 
63 88
         public void Insert(IEnumerable<Carousel> items)
@@ -117,12 +142,13 @@ namespace UnivateProperties_API.Repository.Misc
117 142
             var CarouselList = dBContext.Carousel.ToList();
118 143
 
119 144
             foreach (var item in CarouselList)
120
-            {
145
+            {                
121 146
                 if (!string.IsNullOrEmpty(item.Image) && !item.Image.StartsWith("data:image"))
122 147
                     item.Image = ImageFormatter.ImageToBase64(item.Image);
123 148
 
124 149
                 var carItem = new CarouselList()
125 150
                 {
151
+                    Id = item.Id,
126 152
                     Image = item.Image,
127 153
                     Header = item.Header
128 154
                 };
@@ -147,5 +173,38 @@ namespace UnivateProperties_API.Repository.Misc
147 173
 
148 174
             return list;
149 175
         }
176
+
177
+        public CarouselList GetCarousel(int id)
178
+        {
179
+            var carousel = dBContext.Carousel.Where(c => c.Id == id).FirstOrDefault();
180
+
181
+            CarouselList item = new CarouselList();
182
+            if (carousel != null)
183
+            {
184
+                foreach (string prop in carousel.GetAllProperties())
185
+                {
186
+                    if (prop != "Item" && prop != "Display")
187
+                        item[prop] = carousel[prop];
188
+                }
189
+
190
+                if (item.PropertyId > 0)
191
+                {
192
+                    var property = dBContext.Properties.Include("Province").Include("City").Include("Suburb").Where(p => p.Id == item.PropertyId).FirstOrDefault();
193
+                    item.Address = string.Format("{0}, {1} <br/>{2}", property.Suburb.Description, property.City.Description, property.AddressLine3);
194
+                    item.IsProperty = true;
195
+                }
196
+                if (item.TimeshareId > 0)
197
+                {
198
+                    var timeshare = dBContext.Weeks.Where(t => t.Id == item.TimeshareId).FirstOrDefault();
199
+                    item.Bedrooms = timeshare.Bedrooms;
200
+                    item.Sleeps = timeshare.MaxSleep;
201
+                    item.Arrival = timeshare.ArrivalDate;
202
+                    item.Departure = timeshare.DepartureDate;
203
+                    item.IsProperty = false;
204
+                }
205
+            }
206
+
207
+            return item;
208
+        }
150 209
     }
151 210
 }

+ 1
- 0
UnivateProperties_API/Repository/Misc/ICarouselRepository.cs Переглянути файл

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

+ 54
- 16
UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs Переглянути файл

@@ -4,7 +4,12 @@ using System.Collections.Generic;
4 4
 using System.Linq;
5 5
 using UnivateProperties_API.Containers.ProcessFlow;
6 6
 using UnivateProperties_API.Context;
7
+using UnivateProperties_API.Helpers;
8
+using UnivateProperties_API.Model;
9
+using UnivateProperties_API.Model.Communication;
7 10
 using UnivateProperties_API.Model.ProcessFlow;
11
+using UnivateProperties_API.Repository.Communication;
12
+using UnivateProperties_API.Repository.Timeshare;
8 13
 
9 14
 namespace UnivateProperties_API.Repository.ProccessFlow
10 15
 {
@@ -41,7 +46,7 @@ namespace UnivateProperties_API.Repository.ProccessFlow
41 46
         public List<BidItemDisplay> GetAllBid()
42 47
         {
43 48
             List<BidItem> bids = _dbContext.BidItems
44
-                .Include("Property")                
49
+                .Include("Property")
45 50
                 .Include("TimeshareWeek")
46 51
                 .Include("BidMaker")
47 52
                 .Include("Status")
@@ -77,7 +82,7 @@ namespace UnivateProperties_API.Repository.ProccessFlow
77 82
                     Comment = item.Comment,
78 83
                     DeclineReason = item.DeclinedReason
79 84
                 };
80
-     
85
+
81 86
                 if (item.PropertyId != null)
82 87
                 {
83 88
                     bid.Type = "Property";
@@ -112,12 +117,45 @@ namespace UnivateProperties_API.Repository.ProccessFlow
112 117
 
113 118
         public void Insert(BidItem item)
114 119
         {
115
-            var status = _dbContext.Status.Where(x => x.Code == "E1").FirstOrDefault();
116
-            if (status != null)
117
-                item.StatusId = status.Id;
118
-
119
-            _dbContext.Add(item);
120
-            Save();
120
+            var week = _dbContext.Weeks.Find(item.TimeshareWeekId);
121
+            if (!(item.TimeshareWeek == null && week == null))
122
+            {
123
+                if (week == null && item.TimeshareWeek != null)
124
+                {
125
+                    MyCommon.PostToConsoft(item.TimeshareWeek);
126
+                    WeekRepository weekRepository = new WeekRepository(_dbContext);
127
+                    weekRepository.Insert(item.TimeshareWeek);
128
+                }
129
+                var status = _dbContext.Status.Where(x => x.Code == "E1").FirstOrDefault();
130
+                if (status != null)
131
+                {
132
+                    List<BaseEntity> list = new List<BaseEntity>() { item, week, week.Owner };
133
+                    item.StatusId = status.Id;
134
+                    if (item.TimeshareWeekId != null)
135
+                    {
136
+                        if (week != null)
137
+                        {
138
+                            TemplateRepository templateRepository = new TemplateRepository(_dbContext);
139
+                            var template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekOfferMade-Owner");
140
+                            if (template != null)
141
+                            {
142
+                                templateRepository.SendEmailTemplate(template, week.Owner, list);
143
+                            }
144
+                            template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekOfferMade-User");
145
+                            if (template != null)
146
+                            {
147
+                                var bidMaker = _dbContext.Individuals.FirstOrDefault(x => x.Id == item.BidMakerId);
148
+                                if (bidMaker != null)
149
+                                {
150
+                                    templateRepository.SendEmailTemplate(template, bidMaker, list);
151
+                                }
152
+                            }
153
+                        }
154
+                    }
155
+                }
156
+                _dbContext.Add(item);
157
+                Save();
158
+            }
121 159
         }
122 160
 
123 161
         public void Insert(IEnumerable<BidItem> items)
@@ -165,7 +203,7 @@ namespace UnivateProperties_API.Repository.ProccessFlow
165 203
         }
166 204
 
167 205
         public BidItemDisplay AcceptBid(int id)
168
-        {            
206
+        {
169 207
             var item = _dbContext.BidItems
170 208
                 .Include("Property")
171 209
                 .Include("TimeshareWeek")
@@ -173,13 +211,13 @@ namespace UnivateProperties_API.Repository.ProccessFlow
173 211
                 .Include("Status")
174 212
                 .Where(x => x.Id == id).FirstOrDefault();
175 213
 
176
-            var status =  (from s in _dbContext.Status
177
-                           where s.Code == "E2"                           
178
-                           select s).FirstOrDefault();
214
+            var status = (from s in _dbContext.Status
215
+                          where s.Code == "E2"
216
+                          select s).FirstOrDefault();
179 217
 
180 218
             if (status != null)
181 219
             {
182
-                item.StatusId = status.Id;                
220
+                item.StatusId = status.Id;
183 221
             }
184 222
 
185 223
             _dbContext.Entry(item).State = EntityState.Modified;
@@ -190,7 +228,7 @@ namespace UnivateProperties_API.Repository.ProccessFlow
190 228
         }
191 229
 
192 230
         public BidItemDisplay DecineBid(BitItemDecline item)
193
-        {            
231
+        {
194 232
             var bid = _dbContext.BidItems
195 233
                 .Include("Property")
196 234
                 .Include("TimeshareWeek")
@@ -199,12 +237,12 @@ namespace UnivateProperties_API.Repository.ProccessFlow
199 237
                 .Where(x => x.Id == item.Id).FirstOrDefault();
200 238
 
201 239
             var status = (from s in _dbContext.Status
202
-                          where s.Code == "E3"                          
240
+                          where s.Code == "E3"
203 241
                           select s).FirstOrDefault();
204 242
 
205 243
             if (status != null)
206 244
             {
207
-                bid.StatusId = status.Id;               
245
+                bid.StatusId = status.Id;
208 246
             }
209 247
 
210 248
             bid.DeclinedReason = item.Comment;

+ 3
- 1
UnivateProperties_API/Repository/Properties/IPropertyRepository.cs Переглянути файл

@@ -16,6 +16,8 @@ namespace UnivateProperties_API.Repository.Properties
16 16
         void Insert(PropertyContainer items);
17 17
         PropertyContainer GetDetailed(int id, bool detailed);
18 18
         void Update(PropertyContainer item);
19
-        bool MayEdit(int id);        
19
+        bool MayEdit(int id);
20
+        void InsertImages(int propertyID, List<PropertyImage> Images);
21
+        void InsertFields(int propertyID, List<PropertyUserField> Fields);
20 22
     }
21 23
 }

+ 64
- 23
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Переглянути файл

@@ -548,7 +548,7 @@ namespace UnivateProperties_API.Repository.Properties
548 548
 
549 549
         public List<PropertyDisplay> GetLatestDisplay()
550 550
         {
551
-            List<Property> props = GetAll().OrderBy(x => x.Created).Take(3).ToList();
551
+            List<Property> props = GetAll().OrderByDescending(x => x.Created).Take(3).ToList();
552 552
             return GetDisplayDetails(props);
553 553
         }
554 554
 
@@ -561,16 +561,20 @@ namespace UnivateProperties_API.Repository.Properties
561 561
             if (Type.ToUpper() == "MY")
562 562
             {                
563 563
                 if (individual != null)
564
-                    properties = Get(x => x.OwnerId == individual.Id);
564
+                    properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.OwnerId == individual.Id).ToList();
565 565
                 if (agent != null)
566
-                    properties = Get(x => x.AgentId == agent.Id);
566
+                    properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.AgentId == agent.Id).ToList();
567 567
             }
568
-            else
568
+            else if (Type.ToUpper() == "ADMIN")
569 569
             {
570 570
                 if (individual != null)
571
-                    properties = Get(x => x.OwnerId == individual.Id);
571
+                    properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.OwnerId == individual.Id).ToList();
572 572
                 if (agent != null)
573
-                    properties = Get(x => x.AgencyId == agent.AgencyId);
573
+                    properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.AgencyId == agent.AgencyId).ToList();
574
+            }
575
+            else if (Type.ToUpper() == "SUPERADMIN")
576
+            {
577
+                properties = dBContext.Properties.Include("City").Include("Suburb").ToList();
574 578
             }
575 579
             
576 580
             List<PropertyList> list = new List<PropertyList>();
@@ -583,7 +587,8 @@ namespace UnivateProperties_API.Repository.Properties
583 587
                     Name = string.IsNullOrEmpty(p.PropertyName) ? p.ShortDescription : p.PropertyName,
584 588
                     Price = string.Format("R {0:n}", p.Price),
585 589
                     Publish = p.Published.ToString(),
586
-                    Type = dBContext.PropertyTypes.Find(p.PropertyTypeId)?.Description
590
+                    Type = dBContext.PropertyTypes.Find(p.PropertyTypeId)?.Description,
591
+                    CarouselDescription = string.Format("{0}, {1} <br/>{2}", p.Suburb.Description, p.City.Description, p.AddressLine3)
587 592
                 };
588 593
 
589 594
                 prop.Size = (from u in dBContext.PropertyUserFields
@@ -654,7 +659,7 @@ namespace UnivateProperties_API.Repository.Properties
654 659
 
655 660
             foreach( string prop in property.GetAllProperties())
656 661
             {
657
-                if (prop != "Item")
662
+                if (prop != "Item" && prop != "Display")
658 663
                     property[prop] = items[prop];
659 664
             }
660 665
 
@@ -668,14 +673,9 @@ namespace UnivateProperties_API.Repository.Properties
668 673
 
669 674
             property.Video = property.Video.Replace("https://www.youtube.com/watch?v=", "");
670 675
 
671
-            dBContext.Properties.Add(property);
672
-            Save();
673
-
674 676
             if (images != null)
675 677
             {
676
-                var lastID = (from p in dBContext.PropertyImages
677
-                              orderby p.Id descending
678
-                              select p.Id).FirstOrDefault();
678
+                var lastID = dBContext.GetMaxID("PropertyImages");
679 679
 
680 680
                 bool saveFiles = false;
681 681
                 var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
@@ -689,6 +689,7 @@ namespace UnivateProperties_API.Repository.Properties
689 689
                     }
690 690
                 }
691 691
 
692
+                property.PropertyImages = new List<PropertyImage>();
692 693
                 foreach (PropertyImage image in images)
693 694
                 {
694 695
                     lastID++;
@@ -699,26 +700,27 @@ namespace UnivateProperties_API.Repository.Properties
699 700
                         string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
700 701
                         image.Image = path;
701 702
                     }
702
-                    dBContext.PropertyImages.Add(image);
703
-                    Save();
703
+                    property.PropertyImages.Add(image);
704 704
                 }
705 705
             }
706 706
 
707 707
             if (fields != null)
708 708
             {
709
-                var lastID = (from p in dBContext.PropertyUserFields
710
-                              orderby p.Id descending
711
-                              select p.Id).FirstOrDefault();
712
-
709
+                var lastID = dBContext.GetMaxID("PropertyUserFields");
710
+                property.PropertyUserFields = new List<PropertyUserField>();
713 711
                 foreach (PropertyUserField field in fields)
714 712
                 {
715 713
                     lastID++;
716 714
                     field.Id = lastID;
717 715
                     field.PropertyId = property.Id;
718
-                    dBContext.PropertyUserFields.Add(field);
719
-                    Save();
716
+                    property.PropertyUserFields.Add(field);
720 717
                 }
721 718
             }
719
+
720
+            dBContext.Properties.Add(property);
721
+            Save();
722
+
723
+            items.Id = property.Id;            
722 724
         }
723 725
 
724 726
         public bool MayEdit(int id)
@@ -729,6 +731,45 @@ namespace UnivateProperties_API.Repository.Properties
729 731
                                select b).FirstOrDefault();
730 732
 
731 733
             return (hasBidItems == null) ? true : false;
732
-        }                
734
+        }
735
+
736
+        public void InsertImages(int propertyID, List<PropertyImage> Images)
737
+        {
738
+            if (Images != null)
739
+            {
740
+                var lastID = dBContext.GetMaxID("PropertyImages");
741
+
742
+                bool saveFiles = false;
743
+                var loc = dBContext.Location.FirstOrDefault().PropertyImageLocation;
744
+                if (!string.IsNullOrEmpty(loc))
745
+                {
746
+                    saveFiles = true;
747
+                    loc += string.Format("\\{0}", propertyID);
748
+                    if (Directory.Exists(loc))
749
+                    {
750
+                        Directory.CreateDirectory(loc);
751
+                    }
752
+                }
753
+
754
+                foreach (PropertyImage image in Images)
755
+                {
756
+                    lastID++;
757
+                    image.Id = lastID;
758
+                    image.PropertyId = propertyID;
759
+                    if (saveFiles)
760
+                    {
761
+                        string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
762
+                        image.Image = path;
763
+                    }
764
+                    dBContext.PropertyImages.Add(image);
765
+                    Save();
766
+                }
767
+            }
768
+        }
769
+
770
+        public void InsertFields(int propertyID, List<PropertyUserField> Fields)
771
+        {
772
+            throw new NotImplementedException();
773
+        }
733 774
     }
734 775
 }

+ 17
- 4
UnivateProperties_API/Repository/Region/SuburbRepository.cs Переглянути файл

@@ -115,20 +115,33 @@ namespace UnivateProperties_API.Repository.Region
115 115
 
116 116
         public List<SuburbSearch> GetSearchList()
117 117
         {
118
-            var suburbs = dBContext.Suburbs.Include("City").ToList();
118
+            var suburbs = dBContext.Suburbs.Include("City").Include("City.Province").ToList();
119 119
             List<SuburbSearch> searchList = new List<SuburbSearch>();
120 120
             
121 121
             foreach (var sub in suburbs)
122 122
             {
123 123
                 searchList.Add(new SuburbSearch()
124
-                {
125
-                    Id = sub.Id,
124
+                {                       
125
+                    Province = sub.City.Province.Description,
126
+                    City = sub.City.Description,
126 127
                     Suburb = sub.Description,
127 128
                     Display = string.Format("{0} - {1}", sub.Description, sub.City.Description)
128 129
                 });
129 130
             }
130 131
 
131
-            return searchList;
132
+            var cities = dBContext.Cities.Include("Province").ToList();
133
+            foreach(var city in cities)
134
+            {
135
+                searchList.Add(new SuburbSearch()
136
+                {                    
137
+                    Province = city.Province.Description,
138
+                    City = city.Description,
139
+                    Suburb = "",
140
+                    Display = string.Format("{0}", city.Description)
141
+                });
142
+            }
143
+
144
+            return searchList.OrderBy(s => s.City).ThenBy(s => s.Suburb).ToList();
132 145
         }
133 146
 
134 147
         public List<Suburb> GetByProperty(int propertyId)

+ 53
- 13
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs Переглянути файл

@@ -11,8 +11,11 @@ using UnivateProperties_API.Containers.Timeshare.Detailed;
11 11
 using UnivateProperties_API.Containers.Users;
12 12
 using UnivateProperties_API.Context;
13 13
 using UnivateProperties_API.Helpers;
14
+using UnivateProperties_API.Model;
15
+using UnivateProperties_API.Model.Communication;
14 16
 using UnivateProperties_API.Model.Region;
15 17
 using UnivateProperties_API.Model.Timeshare;
18
+using UnivateProperties_API.Repository.Communication;
16 19
 using UnivateProperties_API.Repository.Region;
17 20
 using UnivateProperties_API.Repository.Users;
18 21
 
@@ -195,33 +198,41 @@ namespace UnivateProperties_API.Repository.Timeshare
195 198
         public void Insert(TimeshareWeek item)
196 199
         {
197 200
             item = GetDetailedWeek(item);
198
-            item.Id = _dbContext.Weeks.Max(x => x.Id) + 1;
199
-            if (item.Owner != null && item.Owner.Id == 0)
200
-            {
201
-                item.Owner.Id = _dbContext.Individuals.Max(x => x.Id) + 1;
202
-            }
203
-            // Set starting Status of A1
204 201
             StatusRepository repo = new StatusRepository(_dbContext);
205
-            item.Status = repo.GetDetailed(s => s.Code == "A1");
206
-            if (item.Status != null)
202
+            var stat = repo.Get(x => x.Code == "A1" && x.StatusType == StatusType.Timeshare).FirstOrDefault();
203
+            if (stat == null)
207 204
             {
208 205
                 //Create initial
209
-                item.Status = new Status()
206
+                stat = new Status()
210 207
                 {
211 208
                     Code = "A1",
212 209
                     Description = "Pending verification",
213 210
                     StatusType = StatusType.Timeshare,
214 211
                     ModifiedBy = "KobusB"
215 212
                 };
213
+                repo.Insert(stat);
216 214
             }
217 215
             item.Id = NewId();
218
-            UnivateProperties_API.Model.ProcessFlow.ProcessFlow flowItem = new Model.ProcessFlow.ProcessFlow()
216
+            item.ProcessFlows.Add(new Model.ProcessFlow.ProcessFlow()
219 217
             {
220 218
                 Status = item.Status,
221 219
                 Timeshare = item
222
-            };
220
+            });
221
+            TemplateRepository templateRepository = new TemplateRepository(_dbContext);
222
+            if(item.Owner != null)
223
+            {
224
+                var template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekLoaded-Owner");
225
+                if(template != null)
226
+                {
227
+                    templateRepository.SendEmailTemplate(template, item.Owner, new List<BaseEntity>() { item, item.Owner });
228
+                }
229
+                template = _dbContext.Templates.FirstOrDefault(x => x.Name == "WeekLoaded-UV");
230
+                if(template != null)
231
+                {
232
+                    templateRepository.SendEmailTemplate(template, item.Owner, new List<BaseEntity>() { item, item.Owner });
233
+                }
234
+            }            
223 235
             _dbContext.Add(item);
224
-            _dbContext.Add(flowItem);
225 236
             Save();
226 237
         }
227 238
 
@@ -317,7 +328,7 @@ namespace UnivateProperties_API.Repository.Timeshare
317 328
             return _TenderId++;
318 329
         }
319 330
 
320
-        private List<WeekDto> GetTenderWeeks()
331
+        public List<WeekDto> GetTenderWeeks()
321 332
         {
322 333
             List<WeekDto> list = new List<WeekDto>();
323 334
             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(MyCommon.TenderUrl);
@@ -389,5 +400,34 @@ namespace UnivateProperties_API.Repository.Timeshare
389 400
             }
390 401
             return detList;
391 402
         }
403
+
404
+        public void VerifyWeek(int id)
405
+        {
406
+            var week = _dbContext.Weeks.FirstOrDefault(x => x.Id == id);
407
+            var newStatus = _dbContext.Status.FirstOrDefault(x => x.Code.ToLower() == "a2" && x.StatusType == StatusType.Timeshare);
408
+            if(week != null && newStatus != null)
409
+            {
410
+                week.Status = newStatus;
411
+                Update(week);
412
+                var template = _dbContext.Templates.Where(x => x.Name == "WeekAuthorized").FirstOrDefault();
413
+                if(template != null)
414
+                {
415
+                    
416
+                    TemplateRepository tempRepo = new TemplateRepository(_dbContext);
417
+                    tempRepo.SendEmailTemplate(template, week.Owner, new List<BaseEntity>() { week, week.Owner});
418
+                }
419
+            }
420
+        }
421
+
422
+        public void PublishWeek(int id)
423
+        {
424
+            var week = _dbContext.Weeks.FirstOrDefault(x => x.Id == id);
425
+            var newStatus = _dbContext.Status.FirstOrDefault(x => x.Code.ToLower() == "b1" && x.StatusType == StatusType.Timeshare);
426
+            if (week != null && newStatus != null)
427
+            {
428
+                week.Status = newStatus;
429
+                Update(week);
430
+            }
431
+        }
392 432
     }
393 433
 }

Завантаження…
Відмінити
Зберегти