George Williams 5 年前
父节点
当前提交
05d9713106

+ 21
- 0
UnivateProperties_API/Containers/Timeshare/RegionDto.cs 查看文件

@@ -0,0 +1,21 @@
1
+namespace UnivateProperties_API.Containers.Timeshare
2
+{
3
+    public class RegionDto
4
+    {
5
+        public RegionDto()
6
+        {
7
+
8
+        }
9
+
10
+        public RegionDto(int id, string regionName, string regionCode)
11
+        {
12
+            Id = id;
13
+            RegionName = regionName;
14
+            RegionCode = regionCode;
15
+        }
16
+
17
+        public int Id { get; set; }
18
+        public string RegionName { get; set; }
19
+        public string RegionCode { get; set; }
20
+    }
21
+}

+ 19
- 0
UnivateProperties_API/Containers/Timeshare/ResortDto.cs 查看文件

@@ -0,0 +1,19 @@
1
+namespace UnivateProperties_API.Containers.Timeshare
2
+{
3
+    public class ResortDto
4
+    {
5
+        public ResortDto()
6
+        {
7
+
8
+        }
9
+
10
+        public ResortDto(string resortCode, string resortName)
11
+        {
12
+            ResortCode = resortCode;
13
+            ResortName = resortName;
14
+        }
15
+
16
+        public string ResortCode { get; set; }
17
+        public string ResortName { get; set; }
18
+    }
19
+}

+ 25
- 0
UnivateProperties_API/Containers/Timeshare/StatusDto.cs 查看文件

@@ -0,0 +1,25 @@
1
+namespace UnivateProperties_API.Containers.Timeshare
2
+{
3
+    public class StatusDto
4
+    {
5
+        public StatusDto()
6
+        {
7
+
8
+        }
9
+
10
+        public StatusDto(int id, string code, string description)
11
+        {
12
+            Id = id;
13
+            Code = code;
14
+            Description = description;
15
+        }
16
+
17
+        public int Id { get; set; }
18
+        public string Code { get; set; }
19
+        public string Description { get; set; }
20
+        public override string ToString()
21
+        {
22
+            return $"{Code} - {Description}";
23
+        }
24
+    }
25
+}

+ 49
- 0
UnivateProperties_API/Containers/Timeshare/WeekDto.cs 查看文件

@@ -0,0 +1,49 @@
1
+using System;
2
+using UnivateProperties_API.Model.Timeshare;
3
+
4
+namespace UnivateProperties_API.Containers.Timeshare
5
+{
6
+    public class WeekDto
7
+    {
8
+        public WeekDto()
9
+        {
10
+
11
+        }
12
+
13
+        public WeekDto(TimeshareWeek week)
14
+        {
15
+            Id = week.Id;
16
+            AgentAsRep = week.AgentAsRep;
17
+            OtherResort = week.OtherResort;
18
+            Resort = new ResortDto(week.ResortCode, week.ResortName);
19
+            Region = new RegionDto(week.Region != null ? week.Region.Id : 0, week.Region?.Description, week.Region?.Code);
20
+            Status = new StatusDto(week.Status.Id, week.Status.Code, week.Status.Description);
21
+            Bedrooms = week.Bedrooms;
22
+            MaxSleep = week.MaxSleep;
23
+            UnitNumber = week.UnitNumber;
24
+            WeekNumber = week.WeekNumber;
25
+            LevyAmount = week.LevyAmount;
26
+            CurrentYearBanked = week.CurrentYearBanked;
27
+            ArrivalDate = week.ArrivalDate;
28
+            DepartureDate = week.DepartureDate;
29
+            SellPrice = week.SellPrice;
30
+        }
31
+
32
+        public int Id { get; set; }
33
+        public bool AgentAsRep { get; set; }
34
+        public bool OtherResort { get; set; }
35
+        public ResortDto Resort { get; set; }
36
+        public RegionDto Region { get; set; }
37
+        public StatusDto Status { get; set; }
38
+        public int Bedrooms { get; set; }
39
+        public int MaxSleep { get; set; }
40
+        public string UnitNumber { get; set; }
41
+        public string WeekNumber { get; set; }
42
+        public double LevyAmount { get; set; }
43
+        public bool CurrentYearBanked { get; set; }
44
+        public string BankedWith { get; set; }
45
+        public DateTime ArrivalDate { get; set; }
46
+        public DateTime DepartureDate { get; set; }
47
+        public double SellPrice { get; set; }
48
+    }
49
+}

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

@@ -24,7 +24,7 @@ namespace UnivateProperties_API.Controllers.Timeshare
24 24
         [HttpGet]
25 25
         public IActionResult Get()
26 26
         {
27
-            var items = _Repo.GetAll();
27
+            var items = (_Repo as WeekRepository).GetDtoListAll();
28 28
             return new OkObjectResult(items);
29 29
         }
30 30
 

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

@@ -29,57 +29,67 @@ namespace UnivateProperties_API.Repository.Timeshare
29 29
             return _dbContext.Weeks.ToList();
30 30
         }
31 31
 
32
-        private TimeshareWeek GetWeekDetailed(TimeshareWeek week)
33
-        {
34
-            // Get Agent
35
-            if(week.AgentId != 0 && week.Agent == null)
36
-            {
37
-                AgentRepository agentRepo = new AgentRepository(_dbContext);
38
-                week.Agent = agentRepo.GetDetailed(x => x.Id == week.AgentId);
39
-            }
40
-            // Get Agency
41
-            if(week.AgencyId != 0 && week.Agency == null)
42
-            {
43
-                AgencyRepository agencyRepo = new AgencyRepository(_dbContext);
44
-                week.Agency = agencyRepo.GetDetailed(x => x.Id == week.AgencyId);
45
-            }
46
-            // Get Region
47
-            if(week.RegionId != 0 && week.Region == null)
48
-            {
49
-                ProvinceRepository provinceRepo = new ProvinceRepository(_dbContext);
50
-                week.Region = provinceRepo.GetDetailed(x => x.Id == week.RegionId);
51
-            }
52
-            // Get Status
53
-            if(week.StatusId != 0 && week.Status == null)
54
-            {
55
-                StatusRepository statusRepo = new StatusRepository(_dbContext);
56
-                week.Status = statusRepo.GetDetailed(x => x.Id == week.StatusId);
57
-            }
58
-
59
-            return week;
60
-        }
61
-
62 32
         public TimeshareWeek GetDetailed(Func<TimeshareWeek, bool> first)
63 33
         {
64 34
             var item = _dbContext.Weeks.FirstOrDefault(first);
65
-            item = GetWeekDetailed(item);
35
+            item = GetDetailedWeek(item);
66 36
             return item;
67 37
         }
68 38
 
39
+        public List<WeekDto> GetDtoListAll()
40
+        {
41
+            List<WeekDto> list = new List<WeekDto>();
42
+            foreach(var item in GetDetailedAll())
43
+            {
44
+                list.Add(new WeekDto(item));
45
+            }
46
+            return list;
47
+        }
48
+
69 49
         public List<TimeshareWeek> GetDetailedAll()
70 50
         {
71 51
             var list = GetAll();
72 52
             List<TimeshareWeek> weeklist = new List<TimeshareWeek>();
73 53
             foreach(var item in list)
74 54
             {
75
-                weeklist.Add(GetWeekDetailed(item));
55
+                weeklist.Add(GetDetailedWeek(item));
76 56
             }
77 57
             return weeklist;
78 58
         }
79 59
 
60
+        private TimeshareWeek GetDetailedWeek(TimeshareWeek week)
61
+        {
62
+            if(week.AgencyId != null)
63
+            {
64
+                AgencyRepository agency = new AgencyRepository(_dbContext);
65
+                week.Agency = agency.Get(x => x.Id == week.AgencyId).FirstOrDefault();
66
+            }
67
+            if(week.AgentId != null)
68
+            {
69
+                AgentRepository agent = new AgentRepository(_dbContext);
70
+                week.Agent = agent.Get(x => x.Id == week.AgentId).FirstOrDefault();
71
+            }
72
+            if (week.StatusId != 0)
73
+            {
74
+                StatusRepository status = new StatusRepository(_dbContext);
75
+                week.Status = status.Get(x => x.Id == week.StatusId).FirstOrDefault();
76
+            }
77
+            if (week.RegionId != 0)
78
+            {
79
+                ProvinceRepository province = new ProvinceRepository(_dbContext);
80
+                week.Region = province.Get(x => x.Id == week.RegionId).FirstOrDefault();
81
+            }
82
+            if (week.OwnerId != 0)
83
+            {
84
+                IndividualRepository individual = new IndividualRepository(_dbContext);
85
+                week.Owner = individual.Get(x => x.Id == week.OwnerId).FirstOrDefault();
86
+            }
87
+            return week;
88
+        }
89
+
80 90
         public void Insert(TimeshareWeek item)
81 91
         {
82
-            item = GetWeekDetailed(item);
92
+            item = GetDetailedWeek(item);
83 93
             // Set starting Status of A1
84 94
             StatusRepository repo = new StatusRepository(_dbContext);
85 95
             item.Status = repo.GetDetailed(s => s.Code == "A1");

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

@@ -164,7 +164,7 @@ namespace UnivateProperties_API
164 164
             {
165 165
                 using (var context = serviceScope.ServiceProvider.GetService<DataContext>())
166 166
                 {
167
-                    context.Database.Migrate();
167
+                    //context.Database.Migrate();
168 168
                 }
169 169
             }
170 170
         }

正在加载...
取消
保存