Kobus 5 years ago
parent
commit
d9445cd776

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

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

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
 using Microsoft.AspNetCore.Mvc;
1
 using Microsoft.AspNetCore.Mvc;
2
 using System.Transactions;
2
 using System.Transactions;
3
+using UnivateProperties_API.Containers.ProcessFlow;
3
 using UnivateProperties_API.Model.ProcessFlow;
4
 using UnivateProperties_API.Model.ProcessFlow;
4
 using UnivateProperties_API.Repository;
5
 using UnivateProperties_API.Repository;
6
+using UnivateProperties_API.Repository.ProccessFlow;
5
 
7
 
6
 namespace UnivateProperties_API.Controllers.ProcessFlow
8
 namespace UnivateProperties_API.Controllers.ProcessFlow
7
 {
9
 {
9
     [ApiController]
11
     [ApiController]
10
     public class BidController : ControllerBase
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
             _Repo = repo;
18
             _Repo = repo;
17
         }
19
         }
30
             return new OkObjectResult(item);
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
         [HttpPost]
42
         [HttpPost]
34
         public IActionResult Post([FromBody] BidItem item)
43
         public IActionResult Post([FromBody] BidItem item)
35
         {
44
         {
41
             }
50
             }
42
         }
51
         }
43
 
52
 
44
-        [HttpPut("{id}")]
53
+        [HttpPut]
45
         public IActionResult Put([FromBody] BidItem item)
54
         public IActionResult Put([FromBody] BidItem item)
46
         {
55
         {
47
             if (item != null)
56
             if (item != null)
56
             return new NoContentResult();
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
         [HttpDelete("{id}")]
80
         [HttpDelete("{id}")]
60
         public IActionResult Delete(int id)
81
         public IActionResult Delete(int id)
61
         {
82
         {

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

74
                 }
74
                 }
75
                 else
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
             else
81
             else

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

9
 namespace UnivateProperties_API.Model.Properties
9
 namespace UnivateProperties_API.Model.Properties
10
 {
10
 {
11
     public class Property : BaseEntity
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
         [ForeignKey("PropertyType")]        
14
         [ForeignKey("PropertyType")]        
21
         public int PropertyTypeId { get; set; }
15
         public int PropertyTypeId { get; set; }
22
         public string PropertyName { get; set; }
16
         public string PropertyName { get; set; }

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

3
 using System.Collections.Generic;
3
 using System.Collections.Generic;
4
 using System.Linq;
4
 using System.Linq;
5
 using System.Threading.Tasks;
5
 using System.Threading.Tasks;
6
+using UnivateProperties_API.Containers.ProcessFlow;
6
 using UnivateProperties_API.Context;
7
 using UnivateProperties_API.Context;
7
 using UnivateProperties_API.Model.ProcessFlow;
8
 using UnivateProperties_API.Model.ProcessFlow;
8
 
9
 
9
 namespace UnivateProperties_API.Repository.ProccessFlow
10
 namespace UnivateProperties_API.Repository.ProccessFlow
10
 {
11
 {
11
-    public class BidRepository : IRepository<BidItem>
12
+    public class BidRepository : IBidRepository
12
     {
13
     {
13
         private readonly DataContext _dbContext;
14
         private readonly DataContext _dbContext;
14
 
15
 
38
             return GetAll();
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
         public void Insert(BidItem item)
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
             _dbContext.Add(item);
120
             _dbContext.Add(item);
44
             Save();
121
             Save();
45
         }
122
         }
87
             _dbContext.Entry(item).State = EntityState.Modified;
164
             _dbContext.Entry(item).State = EntityState.Modified;
88
             Save();
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

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
 
35
 
36
         public Property GetDetailed(Func<Property, bool> first)
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
             if (property != null)
39
             if (property != null)
40
             {
40
             {
41
                 GetDetail(ref property);
41
                 GetDetail(ref property);

+ 1
- 1
UnivateProperties_API/Startup.cs View File

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

Loading…
Cancel
Save