|
@@ -3,12 +3,13 @@ using System;
|
3
|
3
|
using System.Collections.Generic;
|
4
|
4
|
using System.Linq;
|
5
|
5
|
using System.Threading.Tasks;
|
|
6
|
+using UnivateProperties_API.Containers.ProcessFlow;
|
6
|
7
|
using UnivateProperties_API.Context;
|
7
|
8
|
using UnivateProperties_API.Model.ProcessFlow;
|
8
|
9
|
|
9
|
10
|
namespace UnivateProperties_API.Repository.ProccessFlow
|
10
|
11
|
{
|
11
|
|
- public class BidRepository : IRepository<BidItem>
|
|
12
|
+ public class BidRepository : IBidRepository
|
12
|
13
|
{
|
13
|
14
|
private readonly DataContext _dbContext;
|
14
|
15
|
|
|
@@ -38,8 +39,84 @@ namespace UnivateProperties_API.Repository.ProccessFlow
|
38
|
39
|
return GetAll();
|
39
|
40
|
}
|
40
|
41
|
|
|
42
|
+ public List<BidItemDisplay> GetAllBid()
|
|
43
|
+ {
|
|
44
|
+ List<BidItem> bids = _dbContext.BidItems
|
|
45
|
+ .Include("Property")
|
|
46
|
+ .Include("TimeshareWeek")
|
|
47
|
+ .Include("BidMaker")
|
|
48
|
+ .Include("Status")
|
|
49
|
+ .Include("Property.Owner")
|
|
50
|
+ .Include("Property.Agent")
|
|
51
|
+ .ToList();
|
|
52
|
+
|
|
53
|
+ return LoadDisplay(bids);
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ public List<BidItemDisplay> GetMyBid(Func<BidItem, bool> where)
|
|
57
|
+ {
|
|
58
|
+ List<BidItem> bids = _dbContext.BidItems
|
|
59
|
+ .Include("Property")
|
|
60
|
+ .Include("TimeshareWeek")
|
|
61
|
+ .Include("BidMaker")
|
|
62
|
+ .Include("Status")
|
|
63
|
+ .Where(where)
|
|
64
|
+ .ToList();
|
|
65
|
+
|
|
66
|
+ return LoadDisplay(bids);
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ private List<BidItemDisplay> LoadDisplay(List<BidItem> bids)
|
|
70
|
+ {
|
|
71
|
+ List<BidItemDisplay> list = new List<BidItemDisplay>();
|
|
72
|
+ foreach (BidItem item in bids)
|
|
73
|
+ {
|
|
74
|
+ BidItemDisplay bid = new BidItemDisplay()
|
|
75
|
+ {
|
|
76
|
+ Id = item.Id,
|
|
77
|
+ Offer = (decimal)item.Amount,
|
|
78
|
+ Comment = item.Comment,
|
|
79
|
+ DeclineReason = item.DeclinedReason
|
|
80
|
+ };
|
|
81
|
+
|
|
82
|
+ if (item.PropertyId != null)
|
|
83
|
+ {
|
|
84
|
+ bid.Type = "Property";
|
|
85
|
+ bid.ShortDescription = item.Property.ShortDescription;
|
|
86
|
+ bid.Description = item.Property.Description;
|
|
87
|
+ bid.Price = item.Property.Price;
|
|
88
|
+ }
|
|
89
|
+ if (item.TimeshareWeekId != null)
|
|
90
|
+ {
|
|
91
|
+ bid.Type = "Timeshare";
|
|
92
|
+ bid.ShortDescription = string.Format("{0} {1} {2}", item.TimeshareWeek.ResortCode, item.TimeshareWeek.WeekNumber, item.TimeshareWeek.UnitNumber);
|
|
93
|
+ bid.Price = (decimal)item.TimeshareWeek.SellPrice;
|
|
94
|
+ bid.Resort = item.TimeshareWeek.ResortName;
|
|
95
|
+ bid.Unit = item.TimeshareWeek.UnitNumber;
|
|
96
|
+ bid.Module = item.TimeshareWeek.Module;
|
|
97
|
+ }
|
|
98
|
+ if (item.Status != null)
|
|
99
|
+ {
|
|
100
|
+ bid.StatusCode = item.Status.Code;
|
|
101
|
+ bid.Status = string.Format("{0} - {1}", item.Status.Code, item.Status.Description);
|
|
102
|
+ }
|
|
103
|
+ if (item.BidMaker != null)
|
|
104
|
+ bid.MadeBy = item.BidMaker.Name + " " + item.BidMaker.Surname;
|
|
105
|
+
|
|
106
|
+ bid.MadeBy = "Bob";
|
|
107
|
+
|
|
108
|
+ list.Add(bid);
|
|
109
|
+
|
|
110
|
+ }
|
|
111
|
+ return list;
|
|
112
|
+ }
|
|
113
|
+
|
41
|
114
|
public void Insert(BidItem item)
|
42
|
115
|
{
|
|
116
|
+ var status = _dbContext.Status.Where(x => x.Code == "E1" && x.StatusType == StatusType.Bid).FirstOrDefault();
|
|
117
|
+ if (status != null)
|
|
118
|
+ item.StatusId = status.Id;
|
|
119
|
+
|
43
|
120
|
_dbContext.Add(item);
|
44
|
121
|
Save();
|
45
|
122
|
}
|
|
@@ -87,5 +164,59 @@ namespace UnivateProperties_API.Repository.ProccessFlow
|
87
|
164
|
_dbContext.Entry(item).State = EntityState.Modified;
|
88
|
165
|
Save();
|
89
|
166
|
}
|
|
167
|
+
|
|
168
|
+ public BidItemDisplay AcceptBid(int id)
|
|
169
|
+ {
|
|
170
|
+ var item = _dbContext.BidItems
|
|
171
|
+ .Include("Property")
|
|
172
|
+ .Include("TimeshareWeek")
|
|
173
|
+ .Include("BidMaker")
|
|
174
|
+ .Include("Status")
|
|
175
|
+ .Where(x => x.Id == id).FirstOrDefault();
|
|
176
|
+
|
|
177
|
+ var status = (from s in _dbContext.Status
|
|
178
|
+ where s.Code == "E2"
|
|
179
|
+ && s.StatusType == StatusType.Bid
|
|
180
|
+ select s).FirstOrDefault();
|
|
181
|
+
|
|
182
|
+ if (status != null)
|
|
183
|
+ {
|
|
184
|
+ item.StatusId = status.Id;
|
|
185
|
+ }
|
|
186
|
+
|
|
187
|
+ _dbContext.Entry(item).State = EntityState.Modified;
|
|
188
|
+ Save();
|
|
189
|
+
|
|
190
|
+ List<BidItem> bids = new List<BidItem>() { item };
|
|
191
|
+ return LoadDisplay(bids).Find(x => x.Id == item.Id);
|
|
192
|
+ }
|
|
193
|
+
|
|
194
|
+ public BidItemDisplay DecineBid(BitItemDecline item)
|
|
195
|
+ {
|
|
196
|
+ var bid = _dbContext.BidItems
|
|
197
|
+ .Include("Property")
|
|
198
|
+ .Include("TimeshareWeek")
|
|
199
|
+ .Include("BidMaker")
|
|
200
|
+ .Include("Status")
|
|
201
|
+ .Where(x => x.Id == item.Id).FirstOrDefault();
|
|
202
|
+
|
|
203
|
+ var status = (from s in _dbContext.Status
|
|
204
|
+ where s.Code == "E3"
|
|
205
|
+ && s.StatusType == StatusType.Bid
|
|
206
|
+ select s).FirstOrDefault();
|
|
207
|
+
|
|
208
|
+ if (status != null)
|
|
209
|
+ {
|
|
210
|
+ bid.StatusId = status.Id;
|
|
211
|
+ }
|
|
212
|
+
|
|
213
|
+ bid.DeclinedReason = item.Comment;
|
|
214
|
+
|
|
215
|
+ _dbContext.Entry(bid).State = EntityState.Modified;
|
|
216
|
+ Save();
|
|
217
|
+
|
|
218
|
+ List<BidItem> bids = new List<BidItem>() { bid };
|
|
219
|
+ return LoadDisplay(bids).Find(x => x.Id == bid.Id);
|
|
220
|
+ }
|
90
|
221
|
}
|
91
|
222
|
}
|