George Williams 5 лет назад
Родитель
Сommit
1be429f244

+ 2
- 2
UnivateProperties_API/Controllers/ProcessFlow/BidController.cs Просмотреть файл

@@ -33,9 +33,9 @@ namespace UnivateProperties_API.Controllers.ProcessFlow
33 33
         }
34 34
 
35 35
         [HttpGet("GetBids/{name}")]
36
-        public IActionResult GetOwnerBids(string OwnerName)
36
+        public IActionResult GetOwnerBids(string name)
37 37
         {
38
-            var items = _Repo.GetAllBid();
38
+            var items = _Repo.GetAllBidBy(name);
39 39
             return new OkObjectResult(items);
40 40
         }
41 41
 

+ 3
- 3
UnivateProperties_API/Controllers/Properties/PropertyController.cs Просмотреть файл

@@ -45,10 +45,10 @@ namespace UnivateProperties_API.Controllers.Properties
45 45
             return new OkObjectResult(_Repo.GetLatestDisplay());
46 46
         }
47 47
 
48
-        [HttpGet("{type}/{by}")]
49
-        public IActionResult SearchBy(string type, int by)
48
+        [HttpGet("GetPropertyList/{by}")]
49
+        public IActionResult SearchBy(int by)
50 50
         {
51
-            return new OkObjectResult(_Repo.GetPropertyList(type, by));
51
+            return new OkObjectResult(_Repo.GetPropertyList(by));
52 52
         }
53 53
 
54 54
         [HttpGet("MayEditProperty/{id}")]

+ 62
- 1
UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs Просмотреть файл

@@ -69,6 +69,67 @@ namespace UnivateProperties_API.Repository.ProccessFlow
69 69
             return LoadDisplay(bids);
70 70
         }
71 71
 
72
+        public List<BidItemDisplay> GetAllBidBy(string name)
73
+        {
74
+            /*
75
+            * Agency - can see all its agents' listings
76
+            * Agent - only see own listings
77
+            * Private User - only see own listings
78
+            * Super Admin - can see all
79
+            */
80
+            var user = _dbContext.Users.Where(u => u.Username == name).FirstOrDefault();
81
+           
82
+            if (user != null)
83
+            {                
84
+                if (user.Role.ToUpper() == "AGENCY" || user.Role.ToUpper() == "AGENT")
85
+                {
86
+                    var agent = _dbContext.Agents.Where(a => a.UserId == user.Id).FirstOrDefault();
87
+                    if (user.Role.ToUpper() == "AGENCY")
88
+                    {
89
+                        List<BidItem> bids = _dbContext.BidItems
90
+                            .Include("Property")
91
+                            .Include("TimeshareWeek")
92
+                            .Include("BidMaker")
93
+                            .Include("Status")
94
+                            .Where(x => x.TimeshareWeek.AgencyId == agent.AgencyId || x.Property.AgencyId == agent.AgencyId)
95
+                            .ToList();
96
+
97
+                        return LoadDisplay(bids);
98
+                    }            
99
+                    else
100
+                    {
101
+                        List<BidItem> bids = _dbContext.BidItems
102
+                            .Include("Property")
103
+                            .Include("TimeshareWeek")
104
+                            .Include("BidMaker")
105
+                            .Include("Status")
106
+                            .Where(x => x.TimeshareWeek.AgentId == agent.Id || x.Property.AgentId == agent.Id)
107
+                            .ToList();
108
+
109
+                        return LoadDisplay(bids);
110
+                    }
111
+                }                
112
+                if (user.Role.ToUpper() == "PRIVATE USER")
113
+                {
114
+                    var individual = _dbContext.Individuals.Where(i => i.UserId == user.Id).FirstOrDefault();
115
+
116
+                    List<BidItem> bids = _dbContext.BidItems
117
+                            .Include("Property")
118
+                            .Include("TimeshareWeek")
119
+                            .Include("BidMaker")
120
+                            .Include("Status")
121
+                            .Where(x => x.TimeshareWeek.OwnerId == individual.Id || x.Property.OwnerId == individual.Id)
122
+                            .ToList();
123
+
124
+                    return LoadDisplay(bids);
125
+                }
126
+                if (user.Role.ToUpper() == "SUPER ADMIN")
127
+                    return GetAllBid();                                 
128
+            }
129
+
130
+            return null;            
131
+        }
132
+
72 133
         private List<BidItemDisplay> LoadDisplay(List<BidItem> bids)
73 134
         {
74 135
             List<BidItemDisplay> list = new List<BidItemDisplay>();
@@ -361,6 +422,6 @@ namespace UnivateProperties_API.Repository.ProccessFlow
361 422
             bid.Date = item.Created;
362 423
 
363 424
             return bid;
364
-        }
425
+        }        
365 426
     }
366 427
 }

+ 1
- 0
UnivateProperties_API/Repository/ProccessFlow/IBidRepository.cs Просмотреть файл

@@ -10,6 +10,7 @@ namespace UnivateProperties_API.Repository.ProccessFlow
10 10
     public interface IBidRepository : IRepository<BidItem>
11 11
     {
12 12
         List<BidItemDisplay> GetAllBid();
13
+        List<BidItemDisplay> GetAllBidBy(string name);
13 14
         List<BidItemDisplay> GetMyBid(Func<BidItem, bool> where);
14 15
         BidItemDisplay AcceptBid(int id);
15 16
         BidItemDisplay DecineBid(BitItemDecline item);

+ 1
- 1
UnivateProperties_API/Repository/Properties/IPropertyRepository.cs Просмотреть файл

@@ -12,7 +12,7 @@ namespace UnivateProperties_API.Repository.Properties
12 12
         List<PropertyDisplay> GetDisplay(PropertySearch search);        
13 13
         List<PropertyDisplay> GetLatestDisplay();
14 14
         List<PropertyType> GetPropertyTypes(Func<PropertyType, bool> where);
15
-        List<PropertyList> GetPropertyList(string Type, int By);
15
+        List<PropertyList> GetPropertyList(int By);
16 16
         void Insert(PropertyContainer items);
17 17
         PropertyContainer GetDetailed(int id, bool detailed);
18 18
         void Update(PropertyContainer item);

+ 24
- 21
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Просмотреть файл

@@ -593,30 +593,33 @@ namespace UnivateProperties_API.Repository.Properties
593 593
             return GetDisplayDetails(props);
594 594
         }
595 595
 
596
-        public List<PropertyList> GetPropertyList(string Type, int By)
596
+        public List<PropertyList> GetPropertyList(int By)
597 597
         {
598
-            var individual = dBContext.Individuals.Where(x => x.UserId == By).FirstOrDefault();
599
-            var agent = dBContext.Agents.Where(x => x.UserId == By).FirstOrDefault();
600
-
601 598
             List<Property> properties = new List<Property>();
602
-            if (Type.ToUpper() == "MY")
603
-            {                
604
-                if (individual != null)
605
-                    properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.OwnerId == individual.Id).ToList();
606
-                if (agent != null)
607
-                    properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.AgentId == agent.Id).ToList();
608
-            }
609
-            else if (Type.ToUpper() == "ADMIN")
610
-            {
611
-                if (individual != null)
612
-                    properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.OwnerId == individual.Id).ToList();
613
-                if (agent != null)
614
-                    properties = dBContext.Properties.Include("City").Include("Suburb").Where(x => x.AgencyId == agent.AgencyId).ToList();
615
-            }
616
-            else if (Type.ToUpper() == "SUPERADMIN")
599
+            var user = dBContext.Users.Where(u => u.Id == By).FirstOrDefault();
600
+            if (user != null)
617 601
             {
618
-                properties = dBContext.Properties.Include("City").Include("Suburb").ToList();
619
-            }
602
+                if (user.Role.ToUpper() == "AGENCY" || user.Role.ToUpper() == "AGENT")
603
+                {
604
+                    var agent = dBContext.Agents.Where(a => a.UserId == user.Id).FirstOrDefault();
605
+                    if (user.Role.ToUpper() == "AGENCY")
606
+                    {
607
+                        properties = dBContext.Properties.Where(p => p.AgencyId == agent.AgencyId).ToList();
608
+                    }
609
+                    else
610
+                    {
611
+                        properties = dBContext.Properties.Where(p => p.AgentId == agent.Id).ToList();
612
+                    }
613
+                }
614
+                if (user.Role.ToUpper() == "PRIVATE USER")
615
+                {
616
+                    var individual = dBContext.Individuals.Where(i => i.UserId == user.Id).FirstOrDefault();
617
+
618
+                    properties = dBContext.Properties.Where(p => p.OwnerId == individual.Id).ToList();
619
+                }
620
+                if (user.Role.ToUpper() == "SUPER ADMIN")
621
+                    properties = dBContext.Properties.Include("City").Include("Suburb").ToList();
622
+            }           
620 623
             
621 624
             List<PropertyList> list = new List<PropertyList>();
622 625
 

Загрузка…
Отмена
Сохранить