Browse Source

Added Repo and bid controller

master
Kobus 5 years ago
parent
commit
2d79ea9a5d

+ 66
- 0
UnivateProperties_API/Controllers/ProcessFlow/BidController.cs View File

@@ -0,0 +1,66 @@
1
+using Microsoft.AspNetCore.Mvc;
2
+using System.Transactions;
3
+using UnivateProperties_API.Model.ProcessFlow;
4
+using UnivateProperties_API.Repository;
5
+
6
+namespace UnivateProperties_API.Controllers.ProcessFlow
7
+{
8
+    [Route("api/[controller]")]
9
+    [ApiController]
10
+    public class BidController : ControllerBase
11
+    {
12
+        private readonly IRepository<BidItem> _Repo;
13
+
14
+        public BidController(IRepository<BidItem> repo)
15
+        {
16
+            _Repo = repo;
17
+        }
18
+
19
+        [HttpGet]
20
+        public IActionResult Get()
21
+        {
22
+            var items = _Repo.GetAll();
23
+            return new OkObjectResult(items);
24
+        }
25
+
26
+        [HttpGet("{id}")]
27
+        public IActionResult Get(int id)
28
+        {
29
+            var item = _Repo.Get(x => x.Id == id);
30
+            return new OkObjectResult(item);
31
+        }
32
+
33
+        [HttpPost]
34
+        public IActionResult Post([FromBody] BidItem item)
35
+        {
36
+            using (var scope = new TransactionScope())
37
+            {
38
+                _Repo.Insert(item);
39
+                scope.Complete();
40
+                return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
41
+            }
42
+        }
43
+
44
+        [HttpPut("{id}")]
45
+        public IActionResult Put([FromBody] BidItem item)
46
+        {
47
+            if (item != null)
48
+            {
49
+                using (var scope = new TransactionScope())
50
+                {
51
+                    _Repo.Update(item);
52
+                    scope.Complete();
53
+                    return new OkResult();
54
+                }
55
+            }
56
+            return new NoContentResult();
57
+        }
58
+
59
+        [HttpDelete("{id}")]
60
+        public IActionResult Delete(int id)
61
+        {
62
+            _Repo.RemoveAtId(id);
63
+            return new OkResult();
64
+        }
65
+    }
66
+}

+ 91
- 0
UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs View File

@@ -0,0 +1,91 @@
1
+using Microsoft.EntityFrameworkCore;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using System.Threading.Tasks;
6
+using UnivateProperties_API.Context;
7
+using UnivateProperties_API.Model.ProcessFlow;
8
+
9
+namespace UnivateProperties_API.Repository.ProccessFlow
10
+{
11
+    public class BidRepository : IRepository<BidItem>
12
+    {
13
+        private readonly DataContext _dbContext;
14
+
15
+        public BidRepository(DataContext dbContext)
16
+        {
17
+            _dbContext = dbContext;
18
+        }
19
+
20
+        public List<BidItem> Get(Func<BidItem, bool> where)
21
+        {
22
+            return _dbContext.BidItems.Where(where).ToList();
23
+        }
24
+
25
+        public List<BidItem> GetAll()
26
+        {
27
+            return _dbContext.BidItems.ToList();
28
+        }
29
+
30
+        public BidItem GetDetailed(Func<BidItem, bool> first)
31
+        {
32
+            var item = _dbContext.BidItems.FirstOrDefault(first);
33
+            return item;
34
+        }
35
+
36
+        public List<BidItem> GetDetailedAll()
37
+        {
38
+            return GetAll();
39
+        }
40
+
41
+        public void Insert(BidItem item)
42
+        {
43
+            _dbContext.Add(item);
44
+            Save();
45
+        }
46
+
47
+        public void Insert(IEnumerable<BidItem> items)
48
+        {
49
+            foreach (var item in items)
50
+            {
51
+                _dbContext.Add(item);
52
+            }
53
+            Save();
54
+        }
55
+
56
+        public void Remove(BidItem item)
57
+        {
58
+            var i = _dbContext.BidItems.Find(item);
59
+            _dbContext.BidItems.Remove(i);
60
+            Save();
61
+        }
62
+
63
+        public void Remove(IEnumerable<BidItem> items)
64
+        {
65
+            foreach (var item in items)
66
+            {
67
+                var i = _dbContext.BidItems.Find(item);
68
+                _dbContext.BidItems.Remove(i);
69
+            }
70
+            Save();
71
+        }
72
+
73
+        public void RemoveAtId(int item)
74
+        {
75
+            var i = _dbContext.BidItems.Find(item);
76
+            _dbContext.BidItems.Remove(i);
77
+            Save();
78
+        }
79
+
80
+        public void Save()
81
+        {
82
+            _dbContext.SaveChanges();
83
+        }
84
+
85
+        public void Update(BidItem item)
86
+        {
87
+            _dbContext.Entry(item).State = EntityState.Modified;
88
+            Save();
89
+        }
90
+    }
91
+}

+ 9
- 0
UnivateProperties_API/Startup.cs View File

@@ -11,13 +11,17 @@ using Microsoft.IdentityModel.Tokens;
11 11
 using System.Text;
12 12
 using System.Threading.Tasks;
13 13
 using UnivateProperties_API.Context;
14
+using UnivateProperties_API.Model.Banks;
14 15
 using UnivateProperties_API.Model.Communication;
16
+using UnivateProperties_API.Model.ProcessFlow;
15 17
 using UnivateProperties_API.Model.Properties;
16 18
 using UnivateProperties_API.Model.Region;
17 19
 using UnivateProperties_API.Model.Timeshare;
18 20
 using UnivateProperties_API.Model.Users;
19 21
 using UnivateProperties_API.Repository;
22
+using UnivateProperties_API.Repository.Banks;
20 23
 using UnivateProperties_API.Repository.Communication;
24
+using UnivateProperties_API.Repository.ProccessFlow;
21 25
 using UnivateProperties_API.Repository.Properties;
22 26
 using UnivateProperties_API.Repository.Region;
23 27
 using UnivateProperties_API.Repository.Timeshare;
@@ -85,6 +89,9 @@ namespace UnivateProperties_API
85 89
                 };
86 90
             });
87 91
 
92
+            #region ProcessFlow
93
+            services.AddTransient<IRepository<BidItem>, BidRepository>();
94
+            #endregion
88 95
             #region Property
89 96
             services.AddTransient<IRepository<Agent>, AgentRepository>();
90 97
             services.AddTransient<IRegisterRepository, RegisterRepository>();
@@ -111,6 +118,8 @@ namespace UnivateProperties_API
111 118
             services.AddTransient<IRepository<UnitConfiguration>, UnitConfigurationRepository>();
112 119
             services.AddTransient<IRepository<TimeshareWeek>, WeekRepository>();
113 120
             services.AddTransient<IRepository<TimeshareWeek>, WeekRepository>();
121
+            services.AddTransient<IRepository<Bank>, BankAccountRepository>();
122
+            services.AddTransient<IRepository<BankAccount>, BankAccountRepository>();
114 123
             #endregion Timeshare
115 124
             #region User
116 125
             services.AddScoped<IRegisterRepository, RegisterRepository>();

Loading…
Cancel
Save