Kobus 5 years ago
parent
commit
d9445cd776

+ 22
- 0
UnivateProperties_API/Containers/ProcessFlow/BidItemDisplay.cs View File

@@ -0,0 +1,22 @@
1
+namespace UnivateProperties_API.Containers.ProcessFlow
2
+{
3
+    public class BidItemDisplay
4
+    {
5
+        #region Properties
6
+        public int Id { get; set; }        
7
+        public string Type { get; set; }
8
+        public string ShortDescription { get; set; }
9
+        public string Description { get; set; }
10
+        public string Resort { get; set; }
11
+        public string Unit { get; set; }
12
+        public string Module { get; set; }
13
+        public string StatusCode { get; set; }
14
+        public string Status { get; set; }
15
+        public decimal Price { get; set; }
16
+        public decimal Offer { get; set; }
17
+        public string MadeBy { get; set; }
18
+        public string Comment { get; set; }
19
+        public string DeclineReason { get; set; }
20
+        #endregion 
21
+    }
22
+}

+ 10
- 0
UnivateProperties_API/Containers/ProcessFlow/BitItemDecline.cs View File

@@ -0,0 +1,10 @@
1
+namespace UnivateProperties_API.Containers.ProcessFlow
2
+{
3
+    public class BitItemDecline
4
+    {
5
+        #region Proeprties
6
+        public int Id { get; set; }
7
+        public string Comment { get; set; }
8
+        #endregion 
9
+    }
10
+}

+ 24
- 3
UnivateProperties_API/Controllers/ProcessFlow/BidController.cs View File

@@ -1,7 +1,9 @@
1 1
 using Microsoft.AspNetCore.Mvc;
2 2
 using System.Transactions;
3
+using UnivateProperties_API.Containers.ProcessFlow;
3 4
 using UnivateProperties_API.Model.ProcessFlow;
4 5
 using UnivateProperties_API.Repository;
6
+using UnivateProperties_API.Repository.ProccessFlow;
5 7
 
6 8
 namespace UnivateProperties_API.Controllers.ProcessFlow
7 9
 {
@@ -9,9 +11,9 @@ namespace UnivateProperties_API.Controllers.ProcessFlow
9 11
     [ApiController]
10 12
     public class BidController : ControllerBase
11 13
     {
12
-        private readonly IRepository<BidItem> _Repo;
14
+        private readonly IBidRepository _Repo;
13 15
 
14
-        public BidController(IRepository<BidItem> repo)
16
+        public BidController(IBidRepository repo)
15 17
         {
16 18
             _Repo = repo;
17 19
         }
@@ -30,6 +32,13 @@ namespace UnivateProperties_API.Controllers.ProcessFlow
30 32
             return new OkObjectResult(item);
31 33
         }
32 34
 
35
+        [HttpGet("GetBids/{name}")]
36
+        public IActionResult GetOwnerBids(string OwnerName)
37
+        {
38
+            var items = _Repo.GetAllBid();
39
+            return new OkObjectResult(items);
40
+        }
41
+
33 42
         [HttpPost]
34 43
         public IActionResult Post([FromBody] BidItem item)
35 44
         {
@@ -41,7 +50,7 @@ namespace UnivateProperties_API.Controllers.ProcessFlow
41 50
             }
42 51
         }
43 52
 
44
-        [HttpPut("{id}")]
53
+        [HttpPut]
45 54
         public IActionResult Put([FromBody] BidItem item)
46 55
         {
47 56
             if (item != null)
@@ -56,6 +65,18 @@ namespace UnivateProperties_API.Controllers.ProcessFlow
56 65
             return new NoContentResult();
57 66
         }
58 67
 
68
+        [HttpPut("AcceptBid/{id}")]
69
+        public IActionResult AcceptBid(int id)
70
+        {            
71
+            return new OkObjectResult(_Repo.AcceptBid(id));
72
+        }
73
+
74
+        [HttpPut("DeclineBid")]
75
+        public IActionResult DeclineBid([FromBody] BitItemDecline item)
76
+        {            
77
+            return new OkObjectResult(_Repo.DecineBid(item));
78
+        }
79
+
59 80
         [HttpDelete("{id}")]
60 81
         public IActionResult Delete(int id)
61 82
         {

+ 2
- 1
UnivateProperties_API/Controllers/Properties/PropertyController.cs View File

@@ -74,7 +74,8 @@ namespace UnivateProperties_API.Controllers.Properties
74 74
                 }
75 75
                 else
76 76
                 {
77
-                    return new OkObjectResult(_Repo.GetPropertyList(x => proptypeIds.Contains(x.PropertyTypeId) && x.CreatedBy == by));
77
+                    //Needs to change to search on individule/Agent
78
+                    return new OkObjectResult(_Repo.GetPropertyList(x => proptypeIds.Contains(x.PropertyTypeId)));
78 79
                 }
79 80
             }
80 81
             else

+ 2
- 8
UnivateProperties_API/Model/Properties/Property.cs View File

@@ -9,14 +9,8 @@ using UnivateProperties_API.Model.Users;
9 9
 namespace UnivateProperties_API.Model.Properties
10 10
 {
11 11
     public class Property : BaseEntity
12
-    {
13
-        private Property()
14
-        {
15
-
16
-        }
17
-
18
-        #region Properties
19
-        public string CreatedBy { get; set; }
12
+    {        
13
+        #region Properties        
20 14
         [ForeignKey("PropertyType")]        
21 15
         public int PropertyTypeId { get; set; }
22 16
         public string PropertyName { get; set; }

+ 132
- 1
UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs View File

@@ -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
 }

+ 17
- 0
UnivateProperties_API/Repository/ProccessFlow/IBidRepository.cs View File

@@ -0,0 +1,17 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Threading.Tasks;
5
+using UnivateProperties_API.Containers.ProcessFlow;
6
+using UnivateProperties_API.Model.ProcessFlow;
7
+
8
+namespace UnivateProperties_API.Repository.ProccessFlow
9
+{
10
+    public interface IBidRepository : IRepository<BidItem>
11
+    {
12
+        List<BidItemDisplay> GetAllBid();
13
+        List<BidItemDisplay> GetMyBid(Func<BidItem, bool> where);
14
+        BidItemDisplay AcceptBid(int id);
15
+        BidItemDisplay DecineBid(BitItemDecline item);
16
+    }
17
+}

+ 1
- 1
UnivateProperties_API/Repository/Properties/PropertyRepository.cs View File

@@ -35,7 +35,7 @@ namespace UnivateProperties_API.Repository.Properties
35 35
 
36 36
         public Property GetDetailed(Func<Property, bool> first)
37 37
         {
38
-            var property = dBContext.Properties.FirstOrDefault(first);
38
+            var property = dBContext.Properties.Include("Status").FirstOrDefault(first);
39 39
             if (property != null)
40 40
             {
41 41
                 GetDetail(ref property);

+ 1
- 1
UnivateProperties_API/Startup.cs View File

@@ -90,7 +90,7 @@ namespace UnivateProperties_API
90 90
             });
91 91
 
92 92
             #region ProcessFlow
93
-            services.AddTransient<IRepository<BidItem>, BidRepository>();
93
+            services.AddTransient<IBidRepository, BidRepository>();
94 94
             #endregion
95 95
             #region Property
96 96
             services.AddTransient<IRepository<Agent>, AgentRepository>();

Loading…
Cancel
Save