瀏覽代碼

Added Added Is Deleted

Added get avail resort
master
Kobus 5 年之前
父節點
當前提交
bc398e31a8
共有 38 個文件被更改,包括 2047 次插入170 次删除
  1. 23
    3
      UnivateProperties_API/Containers/Timeshare/RegionDto.cs
  2. 67
    2
      UnivateProperties_API/Context/DataContext.cs
  3. 12
    0
      UnivateProperties_API/Controllers/Timeshare/TimeshareWeekController.cs
  4. 1
    2
      UnivateProperties_API/Controllers/Users/AgentController.cs
  5. 6
    70
      UnivateProperties_API/Controllers/Users/RegisterController.cs
  6. 1121
    0
      UnivateProperties_API/Migrations/20191003082255_IsDeleted.Designer.cs
  7. 321
    0
      UnivateProperties_API/Migrations/20191003082255_IsDeleted.cs
  8. 94
    3
      UnivateProperties_API/Migrations/DataContextModelSnapshot.cs
  9. 2
    1
      UnivateProperties_API/Model/BaseEntity.cs
  10. 1
    2
      UnivateProperties_API/Model/Users/User.cs
  11. 1
    1
      UnivateProperties_API/Program.cs
  12. 1
    1
      UnivateProperties_API/Properties/launchSettings.json
  13. 30
    0
      UnivateProperties_API/Repository/Banks/BankAccountRepository.cs
  14. 15
    0
      UnivateProperties_API/Repository/Communication/EmailRepository.cs
  15. 15
    0
      UnivateProperties_API/Repository/Communication/SMTPAccountRepository.cs
  16. 15
    0
      UnivateProperties_API/Repository/Communication/SMTPHostRepository.cs
  17. 1
    0
      UnivateProperties_API/Repository/IRepository.cs
  18. 6
    0
      UnivateProperties_API/Repository/Logging/SearchLogRepository.cs
  19. 6
    0
      UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs
  20. 6
    0
      UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs
  21. 7
    1
      UnivateProperties_API/Repository/Properties/PropertyRepository.cs
  22. 6
    0
      UnivateProperties_API/Repository/Properties/PropertyTypeRepository.cs
  23. 6
    0
      UnivateProperties_API/Repository/Properties/PropertyUserFieldRepository.cs
  24. 6
    0
      UnivateProperties_API/Repository/Properties/UserDefinedFieldRepository.cs
  25. 6
    0
      UnivateProperties_API/Repository/Properties/UserDefinedGroupRepository.cs
  26. 18
    3
      UnivateProperties_API/Repository/Region/CityRepository.cs
  27. 18
    3
      UnivateProperties_API/Repository/Region/ProvinceRepository.cs
  28. 18
    3
      UnivateProperties_API/Repository/Region/SuburbRepository.cs
  29. 15
    0
      UnivateProperties_API/Repository/Timeshare/SeasonRepository.cs
  30. 15
    0
      UnivateProperties_API/Repository/Timeshare/StatusRepository.cs
  31. 17
    0
      UnivateProperties_API/Repository/Timeshare/UnitConfigurationRepository.cs
  32. 43
    5
      UnivateProperties_API/Repository/Timeshare/WeekRepository.cs
  33. 19
    8
      UnivateProperties_API/Repository/Users/AgencyRepository.cs
  34. 16
    8
      UnivateProperties_API/Repository/Users/AgentRepository.cs
  35. 19
    1
      UnivateProperties_API/Repository/Users/IndividualRepository.cs
  36. 52
    36
      UnivateProperties_API/Repository/Users/RegisterRepository.cs
  37. 21
    16
      UnivateProperties_API/Repository/Users/UserRepository.cs
  38. 1
    1
      UnivateProperties_API/appsettings.json

+ 23
- 3
UnivateProperties_API/Containers/Timeshare/RegionDto.cs 查看文件

1
-namespace UnivateProperties_API.Containers.Timeshare
1
+using System.Collections.Generic;
2
+using System.Linq;
3
+
4
+namespace UnivateProperties_API.Containers.Timeshare
2
 {
5
 {
3
     public class RegionDto
6
     public class RegionDto
4
     {
7
     {
5
         public RegionDto()
8
         public RegionDto()
6
         {
9
         {
10
+            Resorts = new List<ResortDto>();
11
+        }
7
 
12
 
13
+        public RegionDto(string regionCode, string regionName)
14
+        {
15
+            RegionCode = regionCode;
16
+            RegionName = regionName;
17
+            Resorts = new List<ResortDto>();
8
         }
18
         }
9
 
19
 
10
-        public RegionDto(int id, string regionName, string regionCode)
20
+        public RegionDto(int id, string regionCode, string regionName)
11
         {
21
         {
12
             Id = id;
22
             Id = id;
13
-            RegionName = regionName;
14
             RegionCode = regionCode;
23
             RegionCode = regionCode;
24
+            RegionName = regionName;
25
+            Resorts = new List<ResortDto>();
15
         }
26
         }
16
 
27
 
17
         public int Id { get; set; }
28
         public int Id { get; set; }
18
         public string RegionName { get; set; }
29
         public string RegionName { get; set; }
19
         public string RegionCode { get; set; }
30
         public string RegionCode { get; set; }
31
+        public List<ResortDto> Resorts { get; set; }
32
+
33
+        public void TryAddResort(string resortCode, string resortName)
34
+        {
35
+            if (!Resorts.Any(x => x.ResortCode == resortCode))
36
+            {
37
+                Resorts.Add(new ResortDto(resortCode, resortName));
38
+            }
39
+        }
20
     }
40
     }
21
 }
41
 }

+ 67
- 2
UnivateProperties_API/Context/DataContext.cs 查看文件

70
 
70
 
71
         public override int SaveChanges()
71
         public override int SaveChanges()
72
         {
72
         {
73
-            foreach(var item in ChangeTracker
73
+            foreach (var item in ChangeTracker
74
                                     .Entries()
74
                                     .Entries()
75
                                     .Where(x => x.State == EntityState.Modified || x.State == EntityState.Added)
75
                                     .Where(x => x.State == EntityState.Modified || x.State == EntityState.Added)
76
                                     .Select(x => x.Entity)
76
                                     .Select(x => x.Entity)
77
                                     .ToList())
77
                                     .ToList())
78
             {
78
             {
79
-                if(item is BaseEntity)
79
+                if (item is BaseEntity)
80
                 {
80
                 {
81
                     (item as BaseEntity).UpdateModified(string.Empty);
81
                     (item as BaseEntity).UpdateModified(string.Empty);
82
                 }
82
                 }
83
             }
83
             }
84
+            UpdateSoftDeleteStatuses();
84
             return base.SaveChanges();
85
             return base.SaveChanges();
85
         }
86
         }
86
 
87
 
88
+        private void UpdateSoftDeleteStatuses()
89
+        {
90
+            foreach (var entry in ChangeTracker.Entries())
91
+            {
92
+                switch (entry.State)
93
+                {
94
+                    case EntityState.Added:
95
+                        entry.CurrentValues["IsDeleted"] = false;
96
+                        break;
97
+                    case EntityState.Deleted:
98
+                        entry.State = EntityState.Modified;
99
+                        entry.CurrentValues["IsDeleted"] = true;
100
+                        break;
101
+                }
102
+            }
103
+        }
104
+
87
         protected override void OnModelCreating(ModelBuilder modelBuilder)
105
         protected override void OnModelCreating(ModelBuilder modelBuilder)
88
         {
106
         {
89
             modelBuilder.Entity<SMTPHost>().ToTable("Hosts");
107
             modelBuilder.Entity<SMTPHost>().ToTable("Hosts");
90
             modelBuilder.Entity<UnitConfiguration>()
108
             modelBuilder.Entity<UnitConfiguration>()
91
                 .HasIndex(u => u.Code)
109
                 .HasIndex(u => u.Code)
92
                 .IsUnique();
110
                 .IsUnique();
111
+            modelBuilder.Entity<Individual>(b =>
112
+            {
113
+                b.HasKey(e => e.Id);
114
+                b.Property(e => e.Id).ValueGeneratedOnAdd();
115
+            });
116
+            modelBuilder.Entity<Agent>(b =>
117
+            {
118
+                b.HasKey(e => e.Id);
119
+                b.Property(e => e.Id).ValueGeneratedOnAdd();
120
+            });
121
+            modelBuilder.Entity<Agency>(b =>
122
+            {
123
+                b.HasKey(e => e.Id);
124
+                b.Property(e => e.Id).ValueGeneratedOnAdd();
125
+            });
126
+            modelBuilder.Entity<Person>(b =>
127
+            {
128
+                b.HasKey(e => e.Id);
129
+                b.Property(e => e.Id).ValueGeneratedOnAdd();
130
+            });
131
+            modelBuilder.Entity<Email>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
132
+            modelBuilder.Entity<SMTPAccount>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
133
+            modelBuilder.Entity<SMTPHost>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
134
+            modelBuilder.Entity<Property>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
135
+            modelBuilder.Entity<PropertyImage>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
136
+            modelBuilder.Entity<PropertyType>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
137
+            modelBuilder.Entity<PropertyUserField>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
138
+            modelBuilder.Entity<UserDefinedField>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
139
+            modelBuilder.Entity<UserDefinedGroup>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
140
+            modelBuilder.Entity<City>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
141
+            modelBuilder.Entity<Province>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
142
+            modelBuilder.Entity<Suburb>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
143
+            modelBuilder.Entity<Season>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
144
+            modelBuilder.Entity<Status>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
145
+            modelBuilder.Entity<TimeshareWeek>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
146
+            modelBuilder.Entity<UnitConfiguration>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
147
+            modelBuilder.Entity<UnitConfigurationType>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
148
+            modelBuilder.Entity<Agency>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
149
+            modelBuilder.Entity<Person>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
150
+            modelBuilder.Entity<User>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
151
+            modelBuilder.Entity<Bank>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
152
+            modelBuilder.Entity<BankAccount>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
153
+            modelBuilder.Entity<SearchLog>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
154
+            modelBuilder.Entity<Address>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
155
+            modelBuilder.Entity<BidItem>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
156
+            modelBuilder.Entity<ProcessFlow>().HasQueryFilter(m => EF.Property<bool>(m, "IsDeleted") == false);
157
+
93
         }
158
         }
94
     }
159
     }
95
 }
160
 }

+ 12
- 0
UnivateProperties_API/Controllers/Timeshare/TimeshareWeekController.cs 查看文件

35
             return new OkObjectResult(item);
35
             return new OkObjectResult(item);
36
         }
36
         }
37
 
37
 
38
+        [HttpGet("getAvailResort")]
39
+        public IActionResult GetAvailResort()
40
+        {
41
+            if (_Repo is WeekRepository)
42
+            {
43
+                var item = (_Repo as WeekRepository).GetAvailResort();
44
+                return new OkObjectResult(item);
45
+            }
46
+            else return new OkResult();
47
+
48
+        }
49
+
38
         [HttpGet("getBy")]
50
         [HttpGet("getBy")]
39
         public IActionResult GetBy(WeekFilterDto week)
51
         public IActionResult GetBy(WeekFilterDto week)
40
         {
52
         {

+ 1
- 2
UnivateProperties_API/Controllers/Users/AgentController.cs 查看文件

36
             using (var scope = new TransactionScope())
36
             using (var scope = new TransactionScope())
37
             {
37
             {
38
                 Agent agent = agentDto.Agent;
38
                 Agent agent = agentDto.Agent;
39
-                byte[] passwordHash, passwordSalt;
40
-                MyCommon.CreatePasswordHash(agentDto.Password, out passwordHash, out passwordSalt);
39
+                MyCommon.CreatePasswordHash(agentDto.Password, out byte[] passwordHash, out byte[] passwordSalt);
41
 
40
 
42
                 agent.User.PasswordHash = passwordHash;
41
                 agent.User.PasswordHash = passwordHash;
43
                 agent.User.PasswordSalt = passwordSalt;
42
                 agent.User.PasswordSalt = passwordSalt;

+ 6
- 70
UnivateProperties_API/Controllers/Users/RegisterController.cs 查看文件

1
-using System;
2
-using System.Collections.Generic;
3
-using System.IdentityModel.Tokens.Jwt;
4
-using System.Linq;
5
-using System.Security.Claims;
6
-using System.Text;
7
-using System.Threading.Tasks;
8
-using AutoMapper;
1
+using AutoMapper;
9
 using Microsoft.AspNetCore.Authorization;
2
 using Microsoft.AspNetCore.Authorization;
10
 using Microsoft.AspNetCore.Mvc;
3
 using Microsoft.AspNetCore.Mvc;
11
 using Microsoft.Extensions.Options;
4
 using Microsoft.Extensions.Options;
12
 using Microsoft.IdentityModel.Tokens;
5
 using Microsoft.IdentityModel.Tokens;
6
+using System;
7
+using System.IdentityModel.Tokens.Jwt;
8
+using System.Security.Claims;
9
+using System.Text;
13
 using UnivateProperties_API.Containers.Users;
10
 using UnivateProperties_API.Containers.Users;
14
 using UnivateProperties_API.Helpers;
11
 using UnivateProperties_API.Helpers;
15
 using UnivateProperties_API.Model.Users;
12
 using UnivateProperties_API.Model.Users;
16
-using UnivateProperties_API.Repository;
17
 using UnivateProperties_API.Repository.Users;
13
 using UnivateProperties_API.Repository.Users;
18
-using System.Net.Http;
19
-using System.Net;
20
-using System.Web.Http;
21
 
14
 
22
 namespace UnivateProperties_API.Controllers.Users
15
 namespace UnivateProperties_API.Controllers.Users
23
 {
16
 {
26
     public class RegisterController : ControllerBase
19
     public class RegisterController : ControllerBase
27
     {
20
     {
28
         private readonly IRegisterRepository _Repo;
21
         private readonly IRegisterRepository _Repo;
29
-        private IMapper _mapper;
22
+        private readonly IMapper _mapper;
30
         private readonly AppSettings _appSettings;
23
         private readonly AppSettings _appSettings;
31
 
24
 
32
         public RegisterController(IRegisterRepository repo, IMapper mapper, IOptions<AppSettings> appSettings)
25
         public RegisterController(IRegisterRepository repo, IMapper mapper, IOptions<AppSettings> appSettings)
108
                 return BadRequest(new { message = ex.Message });
101
                 return BadRequest(new { message = ex.Message });
109
             }
102
             }
110
         }
103
         }
111
-
112
-        //[HttpGet("{id}")]
113
-        //public IActionResult GetById(int id)
114
-        //{
115
-        //    var user = _Repo.GetById(id);
116
-        //    var userDto = _mapper.Map<UserDto>(user);
117
-
118
-        //    if (user == null)
119
-        //    {
120
-        //        return NotFound();
121
-        //    }
122
-
123
-        //    // Only allow SuperAdmins to access other user records
124
-        //    var currentUserId = int.Parse(User.Identity.Name);
125
-        //    if (id != currentUserId && !User.IsInRole(Role.SuperAdmin))
126
-        //    {
127
-        //        return Forbid();
128
-        //    }
129
-
130
-        //    return Ok(userDto);
131
-        //}
132
-
133
-        //[HttpGet("{id}")]
134
-        //public IActionResult GetByAgencyId(int id)
135
-        //{
136
-        //    var agency = _Repo.GetByAgencyId(id);
137
-        //    var agencyDto = _mapper.Map<AgencyDto>(agency);
138
-
139
-        //    if (agency == null)
140
-        //    {
141
-        //        return NotFound();
142
-        //    }
143
-
144
-        //    var currentAgencyId = int.Parse(User.Identity.Name);
145
-        //    if (id != currentAgencyId && !User.IsInRole(Role.Agency))
146
-        //    {
147
-        //        return Forbid();
148
-        //    }
149
-
150
-        //    return Ok(agencyDto);
151
-        //}
152
-
153
-        //[Authorize(Roles = Role.SuperAdmin)]
154
-        //[HttpDelete("{id}")]
155
-        //public IActionResult Delete(User user)
156
-        //{
157
-        //    _Repo.Delete(user.Id);
158
-        //    return Ok();
159
-        //}
160
-
161
-        //[Authorize(Roles = Role.SuperAdmin)]
162
-        //[HttpDelete("{id}")]
163
-        //public IActionResult DeleteAgency(Agency agency)
164
-        //{
165
-        //    _Repo.DeleteAgency(agency.Id);
166
-        //    return Ok();
167
-        //}
168
     }
104
     }
169
 }
105
 }

+ 1121
- 0
UnivateProperties_API/Migrations/20191003082255_IsDeleted.Designer.cs
文件差異過大導致無法顯示
查看文件


+ 321
- 0
UnivateProperties_API/Migrations/20191003082255_IsDeleted.cs 查看文件

1
+using System;
2
+using Microsoft.EntityFrameworkCore.Migrations;
3
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
4
+
5
+namespace UnivateProperties_API.Migrations
6
+{
7
+    public partial class IsDeleted : Migration
8
+    {
9
+        protected override void Up(MigrationBuilder migrationBuilder)
10
+        {
11
+            migrationBuilder.AddColumn<bool>(
12
+                name: "IsDeleted",
13
+                table: "Weeks",
14
+                nullable: false,
15
+                defaultValue: false);
16
+
17
+            migrationBuilder.AddColumn<bool>(
18
+                name: "IsDeleted",
19
+                table: "Users",
20
+                nullable: false,
21
+                defaultValue: false);
22
+
23
+            migrationBuilder.AddColumn<bool>(
24
+                name: "IsDeleted",
25
+                table: "UserDefinedGroups",
26
+                nullable: false,
27
+                defaultValue: false);
28
+
29
+            migrationBuilder.AddColumn<bool>(
30
+                name: "IsDeleted",
31
+                table: "UserDefinedFields",
32
+                nullable: false,
33
+                defaultValue: false);
34
+
35
+            migrationBuilder.AddColumn<bool>(
36
+                name: "IsDeleted",
37
+                table: "UnitConfigurationTypes",
38
+                nullable: false,
39
+                defaultValue: false);
40
+
41
+            migrationBuilder.AddColumn<bool>(
42
+                name: "IsDeleted",
43
+                table: "UnitConfigurations",
44
+                nullable: false,
45
+                defaultValue: false);
46
+
47
+            migrationBuilder.AddColumn<bool>(
48
+                name: "IsDeleted",
49
+                table: "Suburbs",
50
+                nullable: false,
51
+                defaultValue: false);
52
+
53
+            migrationBuilder.AddColumn<bool>(
54
+                name: "IsDeleted",
55
+                table: "Status",
56
+                nullable: false,
57
+                defaultValue: false);
58
+
59
+            migrationBuilder.AddColumn<bool>(
60
+                name: "IsDeleted",
61
+                table: "Seasons",
62
+                nullable: false,
63
+                defaultValue: false);
64
+
65
+            migrationBuilder.AddColumn<bool>(
66
+                name: "IsDeleted",
67
+                table: "SearchLogs",
68
+                nullable: false,
69
+                defaultValue: false);
70
+
71
+            migrationBuilder.AddColumn<bool>(
72
+                name: "IsDeleted",
73
+                table: "Provinces",
74
+                nullable: false,
75
+                defaultValue: false);
76
+
77
+            migrationBuilder.AddColumn<bool>(
78
+                name: "IsDeleted",
79
+                table: "PropertyUserFields",
80
+                nullable: false,
81
+                defaultValue: false);
82
+
83
+            migrationBuilder.AddColumn<bool>(
84
+                name: "IsDeleted",
85
+                table: "PropertyTypes",
86
+                nullable: false,
87
+                defaultValue: false);
88
+
89
+            migrationBuilder.AddColumn<bool>(
90
+                name: "IsDeleted",
91
+                table: "PropertyImages",
92
+                nullable: false,
93
+                defaultValue: false);
94
+
95
+            migrationBuilder.AddColumn<bool>(
96
+                name: "IsDeleted",
97
+                table: "Properties",
98
+                nullable: false,
99
+                defaultValue: false);
100
+
101
+            migrationBuilder.AddColumn<bool>(
102
+                name: "IsDeleted",
103
+                table: "ProcessFlows",
104
+                nullable: false,
105
+                defaultValue: false);
106
+
107
+            migrationBuilder.AddColumn<bool>(
108
+                name: "IsDeleted",
109
+                table: "Individuals",
110
+                nullable: false,
111
+                defaultValue: false);
112
+
113
+            migrationBuilder.AddColumn<bool>(
114
+                name: "IsDeleted",
115
+                table: "Hosts",
116
+                nullable: false,
117
+                defaultValue: false);
118
+
119
+            migrationBuilder.AddColumn<bool>(
120
+                name: "IsDeleted",
121
+                table: "Emails",
122
+                nullable: false,
123
+                defaultValue: false);
124
+
125
+            migrationBuilder.AddColumn<bool>(
126
+                name: "IsDeleted",
127
+                table: "Cities",
128
+                nullable: false,
129
+                defaultValue: false);
130
+
131
+            migrationBuilder.AddColumn<bool>(
132
+                name: "IsDeleted",
133
+                table: "BidItems",
134
+                nullable: false,
135
+                defaultValue: false);
136
+
137
+            migrationBuilder.AddColumn<bool>(
138
+                name: "IsDeleted",
139
+                table: "Banks",
140
+                nullable: false,
141
+                defaultValue: false);
142
+
143
+            migrationBuilder.AddColumn<bool>(
144
+                name: "IsDeleted",
145
+                table: "BankAccounts",
146
+                nullable: false,
147
+                defaultValue: false);
148
+
149
+            migrationBuilder.AddColumn<bool>(
150
+                name: "IsDeleted",
151
+                table: "Agents",
152
+                nullable: false,
153
+                defaultValue: false);
154
+
155
+            migrationBuilder.AddColumn<bool>(
156
+                name: "IsDeleted",
157
+                table: "Agencies",
158
+                nullable: false,
159
+                defaultValue: false);
160
+
161
+            migrationBuilder.AddColumn<bool>(
162
+                name: "IsDeleted",
163
+                table: "Addresses",
164
+                nullable: false,
165
+                defaultValue: false);
166
+
167
+            migrationBuilder.AddColumn<bool>(
168
+                name: "IsDeleted",
169
+                table: "Accounts",
170
+                nullable: false,
171
+                defaultValue: false);
172
+
173
+            migrationBuilder.CreateTable(
174
+                name: "Person",
175
+                columns: table => new
176
+                {
177
+                    Id = table.Column<int>(nullable: false)
178
+                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn),
179
+                    Created = table.Column<DateTime>(nullable: false),
180
+                    Modified = table.Column<DateTime>(nullable: false),
181
+                    ModifiedBy = table.Column<string>(nullable: true),
182
+                    IsDeleted = table.Column<bool>(nullable: false),
183
+                    UserId = table.Column<int>(nullable: true),
184
+                    Name = table.Column<string>(nullable: true),
185
+                    Surname = table.Column<string>(nullable: true),
186
+                    Email = table.Column<string>(nullable: true),
187
+                    Telephone = table.Column<string>(nullable: true),
188
+                    CellNumber = table.Column<string>(nullable: true)
189
+                },
190
+                constraints: table =>
191
+                {
192
+                    table.PrimaryKey("PK_Person", x => x.Id);
193
+                    table.ForeignKey(
194
+                        name: "FK_Person_Users_UserId",
195
+                        column: x => x.UserId,
196
+                        principalTable: "Users",
197
+                        principalColumn: "Id",
198
+                        onDelete: ReferentialAction.Restrict);
199
+                });
200
+
201
+            migrationBuilder.CreateIndex(
202
+                name: "IX_Person_UserId",
203
+                table: "Person",
204
+                column: "UserId");
205
+        }
206
+
207
+        protected override void Down(MigrationBuilder migrationBuilder)
208
+        {
209
+            migrationBuilder.DropTable(
210
+                name: "Person");
211
+
212
+            migrationBuilder.DropColumn(
213
+                name: "IsDeleted",
214
+                table: "Weeks");
215
+
216
+            migrationBuilder.DropColumn(
217
+                name: "IsDeleted",
218
+                table: "Users");
219
+
220
+            migrationBuilder.DropColumn(
221
+                name: "IsDeleted",
222
+                table: "UserDefinedGroups");
223
+
224
+            migrationBuilder.DropColumn(
225
+                name: "IsDeleted",
226
+                table: "UserDefinedFields");
227
+
228
+            migrationBuilder.DropColumn(
229
+                name: "IsDeleted",
230
+                table: "UnitConfigurationTypes");
231
+
232
+            migrationBuilder.DropColumn(
233
+                name: "IsDeleted",
234
+                table: "UnitConfigurations");
235
+
236
+            migrationBuilder.DropColumn(
237
+                name: "IsDeleted",
238
+                table: "Suburbs");
239
+
240
+            migrationBuilder.DropColumn(
241
+                name: "IsDeleted",
242
+                table: "Status");
243
+
244
+            migrationBuilder.DropColumn(
245
+                name: "IsDeleted",
246
+                table: "Seasons");
247
+
248
+            migrationBuilder.DropColumn(
249
+                name: "IsDeleted",
250
+                table: "SearchLogs");
251
+
252
+            migrationBuilder.DropColumn(
253
+                name: "IsDeleted",
254
+                table: "Provinces");
255
+
256
+            migrationBuilder.DropColumn(
257
+                name: "IsDeleted",
258
+                table: "PropertyUserFields");
259
+
260
+            migrationBuilder.DropColumn(
261
+                name: "IsDeleted",
262
+                table: "PropertyTypes");
263
+
264
+            migrationBuilder.DropColumn(
265
+                name: "IsDeleted",
266
+                table: "PropertyImages");
267
+
268
+            migrationBuilder.DropColumn(
269
+                name: "IsDeleted",
270
+                table: "Properties");
271
+
272
+            migrationBuilder.DropColumn(
273
+                name: "IsDeleted",
274
+                table: "ProcessFlows");
275
+
276
+            migrationBuilder.DropColumn(
277
+                name: "IsDeleted",
278
+                table: "Individuals");
279
+
280
+            migrationBuilder.DropColumn(
281
+                name: "IsDeleted",
282
+                table: "Hosts");
283
+
284
+            migrationBuilder.DropColumn(
285
+                name: "IsDeleted",
286
+                table: "Emails");
287
+
288
+            migrationBuilder.DropColumn(
289
+                name: "IsDeleted",
290
+                table: "Cities");
291
+
292
+            migrationBuilder.DropColumn(
293
+                name: "IsDeleted",
294
+                table: "BidItems");
295
+
296
+            migrationBuilder.DropColumn(
297
+                name: "IsDeleted",
298
+                table: "Banks");
299
+
300
+            migrationBuilder.DropColumn(
301
+                name: "IsDeleted",
302
+                table: "BankAccounts");
303
+
304
+            migrationBuilder.DropColumn(
305
+                name: "IsDeleted",
306
+                table: "Agents");
307
+
308
+            migrationBuilder.DropColumn(
309
+                name: "IsDeleted",
310
+                table: "Agencies");
311
+
312
+            migrationBuilder.DropColumn(
313
+                name: "IsDeleted",
314
+                table: "Addresses");
315
+
316
+            migrationBuilder.DropColumn(
317
+                name: "IsDeleted",
318
+                table: "Accounts");
319
+        }
320
+    }
321
+}

+ 94
- 3
UnivateProperties_API/Migrations/DataContextModelSnapshot.cs 查看文件

16
 #pragma warning disable 612, 618
16
 #pragma warning disable 612, 618
17
             modelBuilder
17
             modelBuilder
18
                 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
18
                 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
19
-                .HasAnnotation("ProductVersion", "2.2.4-servicing-10062")
19
+                .HasAnnotation("ProductVersion", "2.2.6-servicing-10079")
20
                 .HasAnnotation("Relational:MaxIdentifierLength", 63);
20
                 .HasAnnotation("Relational:MaxIdentifierLength", 63);
21
 
21
 
22
             modelBuilder.Entity("UnivateProperties_API.Model.Banks.Bank", b =>
22
             modelBuilder.Entity("UnivateProperties_API.Model.Banks.Bank", b =>
26
 
26
 
27
                     b.Property<DateTime>("Created");
27
                     b.Property<DateTime>("Created");
28
 
28
 
29
+                    b.Property<bool>("IsDeleted");
30
+
29
                     b.Property<DateTime>("Modified");
31
                     b.Property<DateTime>("Modified");
30
 
32
 
31
                     b.Property<string>("ModifiedBy");
33
                     b.Property<string>("ModifiedBy");
52
 
54
 
53
                     b.Property<DateTime>("Created");
55
                     b.Property<DateTime>("Created");
54
 
56
 
57
+                    b.Property<bool>("IsDeleted");
58
+
55
                     b.Property<DateTime>("Modified");
59
                     b.Property<DateTime>("Modified");
56
 
60
 
57
                     b.Property<string>("ModifiedBy");
61
                     b.Property<string>("ModifiedBy");
84
 
88
 
85
                     b.Property<bool>("IsBodyHtml");
89
                     b.Property<bool>("IsBodyHtml");
86
 
90
 
91
+                    b.Property<bool>("IsDeleted");
92
+
87
                     b.Property<DateTime>("Modified");
93
                     b.Property<DateTime>("Modified");
88
 
94
 
89
                     b.Property<string>("ModifiedBy");
95
                     b.Property<string>("ModifiedBy");
114
 
120
 
115
                     b.Property<string>("DisplayName");
121
                     b.Property<string>("DisplayName");
116
 
122
 
123
+                    b.Property<bool>("IsDeleted");
124
+
117
                     b.Property<DateTime>("Modified");
125
                     b.Property<DateTime>("Modified");
118
 
126
 
119
                     b.Property<string>("ModifiedBy");
127
                     b.Property<string>("ModifiedBy");
136
 
144
 
137
                     b.Property<string>("Host");
145
                     b.Property<string>("Host");
138
 
146
 
147
+                    b.Property<bool>("IsDeleted");
148
+
139
                     b.Property<DateTime>("Modified");
149
                     b.Property<DateTime>("Modified");
140
 
150
 
141
                     b.Property<string>("ModifiedBy");
151
                     b.Property<string>("ModifiedBy");
160
 
170
 
161
                     b.Property<DateTime>("Created");
171
                     b.Property<DateTime>("Created");
162
 
172
 
173
+                    b.Property<bool>("IsDeleted");
174
+
163
                     b.Property<DateTime>("Modified");
175
                     b.Property<DateTime>("Modified");
164
 
176
 
165
                     b.Property<string>("ModifiedBy");
177
                     b.Property<string>("ModifiedBy");
166
 
178
 
167
                     b.Property<string>("Search");
179
                     b.Property<string>("Search");
168
 
180
 
169
-                    b.Property<int?>("UserID");
181
+                    b.Property<string>("Type");
170
 
182
 
171
                     b.HasKey("Id");
183
                     b.HasKey("Id");
172
 
184
 
182
 
194
 
183
                     b.Property<DateTime>("Created");
195
                     b.Property<DateTime>("Created");
184
 
196
 
197
+                    b.Property<bool>("IsDeleted");
198
+
185
                     b.Property<DateTime>("Modified");
199
                     b.Property<DateTime>("Modified");
186
 
200
 
187
                     b.Property<string>("ModifiedBy");
201
                     b.Property<string>("ModifiedBy");
214
 
228
 
215
                     b.Property<string>("DeclinedReason");
229
                     b.Property<string>("DeclinedReason");
216
 
230
 
231
+                    b.Property<bool>("IsDeleted");
232
+
217
                     b.Property<DateTime>("Modified");
233
                     b.Property<DateTime>("Modified");
218
 
234
 
219
                     b.Property<string>("ModifiedBy");
235
                     b.Property<string>("ModifiedBy");
244
 
260
 
245
                     b.Property<DateTime>("Created");
261
                     b.Property<DateTime>("Created");
246
 
262
 
263
+                    b.Property<bool>("IsDeleted");
264
+
247
                     b.Property<DateTime>("Modified");
265
                     b.Property<DateTime>("Modified");
248
 
266
 
249
                     b.Property<string>("ModifiedBy");
267
                     b.Property<string>("ModifiedBy");
286
 
304
 
287
                     b.Property<string>("Description");
305
                     b.Property<string>("Description");
288
 
306
 
289
-                    b.Property<int?>("GCRecord");
307
+                    b.Property<bool>("IsDeleted");
290
 
308
 
291
                     b.Property<bool>("IsSale");
309
                     b.Property<bool>("IsSale");
292
 
310
 
350
 
368
 
351
                     b.Property<bool>("IsDefault");
369
                     b.Property<bool>("IsDefault");
352
 
370
 
371
+                    b.Property<bool>("IsDeleted");
372
+
353
                     b.Property<DateTime>("Modified");
373
                     b.Property<DateTime>("Modified");
354
 
374
 
355
                     b.Property<string>("ModifiedBy");
375
                     b.Property<string>("ModifiedBy");
372
 
392
 
373
                     b.Property<string>("Description");
393
                     b.Property<string>("Description");
374
 
394
 
395
+                    b.Property<bool>("IsDeleted");
396
+
375
                     b.Property<DateTime>("Modified");
397
                     b.Property<DateTime>("Modified");
376
 
398
 
377
                     b.Property<string>("ModifiedBy");
399
                     b.Property<string>("ModifiedBy");
392
 
414
 
393
                     b.Property<string>("Description");
415
                     b.Property<string>("Description");
394
 
416
 
417
+                    b.Property<bool>("IsDeleted");
418
+
395
                     b.Property<DateTime>("Modified");
419
                     b.Property<DateTime>("Modified");
396
 
420
 
397
                     b.Property<string>("ModifiedBy");
421
                     b.Property<string>("ModifiedBy");
424
 
448
 
425
                     b.Property<int>("GroupId");
449
                     b.Property<int>("GroupId");
426
 
450
 
451
+                    b.Property<bool>("IsDeleted");
452
+
427
                     b.Property<DateTime>("Modified");
453
                     b.Property<DateTime>("Modified");
428
 
454
 
429
                     b.Property<string>("ModifiedBy");
455
                     b.Property<string>("ModifiedBy");
446
 
472
 
447
                     b.Property<string>("Description");
473
                     b.Property<string>("Description");
448
 
474
 
475
+                    b.Property<bool>("IsDeleted");
476
+
449
                     b.Property<DateTime>("Modified");
477
                     b.Property<DateTime>("Modified");
450
 
478
 
451
                     b.Property<string>("ModifiedBy");
479
                     b.Property<string>("ModifiedBy");
470
 
498
 
471
                     b.Property<string>("Description");
499
                     b.Property<string>("Description");
472
 
500
 
501
+                    b.Property<bool>("IsDeleted");
502
+
473
                     b.Property<DateTime>("Modified");
503
                     b.Property<DateTime>("Modified");
474
 
504
 
475
                     b.Property<string>("ModifiedBy");
505
                     b.Property<string>("ModifiedBy");
494
 
524
 
495
                     b.Property<string>("Description");
525
                     b.Property<string>("Description");
496
 
526
 
527
+                    b.Property<bool>("IsDeleted");
528
+
497
                     b.Property<DateTime>("Modified");
529
                     b.Property<DateTime>("Modified");
498
 
530
 
499
                     b.Property<string>("ModifiedBy");
531
                     b.Property<string>("ModifiedBy");
514
 
546
 
515
                     b.Property<string>("Description");
547
                     b.Property<string>("Description");
516
 
548
 
549
+                    b.Property<bool>("IsDeleted");
550
+
517
                     b.Property<DateTime>("Modified");
551
                     b.Property<DateTime>("Modified");
518
 
552
 
519
                     b.Property<string>("ModifiedBy");
553
                     b.Property<string>("ModifiedBy");
534
 
568
 
535
                     b.Property<DateTime>("Created");
569
                     b.Property<DateTime>("Created");
536
 
570
 
571
+                    b.Property<bool>("IsDeleted");
572
+
537
                     b.Property<DateTime>("Modified");
573
                     b.Property<DateTime>("Modified");
538
 
574
 
539
                     b.Property<string>("ModifiedBy");
575
                     b.Property<string>("ModifiedBy");
556
 
592
 
557
                     b.Property<string>("Description");
593
                     b.Property<string>("Description");
558
 
594
 
595
+                    b.Property<bool>("IsDeleted");
596
+
559
                     b.Property<DateTime>("Modified");
597
                     b.Property<DateTime>("Modified");
560
 
598
 
561
                     b.Property<string>("ModifiedBy");
599
                     b.Property<string>("ModifiedBy");
590
 
628
 
591
                     b.Property<DateTime>("DepartureDate");
629
                     b.Property<DateTime>("DepartureDate");
592
 
630
 
631
+                    b.Property<bool>("IsDeleted");
632
+
593
                     b.Property<bool>("LeviesPaidInFull");
633
                     b.Property<bool>("LeviesPaidInFull");
594
 
634
 
595
                     b.Property<double>("LevyAmount");
635
                     b.Property<double>("LevyAmount");
660
 
700
 
661
                     b.Property<DateTime>("Created");
701
                     b.Property<DateTime>("Created");
662
 
702
 
703
+                    b.Property<bool>("IsDeleted");
704
+
663
                     b.Property<DateTime>("Modified");
705
                     b.Property<DateTime>("Modified");
664
 
706
 
665
                     b.Property<string>("ModifiedBy");
707
                     b.Property<string>("ModifiedBy");
681
 
723
 
682
                     b.Property<string>("Description");
724
                     b.Property<string>("Description");
683
 
725
 
726
+                    b.Property<bool>("IsDeleted");
727
+
684
                     b.Property<DateTime>("Modified");
728
                     b.Property<DateTime>("Modified");
685
 
729
 
686
                     b.Property<string>("ModifiedBy");
730
                     b.Property<string>("ModifiedBy");
707
 
751
 
708
                     b.Property<string>("EAABEFFCNumber");
752
                     b.Property<string>("EAABEFFCNumber");
709
 
753
 
754
+                    b.Property<bool>("IsDeleted");
755
+
710
                     b.Property<DateTime>("Modified");
756
                     b.Property<DateTime>("Modified");
711
 
757
 
712
                     b.Property<string>("ModifiedBy");
758
                     b.Property<string>("ModifiedBy");
729
 
775
 
730
                     b.Property<string>("Email");
776
                     b.Property<string>("Email");
731
 
777
 
778
+                    b.Property<bool>("IsDeleted");
779
+
732
                     b.Property<DateTime>("Modified");
780
                     b.Property<DateTime>("Modified");
733
 
781
 
734
                     b.Property<string>("ModifiedBy");
782
                     b.Property<string>("ModifiedBy");
769
 
817
 
770
                     b.Property<string>("IncomeTaxNumber");
818
                     b.Property<string>("IncomeTaxNumber");
771
 
819
 
820
+                    b.Property<bool>("IsDeleted");
821
+
772
                     b.Property<string>("MaritalStatus");
822
                     b.Property<string>("MaritalStatus");
773
 
823
 
774
                     b.Property<DateTime>("Modified");
824
                     b.Property<DateTime>("Modified");
792
                     b.ToTable("Individuals");
842
                     b.ToTable("Individuals");
793
                 });
843
                 });
794
 
844
 
845
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.Person", b =>
846
+                {
847
+                    b.Property<int>("Id")
848
+                        .ValueGeneratedOnAdd();
849
+
850
+                    b.Property<string>("CellNumber");
851
+
852
+                    b.Property<DateTime>("Created");
853
+
854
+                    b.Property<string>("Email");
855
+
856
+                    b.Property<bool>("IsDeleted");
857
+
858
+                    b.Property<DateTime>("Modified");
859
+
860
+                    b.Property<string>("ModifiedBy");
861
+
862
+                    b.Property<string>("Name");
863
+
864
+                    b.Property<string>("Surname");
865
+
866
+                    b.Property<string>("Telephone");
867
+
868
+                    b.Property<int?>("UserId");
869
+
870
+                    b.HasKey("Id");
871
+
872
+                    b.HasIndex("UserId");
873
+
874
+                    b.ToTable("Person");
875
+                });
876
+
795
             modelBuilder.Entity("UnivateProperties_API.Model.Users.User", b =>
877
             modelBuilder.Entity("UnivateProperties_API.Model.Users.User", b =>
796
                 {
878
                 {
797
                     b.Property<int>("Id")
879
                     b.Property<int>("Id")
799
 
881
 
800
                     b.Property<DateTime>("Created");
882
                     b.Property<DateTime>("Created");
801
 
883
 
884
+                    b.Property<bool>("IsDeleted");
885
+
802
                     b.Property<DateTime>("Modified");
886
                     b.Property<DateTime>("Modified");
803
 
887
 
804
                     b.Property<string>("ModifiedBy");
888
                     b.Property<string>("ModifiedBy");
1022
                         .WithMany()
1106
                         .WithMany()
1023
                         .HasForeignKey("UserId");
1107
                         .HasForeignKey("UserId");
1024
                 });
1108
                 });
1109
+
1110
+            modelBuilder.Entity("UnivateProperties_API.Model.Users.Person", b =>
1111
+                {
1112
+                    b.HasOne("UnivateProperties_API.Model.Users.User", "User")
1113
+                        .WithMany()
1114
+                        .HasForeignKey("UserId");
1115
+                });
1025
 #pragma warning restore 612, 618
1116
 #pragma warning restore 612, 618
1026
         }
1117
         }
1027
     }
1118
     }

+ 2
- 1
UnivateProperties_API/Model/BaseEntity.cs 查看文件

5
 
5
 
6
 namespace UnivateProperties_API.Model
6
 namespace UnivateProperties_API.Model
7
 {
7
 {
8
-    public abstract class BaseEntity
8
+    public class BaseEntity
9
     {
9
     {
10
         #region Properties
10
         #region Properties
11
         [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
11
         [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
16
         public string ModifiedBy { get; set; }
16
         public string ModifiedBy { get; set; }
17
         [NotMapped]
17
         [NotMapped]
18
         public ValidateEntity Valid { get; set; }
18
         public ValidateEntity Valid { get; set; }
19
+        public bool IsDeleted { get; set; } = false;
19
         #endregion
20
         #endregion
20
 
21
 
21
         #region Methods
22
         #region Methods

+ 1
- 2
UnivateProperties_API/Model/Users/User.cs 查看文件

9
         {
9
         {
10
             Username = username;
10
             Username = username;
11
 
11
 
12
-            byte[] passwordHash, passwordSalt;
13
-            MyCommon.CreatePasswordHash(password, out passwordHash, out passwordSalt);
12
+            MyCommon.CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt);
14
 
13
 
15
             PasswordHash = passwordHash;
14
             PasswordHash = passwordHash;
16
             PasswordSalt = passwordSalt;
15
             PasswordSalt = passwordSalt;

+ 1
- 1
UnivateProperties_API/Program.cs 查看文件

18
         public static IWebHost BuildWebHost(string[] args) =>
18
         public static IWebHost BuildWebHost(string[] args) =>
19
             WebHost.CreateDefaultBuilder(args)
19
             WebHost.CreateDefaultBuilder(args)
20
                 .UseStartup<Startup>()
20
                 .UseStartup<Startup>()
21
-                .UseUrls("http://192.168.6.188/Univate-API")
21
+                .UseUrls("http://192.168.6.188:5000")
22
                 .Build();
22
                 .Build();
23
     }
23
     }
24
 }
24
 }

+ 1
- 1
UnivateProperties_API/Properties/launchSettings.json 查看文件

24
       "environmentVariables": {
24
       "environmentVariables": {
25
         "ASPNETCORE_ENVIRONMENT": "Development"
25
         "ASPNETCORE_ENVIRONMENT": "Development"
26
       },
26
       },
27
-      "applicationUrl": "http://localhost:5000"
27
+      "applicationUrl": "http://192.168.6.188:5000"
28
     }
28
     }
29
   }
29
   }
30
 }
30
 }

+ 30
- 0
UnivateProperties_API/Repository/Banks/BankAccountRepository.cs 查看文件

51
 
51
 
52
         public void Insert(Bank item)
52
         public void Insert(Bank item)
53
         {
53
         {
54
+            item.Id = NewBankId();
54
             _dbContext.Add(item);
55
             _dbContext.Add(item);
55
             Save();
56
             Save();
56
         }
57
         }
57
 
58
 
58
         public void Insert(IEnumerable<Bank> items)
59
         public void Insert(IEnumerable<Bank> items)
59
         {
60
         {
61
+            int id = NewBankId();
60
             foreach (var item in items)
62
             foreach (var item in items)
61
             {
63
             {
64
+                item.Id = id;
62
                 _dbContext.Add(item);
65
                 _dbContext.Add(item);
66
+                id += 1;
63
             }
67
             }
64
             Save();
68
             Save();
65
         }
69
         }
66
 
70
 
67
         public void Insert(BankAccount item)
71
         public void Insert(BankAccount item)
68
         {
72
         {
73
+            item.Id = NewId();
69
             _dbContext.Add(item);
74
             _dbContext.Add(item);
70
             Save();
75
             Save();
71
         }
76
         }
72
 
77
 
73
         public void Insert(IEnumerable<BankAccount> items)
78
         public void Insert(IEnumerable<BankAccount> items)
74
         {
79
         {
80
+            int id = NewId();
75
             foreach (var item in items)
81
             foreach (var item in items)
76
             {
82
             {
83
+                item.Id = id;
77
                 _dbContext.Add(item);
84
                 _dbContext.Add(item);
85
+                id += 1;
78
             }
86
             }
79
             Save();
87
             Save();
80
         }
88
         }
146
         {
154
         {
147
             return _dbContext.BankAccounts.ToList();
155
             return _dbContext.BankAccounts.ToList();
148
         }
156
         }
157
+
158
+        public int NewId()
159
+        {
160
+            int id = 0;
161
+            if (_dbContext.BankAccounts.Count() > 0)
162
+            {
163
+                _dbContext.BankAccounts.Max(x => x.Id);
164
+            }
165
+            id += 1;
166
+            return id;
167
+        }
168
+
169
+        public int NewBankId()
170
+        {
171
+            int id = 0;
172
+            if (_dbContext.Banks.Count() > 0)
173
+            {
174
+                _dbContext.Banks.Max(x => x.Id);
175
+            }
176
+            id += 1;
177
+            return id;
178
+        }
149
     }
179
     }
150
 }
180
 }

+ 15
- 0
UnivateProperties_API/Repository/Communication/EmailRepository.cs 查看文件

55
         {
55
         {
56
             SMTPAccountRepository account = new SMTPAccountRepository(_dbContext);
56
             SMTPAccountRepository account = new SMTPAccountRepository(_dbContext);
57
             item = GetDetailedObject(item, account);
57
             item = GetDetailedObject(item, account);
58
+            item.Id = NewId();
58
             item.SendMail();
59
             item.SendMail();
59
             _dbContext.Add(item);
60
             _dbContext.Add(item);
60
             Save();
61
             Save();
62
 
63
 
63
         public void Insert(IEnumerable<Email> items)
64
         public void Insert(IEnumerable<Email> items)
64
         {
65
         {
66
+            int id = NewId();
65
             foreach (var item in items)
67
             foreach (var item in items)
66
             {
68
             {
69
+                item.Id = id;
67
                 item.SendMail();
70
                 item.SendMail();
68
                 _dbContext.Add(item);
71
                 _dbContext.Add(item);
72
+                id += 1;
69
             }
73
             }
70
             Save();
74
             Save();
71
         }
75
         }
104
         {
108
         {
105
             _dbContext.SaveChanges();
109
             _dbContext.SaveChanges();
106
         }
110
         }
111
+
112
+        public int NewId()
113
+        {
114
+            int id = 0;
115
+            if (_dbContext.Emails.Count() > 0)
116
+            {
117
+                id = _dbContext.Emails.Max(x => x.Id);
118
+            }
119
+            id += 1;
120
+            return id;
121
+        }
107
     }
122
     }
108
 }
123
 }

+ 15
- 0
UnivateProperties_API/Repository/Communication/SMTPAccountRepository.cs 查看文件

47
 
47
 
48
         public void Insert(SMTPAccount item)
48
         public void Insert(SMTPAccount item)
49
         {
49
         {
50
+            item.Id = NewId();
50
             _dbContext.Add(item);
51
             _dbContext.Add(item);
51
             Save();
52
             Save();
52
         }
53
         }
53
 
54
 
54
         public void Insert(IEnumerable<SMTPAccount> items)
55
         public void Insert(IEnumerable<SMTPAccount> items)
55
         {
56
         {
57
+            int id = NewId();
56
             foreach (var item in items)
58
             foreach (var item in items)
57
             {
59
             {
60
+                item.Id = id;
58
                 _dbContext.Add(item);
61
                 _dbContext.Add(item);
62
+                id += 1;
59
             }
63
             }
60
             Save();
64
             Save();
61
         }
65
         }
94
         {
98
         {
95
             _dbContext.SaveChanges();
99
             _dbContext.SaveChanges();
96
         }
100
         }
101
+
102
+        public int NewId()
103
+        {
104
+            int id = 0;
105
+            if (_dbContext.Accounts.Count() > 0)
106
+            {
107
+                id = _dbContext.Accounts.Max(x => x.Id);
108
+            }
109
+            id += 1;
110
+            return id;
111
+        }
97
     }
112
     }
98
 }
113
 }

+ 15
- 0
UnivateProperties_API/Repository/Communication/SMTPHostRepository.cs 查看文件

38
 
38
 
39
         public void Insert(SMTPHost item)
39
         public void Insert(SMTPHost item)
40
         {
40
         {
41
+            item.Id = NewId();
41
             _dbContext.Add(item);
42
             _dbContext.Add(item);
42
             Save();
43
             Save();
43
         }
44
         }
44
 
45
 
45
         public void Insert(IEnumerable<SMTPHost> items)
46
         public void Insert(IEnumerable<SMTPHost> items)
46
         {
47
         {
48
+            int id = NewId();
47
             foreach (var item in items)
49
             foreach (var item in items)
48
             {
50
             {
51
+                item.Id = id;
49
                 _dbContext.Add(item);
52
                 _dbContext.Add(item);
53
+                id += 1;
50
             }
54
             }
51
             Save();
55
             Save();
52
         }
56
         }
85
         {
89
         {
86
             _dbContext.SaveChanges();
90
             _dbContext.SaveChanges();
87
         }
91
         }
92
+
93
+        public int NewId()
94
+        {
95
+            int id = 0;
96
+            if (_dbContext.Hosts.Count() > 0)
97
+            {
98
+                id = _dbContext.Hosts.Max(x => x.Id);
99
+            }
100
+            id += 1;
101
+            return id;
102
+        }
88
     }
103
     }
89
 }
104
 }

+ 1
- 0
UnivateProperties_API/Repository/IRepository.cs 查看文件

16
         void Remove(IEnumerable<TEntity> items);
16
         void Remove(IEnumerable<TEntity> items);
17
         void RemoveAtId(int item);
17
         void RemoveAtId(int item);
18
         void Update(TEntity item);
18
         void Update(TEntity item);
19
+        int NewId();
19
         void Save();
20
         void Save();
20
     }
21
     }
21
 }
22
 }

+ 6
- 0
UnivateProperties_API/Repository/Logging/SearchLogRepository.cs 查看文件

143
             _dbContext.Entry(item).State = EntityState.Modified;
143
             _dbContext.Entry(item).State = EntityState.Modified;
144
             Save();
144
             Save();
145
         }
145
         }
146
+
147
+        public int NewId()
148
+        {
149
+            // Not sure if properties need it
150
+            return 0;
151
+        }
146
     }
152
     }
147
 }
153
 }

+ 6
- 0
UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs 查看文件

215
             List<BidItem> bids = new List<BidItem>() { bid };
215
             List<BidItem> bids = new List<BidItem>() { bid };
216
             return LoadDisplay(bids).Find(x => x.Id == bid.Id);
216
             return LoadDisplay(bids).Find(x => x.Id == bid.Id);
217
         }
217
         }
218
+
219
+        public int NewId()
220
+        {
221
+            // Not sure if properties need it
222
+            return 0;
223
+        }
218
     }
224
     }
219
 }
225
 }

+ 6
- 0
UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs 查看文件

94
             dBContext.Entry(item).State = EntityState.Modified;
94
             dBContext.Entry(item).State = EntityState.Modified;
95
             Save();
95
             Save();
96
         }
96
         }
97
+
98
+        public int NewId()
99
+        {
100
+            // Not sure if properties need it
101
+            return 0;
102
+        }
97
     }
103
     }
98
 }
104
 }

+ 7
- 1
UnivateProperties_API/Repository/Properties/PropertyRepository.cs 查看文件

439
             }
439
             }
440
                 
440
                 
441
             return list;
441
             return list;
442
-        }       
442
+        }
443
+
444
+        public int NewId()
445
+        {
446
+            // Not sure if properties need it
447
+            return 0;
448
+        }
443
     }
449
     }
444
 }
450
 }

+ 6
- 0
UnivateProperties_API/Repository/Properties/PropertyTypeRepository.cs 查看文件

86
             dBContext.Entry(item).State = EntityState.Modified;
86
             dBContext.Entry(item).State = EntityState.Modified;
87
             Save();
87
             Save();
88
         }
88
         }
89
+
90
+        public int NewId()
91
+        {
92
+            // Not sure if properties need it
93
+            return 0;
94
+        }
89
     }
95
     }
90
 }
96
 }

+ 6
- 0
UnivateProperties_API/Repository/Properties/PropertyUserFieldRepository.cs 查看文件

86
             dBContext.Entry(item).State = EntityState.Modified;
86
             dBContext.Entry(item).State = EntityState.Modified;
87
             Save();
87
             Save();
88
         }
88
         }
89
+
90
+        public int NewId()
91
+        {
92
+            // Not sure if properties need it
93
+            return 0;
94
+        }
89
     }
95
     }
90
 }
96
 }

+ 6
- 0
UnivateProperties_API/Repository/Properties/UserDefinedFieldRepository.cs 查看文件

86
             dBContext.Entry(item).State = EntityState.Modified;
86
             dBContext.Entry(item).State = EntityState.Modified;
87
             Save();
87
             Save();
88
         }
88
         }
89
+
90
+        public int NewId()
91
+        {
92
+            // Not sure if properties need it
93
+            return 0;
94
+        }
89
     }
95
     }
90
 }
96
 }

+ 6
- 0
UnivateProperties_API/Repository/Properties/UserDefinedGroupRepository.cs 查看文件

192
             dBContext.Entry(item).State = EntityState.Modified;
192
             dBContext.Entry(item).State = EntityState.Modified;
193
             Save();
193
             Save();
194
         }
194
         }
195
+
196
+        public int NewId()
197
+        {
198
+            // Not sure if properties need it
199
+            return 0;
200
+        }
195
     }
201
     }
196
 }
202
 }

+ 18
- 3
UnivateProperties_API/Repository/Region/CityRepository.cs 查看文件

47
 
47
 
48
         public void Insert(City item)
48
         public void Insert(City item)
49
         {
49
         {
50
-            dBContext.Cities.Add(item);
50
+            item.Id = NewId();
51
+            dBContext.Add(item);
51
             Save();
52
             Save();
52
         }
53
         }
53
 
54
 
54
         public void Insert(IEnumerable<City> items)
55
         public void Insert(IEnumerable<City> items)
55
         {
56
         {
57
+            int id = NewId();
56
             foreach (var item in items)
58
             foreach (var item in items)
57
             {
59
             {
58
-                dBContext.Cities.Add(item);
59
-                Save();
60
+                item.Id = id;
61
+                dBContext.Add(item);
62
+                id += 1;
60
             }
63
             }
64
+            Save();
61
         }
65
         }
62
 
66
 
63
         public void Remove(City item)
67
         public void Remove(City item)
95
             dBContext.Entry(item).State = EntityState.Modified;
99
             dBContext.Entry(item).State = EntityState.Modified;
96
             Save();
100
             Save();
97
         }
101
         }
102
+
103
+        public int NewId()
104
+        {
105
+            int id = 0;
106
+            if (dBContext.Cities.Count() > 0)
107
+            {
108
+                id = dBContext.Cities.Max(x => x.Id);
109
+            }
110
+            id += 1;
111
+            return id;
112
+        }
98
     }
113
     }
99
 }
114
 }

+ 18
- 3
UnivateProperties_API/Repository/Region/ProvinceRepository.cs 查看文件

39
 
39
 
40
         public void Insert(Province item)
40
         public void Insert(Province item)
41
         {
41
         {
42
-            dBContext.Provinces.Add(item);
42
+            item.Id = NewId();
43
+            dBContext.Add(item);
43
             Save();
44
             Save();
44
         }
45
         }
45
 
46
 
46
         public void Insert(IEnumerable<Province> items)
47
         public void Insert(IEnumerable<Province> items)
47
         {
48
         {
49
+            int id = NewId();
48
             foreach (var item in items)
50
             foreach (var item in items)
49
             {
51
             {
50
-                dBContext.Provinces.Add(item);
51
-                Save();
52
+                item.Id = id;
53
+                dBContext.Add(item);
54
+                id += 1;
52
             }
55
             }
56
+            Save();
53
         }
57
         }
54
 
58
 
55
         public void Remove(Province item)
59
         public void Remove(Province item)
87
             dBContext.Entry(item).State = EntityState.Modified;
91
             dBContext.Entry(item).State = EntityState.Modified;
88
             Save();
92
             Save();
89
         }
93
         }
94
+
95
+        public int NewId()
96
+        {
97
+            int id = 0;
98
+            if (dBContext.Provinces.Count() > 0)
99
+            {
100
+                id = dBContext.Provinces.Max(x => x.Id);
101
+            }
102
+            id += 1;
103
+            return id;
104
+        }
90
     }
105
     }
91
 }
106
 }

+ 18
- 3
UnivateProperties_API/Repository/Region/SuburbRepository.cs 查看文件

48
 
48
 
49
         public void Insert(Suburb item)
49
         public void Insert(Suburb item)
50
         {
50
         {
51
-            dBContext.Suburbs.Add(item);
51
+            item.Id = NewId();
52
+            dBContext.Add(item);
52
             Save();
53
             Save();
53
         }
54
         }
54
 
55
 
55
         public void Insert(IEnumerable<Suburb> items)
56
         public void Insert(IEnumerable<Suburb> items)
56
         {
57
         {
58
+            int id = NewId();
57
             foreach (var item in items)
59
             foreach (var item in items)
58
             {
60
             {
59
-                dBContext.Suburbs.Add(item);
60
-                Save();
61
+                item.Id = id;
62
+                dBContext.Add(item);
63
+                id += 1;
61
             }
64
             }
65
+            Save();
62
         }
66
         }
63
 
67
 
64
         public void Remove(Suburb item)
68
         public void Remove(Suburb item)
96
             dBContext.Entry(item).State = EntityState.Modified;
100
             dBContext.Entry(item).State = EntityState.Modified;
97
             Save();
101
             Save();
98
         }
102
         }
103
+
104
+        public int NewId()
105
+        {
106
+            int id = 0;
107
+            if (dBContext.Suburbs.Count() > 0)
108
+            {
109
+                id = dBContext.Suburbs.Max(x => x.Id);
110
+            }
111
+            id += 1;
112
+            return id;
113
+        }
99
     }
114
     }
100
 }
115
 }

+ 15
- 0
UnivateProperties_API/Repository/Timeshare/SeasonRepository.cs 查看文件

39
 
39
 
40
         public void Insert(Season item)
40
         public void Insert(Season item)
41
         {
41
         {
42
+            item.Id = NewId();
42
             _dbContext.Add(item);
43
             _dbContext.Add(item);
43
             Save();
44
             Save();
44
         }
45
         }
45
 
46
 
46
         public void Insert(IEnumerable<Season> items)
47
         public void Insert(IEnumerable<Season> items)
47
         {
48
         {
49
+            int id = NewId();
48
             foreach (var item in items)
50
             foreach (var item in items)
49
             {
51
             {
52
+                item.Id = id;
50
                 _dbContext.Add(item);
53
                 _dbContext.Add(item);
54
+                id += 1;
51
             }
55
             }
52
             Save();
56
             Save();
53
         }
57
         }
86
             _dbContext.Entry(item).State = EntityState.Modified;
90
             _dbContext.Entry(item).State = EntityState.Modified;
87
             Save();
91
             Save();
88
         }
92
         }
93
+
94
+        public int NewId()
95
+        {
96
+            int id = 0;
97
+            if (_dbContext.Seasons.Count() > 0)
98
+            {
99
+                id = _dbContext.Seasons.Max(x => x.Id);
100
+            }
101
+            id += 1;
102
+            return id;
103
+        }
89
     }
104
     }
90
 }
105
 }

+ 15
- 0
UnivateProperties_API/Repository/Timeshare/StatusRepository.cs 查看文件

39
 
39
 
40
         public void Insert(Status item)
40
         public void Insert(Status item)
41
         {
41
         {
42
+            item.Id = NewId();
42
             _dbContext.Add(item);
43
             _dbContext.Add(item);
43
             Save();
44
             Save();
44
         }
45
         }
45
 
46
 
46
         public void Insert(IEnumerable<Status> items)
47
         public void Insert(IEnumerable<Status> items)
47
         {
48
         {
49
+            int id = NewId();
48
             foreach (var item in items)
50
             foreach (var item in items)
49
             {
51
             {
52
+                item.Id = id;
50
                 _dbContext.Add(item);
53
                 _dbContext.Add(item);
54
+                id += 1;
51
             }
55
             }
52
             Save();
56
             Save();
53
         }
57
         }
86
             _dbContext.Entry(item).State = EntityState.Modified;
90
             _dbContext.Entry(item).State = EntityState.Modified;
87
             Save();
91
             Save();
88
         }
92
         }
93
+
94
+        public int NewId()
95
+        {
96
+            int id = 0;
97
+            if (_dbContext.Status.Count() > 0)
98
+            {
99
+                id = _dbContext.Status.Max(x => x.Id);
100
+            }
101
+            id += 1;
102
+            return id;
103
+        }
89
     }
104
     }
90
 }
105
 }

+ 17
- 0
UnivateProperties_API/Repository/Timeshare/UnitConfigurationRepository.cs 查看文件

77
 
77
 
78
         public void Insert(UnitConfiguration item)
78
         public void Insert(UnitConfiguration item)
79
         {
79
         {
80
+            item.Id = NewId();
80
             _dbContext.Add(item);
81
             _dbContext.Add(item);
81
             Save();
82
             Save();
82
         }
83
         }
83
 
84
 
84
         public void InsertType(UnitConfigurationType type)
85
         public void InsertType(UnitConfigurationType type)
85
         {
86
         {
87
+            int id = _dbContext.UnitConfigurationTypes.Max(x => x.Id);
88
+            type.Id = id + 1;
86
             _dbContext.Add(type);
89
             _dbContext.Add(type);
87
             Save();
90
             Save();
88
         }
91
         }
89
 
92
 
90
         public void Insert(IEnumerable<UnitConfiguration> items)
93
         public void Insert(IEnumerable<UnitConfiguration> items)
91
         {
94
         {
95
+            int id = NewId();
92
             foreach (var item in items)
96
             foreach (var item in items)
93
             {
97
             {
98
+                item.Id = id;
94
                 _dbContext.Add(item);
99
                 _dbContext.Add(item);
100
+                id += 1;
95
             }
101
             }
96
             Save();
102
             Save();
97
         }
103
         }
137
             _dbContext.Entry(item).State = EntityState.Modified;
143
             _dbContext.Entry(item).State = EntityState.Modified;
138
             Save();
144
             Save();
139
         }
145
         }
146
+
147
+        public int NewId()
148
+        {
149
+            int id = 0;
150
+            if (_dbContext.UnitConfigurations.Count() > 0)
151
+            {
152
+                id = _dbContext.UnitConfigurations.Max(x => x.Id);
153
+            }
154
+            id += 1;
155
+            return id;
156
+        }
140
     }
157
     }
141
 }
158
 }

+ 43
- 5
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs 查看文件

46
             return list;
46
             return list;
47
         }
47
         }
48
 
48
 
49
+        public List<RegionDto> GetAvailResort()
50
+        {
51
+            List<RegionDto> list = new List<RegionDto>();
52
+            foreach (var item in GetDetailedAll())
53
+            {
54
+                if (item.Region != null)
55
+                {
56
+                    if (!list.Any(x => x.RegionCode == item.Region.Code))
57
+                    {
58
+                        list.Add(new RegionDto(item.Region.Code, item.Region.Description));
59
+                    }
60
+                    foreach (var i in list.Where(x => x.RegionCode == item.Region.Code))
61
+                    {
62
+                        i.TryAddResort(item.ResortCode, item.ResortName);
63
+                    }
64
+                }
65
+
66
+            }
67
+            return list;
68
+        }
69
+
49
         public List<TimeshareWeek> GetDetailedAll()
70
         public List<TimeshareWeek> GetDetailedAll()
50
         {
71
         {
51
             var list = GetAll();
72
             var list = GetAll();
74
                 StatusRepository status = new StatusRepository(_dbContext);
95
                 StatusRepository status = new StatusRepository(_dbContext);
75
                 week.Status = status.Get(x => x.Id == week.StatusId).FirstOrDefault();
96
                 week.Status = status.Get(x => x.Id == week.StatusId).FirstOrDefault();
76
             }
97
             }
98
+            else
99
+            {
100
+                StatusRepository repo = new StatusRepository(_dbContext);
101
+                week.Status = repo.GetDetailed(s => s.Code == "A1");
102
+            }
77
             if (week.RegionId != 0)
103
             if (week.RegionId != 0)
78
             {
104
             {
79
                 ProvinceRepository province = new ProvinceRepository(_dbContext);
105
                 ProvinceRepository province = new ProvinceRepository(_dbContext);
90
         public void Insert(TimeshareWeek item)
116
         public void Insert(TimeshareWeek item)
91
         {
117
         {
92
             item = GetDetailedWeek(item);
118
             item = GetDetailedWeek(item);
93
-            // Set starting Status of A1
94
-            StatusRepository repo = new StatusRepository(_dbContext);
95
-            item.Status = repo.GetDetailed(s => s.Code == "A1");
96
-            if(item.Status != null)
119
+            if(item.Status == null)
97
             {
120
             {
98
                 //Create initial
121
                 //Create initial
99
                 item.Status = new Status()
122
                 item.Status = new Status()
103
                     StatusType = StatusType.Timeshare,
126
                     StatusType = StatusType.Timeshare,
104
                     ModifiedBy = "KobusB"
127
                     ModifiedBy = "KobusB"
105
                 };
128
                 };
106
-            }            
129
+            }
130
+            item.Id = NewId();
107
             _dbContext.Add(item);
131
             _dbContext.Add(item);
108
             Save();
132
             Save();
109
         }
133
         }
110
 
134
 
111
         public void Insert(IEnumerable<TimeshareWeek> items)
135
         public void Insert(IEnumerable<TimeshareWeek> items)
112
         {
136
         {
137
+            int id = NewId();
113
             foreach (var item in items)
138
             foreach (var item in items)
114
             {
139
             {
140
+                item.Id = id;
115
                 _dbContext.Add(item);
141
                 _dbContext.Add(item);
142
+                id += 1;
116
             }
143
             }
117
             Save();
144
             Save();
118
         }
145
         }
179
             }
206
             }
180
             return item;
207
             return item;
181
         }
208
         }
209
+
210
+        public int NewId()
211
+        {
212
+            int id = 0;
213
+            if (_dbContext.Weeks.Count() > 0)
214
+            {
215
+                id = _dbContext.Weeks.Max(x => x.Id);
216
+            }
217
+            id += 1;
218
+            return id;
219
+        }
182
     }
220
     }
183
 }
221
 }

+ 19
- 8
UnivateProperties_API/Repository/Users/AgencyRepository.cs 查看文件

2
 using System;
2
 using System;
3
 using System.Collections.Generic;
3
 using System.Collections.Generic;
4
 using System.Linq;
4
 using System.Linq;
5
-using System.Threading.Tasks;
6
 using UnivateProperties_API.Context;
5
 using UnivateProperties_API.Context;
7
 using UnivateProperties_API.Model.Users;
6
 using UnivateProperties_API.Model.Users;
8
 
7
 
35
             return item;
34
             return item;
36
         }
35
         }
37
 
36
 
38
-        private Agency GetDetailedObject(Agency item, AgencyRepository repo)
39
-        {
40
-            item = repo.GetDetailed(x => x.Id == item.Id);
41
-            return item;
42
-        }
43
-
44
         public void Insert(Agency item)
37
         public void Insert(Agency item)
45
         {
38
         {
39
+            item.Id = NewId();
46
             _dbContext.Add(item);
40
             _dbContext.Add(item);
47
             Save();
41
             Save();
48
         }
42
         }
49
 
43
 
50
         public void Insert(IEnumerable<Agency> item)
44
         public void Insert(IEnumerable<Agency> item)
51
         {
45
         {
52
-            _dbContext.Add(item);
46
+            int id = NewId();
47
+            foreach (var i in item)
48
+            {
49
+                i.Id = id;
50
+                _dbContext.Add(i);
51
+                id += 1;
52
+            }
53
             Save();
53
             Save();
54
         }
54
         }
55
 
55
 
93
             //TODO: GetDetailed Agency
93
             //TODO: GetDetailed Agency
94
             throw new NotImplementedException();
94
             throw new NotImplementedException();
95
         }
95
         }
96
+
97
+        public int NewId()
98
+        {
99
+            int id = 0;
100
+            if (_dbContext.Agencies.Count() > 0)
101
+            {
102
+                id = _dbContext.Agencies.Max(x => x.Id);
103
+            }
104
+            id += 1;
105
+            return id;
106
+        }
96
     }
107
     }
97
 }
108
 }

+ 16
- 8
UnivateProperties_API/Repository/Users/AgentRepository.cs 查看文件

3
 using System.Collections.Generic;
3
 using System.Collections.Generic;
4
 using System.Linq;
4
 using System.Linq;
5
 using UnivateProperties_API.Context;
5
 using UnivateProperties_API.Context;
6
-using UnivateProperties_API.Helpers;
7
 using UnivateProperties_API.Model.Users;
6
 using UnivateProperties_API.Model.Users;
8
 
7
 
9
 namespace UnivateProperties_API.Repository.Users
8
 namespace UnivateProperties_API.Repository.Users
36
             return item;
35
             return item;
37
         }
36
         }
38
 
37
 
39
-        private Agent GetDetailedObject(Agent item, AgentRepository repo)
40
-        {
41
-            item = repo.GetDetailed(x => x.Id == item.Id);
42
-            return item;
43
-        }
44
-
45
         public void Insert(Agent item)
38
         public void Insert(Agent item)
46
         {
39
         {
40
+            item.Id = NewId();
47
             _dbContext.Add(item);
41
             _dbContext.Add(item);
48
             Save();
42
             Save();
49
         }
43
         }
50
 
44
 
51
         public void Insert(IEnumerable<Agent> item)
45
         public void Insert(IEnumerable<Agent> item)
52
         {
46
         {
47
+            int id = NewId();
53
             foreach (var i in item)
48
             foreach (var i in item)
54
             {
49
             {
55
-                _dbContext.Add(item);
50
+                i.Id = id;
51
+                _dbContext.Add(i);
52
+                id += 1;
56
             }
53
             }
57
             Save();
54
             Save();
58
         }
55
         }
97
             // TODO: GetDetailed
94
             // TODO: GetDetailed
98
             throw new NotImplementedException();
95
             throw new NotImplementedException();
99
         }
96
         }
97
+
98
+        public int NewId()
99
+        {
100
+            int id = 0;
101
+            if (_dbContext.Agents.Count() > 0)
102
+            {
103
+                id = _dbContext.Agents.Max(x => x.Id);
104
+            }
105
+            id += 1;
106
+            return id;
107
+        }
100
     }
108
     }
101
 }
109
 }

+ 19
- 1
UnivateProperties_API/Repository/Users/IndividualRepository.cs 查看文件

42
 
42
 
43
         public void Insert(Individual item)
43
         public void Insert(Individual item)
44
         {
44
         {
45
+            item.Id = NewId();
45
             _dbContext.Add(item);
46
             _dbContext.Add(item);
46
             Save();
47
             Save();
47
         }
48
         }
48
 
49
 
49
         public void Insert(IEnumerable<Individual> item)
50
         public void Insert(IEnumerable<Individual> item)
50
         {
51
         {
51
-            _dbContext.Add(item);
52
+            int id = NewId();
53
+            foreach (var i in item)
54
+            {
55
+                i.Id = id;
56
+                _dbContext.Add(i);
57
+                id += 1;
58
+            }
52
             Save();
59
             Save();
53
         }
60
         }
54
 
61
 
93
             // TODO: GetDetailed
100
             // TODO: GetDetailed
94
             throw new NotImplementedException();
101
             throw new NotImplementedException();
95
         }
102
         }
103
+
104
+        public int NewId()
105
+        {
106
+            int id = 0;
107
+            if (_dbContext.Individuals.Count() > 0)
108
+            {
109
+                id = _dbContext.Individuals.Max(x => x.Id);
110
+            }
111
+            id += 1;
112
+            return id;
113
+        }
96
     }
114
     }
97
 }
115
 }

+ 52
- 36
UnivateProperties_API/Repository/Users/RegisterRepository.cs 查看文件

1
 using Microsoft.AspNetCore.Authorization;
1
 using Microsoft.AspNetCore.Authorization;
2
-using Microsoft.EntityFrameworkCore;
3
-using Microsoft.Extensions.Options;
4
-using Microsoft.IdentityModel.Tokens;
5
-using System;
6
 using System.Collections.Generic;
2
 using System.Collections.Generic;
7
-using System.IdentityModel.Tokens.Jwt;
8
 using System.Linq;
3
 using System.Linq;
9
-using System.Security.Claims;
10
-using System.Text;
11
-using UnivateProperties_API.Containers;
12
 using UnivateProperties_API.Containers.Users;
4
 using UnivateProperties_API.Containers.Users;
13
 using UnivateProperties_API.Context;
5
 using UnivateProperties_API.Context;
14
 using UnivateProperties_API.Helpers;
6
 using UnivateProperties_API.Helpers;
20
     {
12
     {
21
         private readonly DataContext _dbContext;
13
         private readonly DataContext _dbContext;
22
 
14
 
23
-        private readonly AppSettings _appSettings;
24
-
25
-        public RegisterRepository(DataContext dbContext, IOptions<AppSettings> appSettings)
15
+        public RegisterRepository(DataContext dbContext)
26
         {
16
         {
27
             _dbContext = dbContext;
17
             _dbContext = dbContext;
28
-            _appSettings = appSettings.Value;
29
         }
18
         }
30
 
19
 
31
         public User Authenticate(string username, string password)
20
         public User Authenticate(string username, string password)
56
             if (_dbContext.Users.Any(x => x.Username == user.Username))
45
             if (_dbContext.Users.Any(x => x.Username == user.Username))
57
                 throw new AppException("Username \"" + user.Username + "\" is already taken");
46
                 throw new AppException("Username \"" + user.Username + "\" is already taken");
58
 
47
 
59
-            byte[] passwordHash, passwordSalt;
60
-            MyCommon.CreatePasswordHash(password, out passwordHash, out passwordSalt);
48
+            MyCommon.CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt);
61
 
49
 
62
             user.PasswordHash = passwordHash;
50
             user.PasswordHash = passwordHash;
63
             user.PasswordSalt = passwordSalt;
51
             user.PasswordSalt = passwordSalt;
64
-
52
+            user.Id = NewUserId();
65
             _dbContext.Users.Add(user);
53
             _dbContext.Users.Add(user);
66
             if (save)
54
             if (save)
67
             {
55
             {
86
                 EAABEFFCNumber = agency.EaabeffcNumber,
74
                 EAABEFFCNumber = agency.EaabeffcNumber,
87
                 CompanyRegNumber = agency.RegNo
75
                 CompanyRegNumber = agency.RegNo
88
             };
76
             };
89
-
77
+            a.Id = NewAgencyId();
90
             _dbContext.Agencies.Add(a);
78
             _dbContext.Agencies.Add(a);
91
             CreatePerson(agency.User, PersonType.Agent, false, a);
79
             CreatePerson(agency.User, PersonType.Agent, false, a);
92
 
80
 
103
 
91
 
104
             if (_dbContext.Users.Any(x => x.Username == individual.Username))
92
             if (_dbContext.Users.Any(x => x.Username == individual.Username))
105
                 throw new AppException("Individual \"" + individual.Username + "\" is already taken");
93
                 throw new AppException("Individual \"" + individual.Username + "\" is already taken");
106
-            byte[] passwordHash, passwordSalt;
107
 
94
 
108
-            MyCommon.CreatePasswordHash(individual.Password, out passwordHash, out passwordSalt);
95
+            MyCommon.CreatePasswordHash(individual.Password, out byte[] passwordHash, out byte[] passwordSalt);
109
 
96
 
110
             User createUser = new User(individual.Username, individual.Password);
97
             User createUser = new User(individual.Username, individual.Password);
111
 
98
 
123
                     Telephone = individual.Telephone,
110
                     Telephone = individual.Telephone,
124
                     Agency = agency
111
                     Agency = agency
125
                 };
112
                 };
113
+                agent.Id = NewAgentId();
126
                 _dbContext.Agents.Add(agent);
114
                 _dbContext.Agents.Add(agent);
127
             }
115
             }
128
             else if (personType == PersonType.Individual)
116
             else if (personType == PersonType.Individual)
136
                     CellNumber = individual.CellNumber,
124
                     CellNumber = individual.CellNumber,
137
                     Telephone = individual.Telephone
125
                     Telephone = individual.Telephone
138
                 };
126
                 };
127
+                i.Id = NewIndividualId();
139
                 _dbContext.Individuals.Add(i);
128
                 _dbContext.Individuals.Add(i);
140
             }
129
             }
141
             if (save)
130
             if (save)
144
             }
133
             }
145
         }
134
         }
146
 
135
 
147
-        //public void InsertPerson(UserDto item)
148
-        //{
149
-        //    Individual i = new Individual()
150
-        //    {
151
-        //        Name = item.Name,
152
-        //        Surname = item.Surname,
153
-        //        User = new User(item.Username, item.Password),
154
-        //        Email = item.Email,
155
-        //        CellNumber = item.CellNumber,
156
-        //        Telephone = item.Telephone
157
-        //    };
158
-
159
-        //    _dbContext.Add(i);
160
-        //    Save();
161
-        //}
162
-
163
         public void Update(User userParam, string password = null)
136
         public void Update(User userParam, string password = null)
164
         {
137
         {
165
             var user = _dbContext.Users.Find(userParam.Id);
138
             var user = _dbContext.Users.Find(userParam.Id);
180
             // update password if it was entered
153
             // update password if it was entered
181
             if (!string.IsNullOrWhiteSpace(password))
154
             if (!string.IsNullOrWhiteSpace(password))
182
             {
155
             {
183
-                byte[] passwordHash, passwordSalt;
184
-                MyCommon.CreatePasswordHash(password, out passwordHash, out passwordSalt);
156
+                MyCommon.CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt);
185
 
157
 
186
                 user.PasswordHash = passwordHash;
158
                 user.PasswordHash = passwordHash;
187
                 user.PasswordSalt = passwordSalt;
159
                 user.PasswordSalt = passwordSalt;
258
         {
230
         {
259
             _dbContext.SaveChanges();
231
             _dbContext.SaveChanges();
260
         }
232
         }
233
+
234
+        public int NewAgencyId()
235
+        {
236
+            int id = 0;
237
+            if (_dbContext.Agencies.Count() > 0)
238
+            {
239
+                id = _dbContext.Agencies.Max(x => x.Id);
240
+            }
241
+            id += 1;
242
+            return id;
243
+        }
244
+
245
+        public int NewAgentId()
246
+        {
247
+            int id = 0;
248
+            if (_dbContext.Agents.Count() > 0)
249
+            {
250
+                id = _dbContext.Agents.Max(x => x.Id);
251
+            }
252
+            id += 1;
253
+            return id;
254
+        }
255
+
256
+        public int NewIndividualId()
257
+        {
258
+            int id = 0;
259
+            if (_dbContext.Individuals.Count() > 0)
260
+            {
261
+                id = _dbContext.Individuals.Max(x => x.Id);
262
+            }
263
+            id += 1;
264
+            return id;
265
+        }
266
+
267
+        public int NewUserId()
268
+        {
269
+            int id = 0;
270
+            if (_dbContext.Users.Count() > 0)
271
+            {
272
+                id = _dbContext.Users.Max(x => x.Id);
273
+            }
274
+            id += 1;
275
+            return id;
276
+        }
261
     }
277
     }
262
 }
278
 }

+ 21
- 16
UnivateProperties_API/Repository/Users/UserRepository.cs 查看文件

1
-using Microsoft.EntityFrameworkCore;
2
-using Microsoft.Extensions.Options;
3
-using Microsoft.IdentityModel.Tokens;
4
-using System;
1
+using System;
5
 using System.Collections.Generic;
2
 using System.Collections.Generic;
6
-using System.IdentityModel.Tokens.Jwt;
7
 using System.Linq;
3
 using System.Linq;
8
-using System.Security.Claims;
9
-using System.Text;
10
 using UnivateProperties_API.Context;
4
 using UnivateProperties_API.Context;
11
 using UnivateProperties_API.Helpers;
5
 using UnivateProperties_API.Helpers;
12
 using UnivateProperties_API.Model.Users;
6
 using UnivateProperties_API.Model.Users;
48
 
42
 
49
         public void Insert(User item)
43
         public void Insert(User item)
50
         {
44
         {
45
+            item.Id = NewId();
51
             _dbContext.Add(item);
46
             _dbContext.Add(item);
52
             Save();
47
             Save();
53
         }
48
         }
54
 
49
 
55
         public void Insert(IEnumerable<User> item)
50
         public void Insert(IEnumerable<User> item)
56
         {
51
         {
57
-            _dbContext.Add(item);
52
+            int id = NewId();
53
+            foreach (var i in item)
54
+            {
55
+                i.Id = id;
56
+                _dbContext.Add(i);
57
+                id += 1;
58
+            }
58
             Save();
59
             Save();
59
         }
60
         }
60
 
61
 
82
             Save();
83
             Save();
83
         }
84
         }
84
 
85
 
85
-        //public void Update(User item)
86
-        //{
87
-        //    _dbContext.Entry(item).State = EntityState.Modified;
88
-        //    Save();
89
-        //}
90
-
91
         public void Update(User userParam)
86
         public void Update(User userParam)
92
         {
87
         {
93
             var user = _dbContext.Users.Find(userParam.Id);
88
             var user = _dbContext.Users.Find(userParam.Id);
108
             // update password if it was entered
103
             // update password if it was entered
109
             if (!string.IsNullOrWhiteSpace(userParam.PasswordHash.ToString()))
104
             if (!string.IsNullOrWhiteSpace(userParam.PasswordHash.ToString()))
110
             {
105
             {
111
-                byte[] passwordHash, passwordSalt;
112
-                CreatePasswordHash(userParam.PasswordHash.ToString(), out passwordHash, out passwordSalt);
106
+                CreatePasswordHash(userParam.PasswordHash.ToString(), out byte[] passwordHash, out byte[] passwordSalt);
113
 
107
 
114
                 user.PasswordHash = passwordHash;
108
                 user.PasswordHash = passwordHash;
115
                 user.PasswordSalt = passwordSalt;
109
                 user.PasswordSalt = passwordSalt;
140
         {
134
         {
141
             throw new NotImplementedException();
135
             throw new NotImplementedException();
142
         }
136
         }
137
+
138
+        public int NewId()
139
+        {
140
+            int id = 0;
141
+            if (_dbContext.Users.Count() > 0)
142
+            {
143
+                id = _dbContext.Users.Max(x => x.Id);
144
+            }
145
+            id += 1;
146
+            return id;
147
+        }
143
     }
148
     }
144
 }
149
 }

+ 1
- 1
UnivateProperties_API/appsettings.json 查看文件

9
   },
9
   },
10
   "AllowedHosts": "*",
10
   "AllowedHosts": "*",
11
   "ConnectionStrings": {
11
   "ConnectionStrings": {
12
-    "DefaultConnection": "Server=localhost;Port=5432;Database=Univate;User Id=postgres;Password=Prov1s1on;"
12
+    "DefaultConnection": "Server=localhost;Port=5432;Database=Univate;User Id=postgres;Password=prov1s1on;"
13
   }
13
   }
14
 }
14
 }

Loading…
取消
儲存