浏览代码

Restaurant Details Functions

master
George Williams 4 年前
父节点
当前提交
b4c51dfdb2

二进制
.vs/ProRestaurant/v16/.suo 查看文件


+ 1
- 1
ProRestaurant/Classes/ImageFormatter.cs 查看文件

@@ -50,7 +50,7 @@ namespace ProRestaurant.Classes
50 50
                             base64String = "data:image/jpeg;base64," + base64String;
51 51
                         if (Path.EndsWith(".gif"))
52 52
                             base64String = "data:image/gif;base64," + base64String;
53
-                        if (base64String.EndsWith(".png"))
53
+                        if (Path.EndsWith(".png"))
54 54
                             base64String = "data:image/png;base64," + base64String;
55 55
 
56 56
                         return base64String;

+ 15
- 0
ProRestaurant/Containers/RestaurantContainer.cs 查看文件

@@ -1,5 +1,6 @@
1 1
 using ProRestaurant.Models.Restaurants;
2 2
 using System.Collections.Generic;
3
+using System.Security.Permissions;
3 4
 
4 5
 namespace ProRestaurant.Containers
5 6
 {
@@ -24,4 +25,18 @@ namespace ProRestaurant.Containers
24 25
         public string DeliveryTime { get; set; }
25 26
         public string DeliveryFee { get; set; }
26 27
     }
28
+
29
+    public class RestaurantDetails : Restaurant
30
+    {
31
+        public List<string> SelectedMethodsOfPayments { get; set; }
32
+        public List<Category> SavedCategories { get; set; }
33
+        public List<TradingHoursContainer> SavedTradingHours { get; set; }
34
+        public int DeliveryFrom { get; set; }
35
+        public int DeliveryTo { get; set; }
36
+    }
37
+
38
+    public class Category
39
+    {
40
+        public string Description { get; set; }
41
+    }
27 42
 }

+ 1
- 0
ProRestaurant/Containers/TradingHoursContainer.cs 查看文件

@@ -2,6 +2,7 @@
2 2
 {
3 3
     public class TradingHoursContainer
4 4
     {
5
+        public int Id { get; set; }
5 6
         public string Description { get; set; }
6 7
         public string From { get; set; }
7 8
         public string To { get; set; }

+ 7
- 1
ProRestaurant/Controllers/Restaurants/RestaurantCategoryController.cs 查看文件

@@ -22,6 +22,12 @@ namespace ProRestaurant.Controllers.Restaurants
22 22
             return new OkObjectResult(repo.Get());
23 23
         }
24 24
 
25
+        [HttpGet("GetSelectCategories")]
26
+        public IActionResult GetSelectCategories()
27
+        {
28
+            return new OkObjectResult(repo.GetCategories());
29
+        }
30
+
25 31
         [HttpPost]
26 32
         public IActionResult Post([FromBody] RestaurantCategory category)
27 33
         {
@@ -50,7 +56,7 @@ namespace ProRestaurant.Controllers.Restaurants
50 56
 
51 57
         [HttpDelete("{id}")]
52 58
         public IActionResult Delete(int id)
53
-        {            
59
+        {                       
54 60
             repo.Remove(id);
55 61
             return new OkResult();
56 62
         }

+ 17
- 3
ProRestaurant/Controllers/Restaurants/RestaurantController.cs 查看文件

@@ -1,4 +1,5 @@
1 1
 using Microsoft.AspNetCore.Mvc;
2
+using ProRestaurant.Containers;
2 3
 using ProRestaurant.Models.Restaurants;
3 4
 using ProRestaurant.Repository.Restaurants;
4 5
 using System.Transactions;
@@ -31,9 +32,15 @@ namespace ProRestaurant.Controllers.Restaurants
31 32
         [HttpGet("{id}")]
32 33
         public IActionResult Get(int id)
33 34
         {
34
-            var restaurant = repo.GetRestaurant(u => u.Id == id);
35
+            var restaurant = repo.GetRestaurant(u => u.Id == id);           
35 36
             return new OkObjectResult(restaurant);
36
-        }        
37
+        }
38
+        
39
+        [HttpGet("GetTradingHours/{id}")]
40
+        public IActionResult GetTradingHours(int id)
41
+        {
42
+            return new OkObjectResult(repo.GetTradingHours(id));
43
+        }
37 44
 
38 45
         [HttpPost]
39 46
         public IActionResult Post([FromBody] Restaurant restaurant)
@@ -47,7 +54,7 @@ namespace ProRestaurant.Controllers.Restaurants
47 54
         }
48 55
 
49 56
         [HttpPut]
50
-        public IActionResult Put([FromBody] Restaurant restaurant)
57
+        public IActionResult Put([FromBody] RestaurantDetails restaurant)
51 58
         {
52 59
             if (restaurant != null)
53 60
             {
@@ -67,5 +74,12 @@ namespace ProRestaurant.Controllers.Restaurants
67 74
             repo.Remove(repo.GetRestaurant(u => u.Id == id));
68 75
             return new OkResult();
69 76
         }
77
+
78
+        [HttpDelete("RemoveTradingHours/{id}")]
79
+        public IActionResult RemoveTradingHours(int id)
80
+        {
81
+            repo.RemoveTradeHours(id);
82
+            return new OkResult();
83
+        }
70 84
     }
71 85
 }

+ 1
- 1
ProRestaurant/Repository/Accounts/RegistrationRepository.cs 查看文件

@@ -141,7 +141,7 @@ namespace ProRestaurant.Repository.Accounts
141 141
                 var loc = dBContext.Locations.FirstOrDefault()?.ImageStore;
142 142
                 if (!string.IsNullOrEmpty(loc))
143 143
                 {
144
-                    var folderName = restaurant.Name + string.Format("{0:yyyy_MM_dd_hh_mm_ss}", DateTime.Now);
144
+                    var folderName = restaurant.Name + "-" + restaurant.Suburb;
145 145
                     saveFile = true;
146 146
                     loc += string.Format("{0}", folderName);
147 147
                     if (!Directory.Exists(loc))

+ 3
- 1
ProRestaurant/Repository/Restaurants/IRestaurantCategoryRepository.cs 查看文件

@@ -1,4 +1,5 @@
1
-using ProRestaurant.Models.Restaurants;
1
+using ProRestaurant.Containers;
2
+using ProRestaurant.Models.Restaurants;
2 3
 using System;
3 4
 using System.Collections.Generic;
4 5
 using System.Threading.Tasks;
@@ -8,6 +9,7 @@ namespace ProRestaurant.Repository.Restaurants
8 9
     public interface IRestaurantCategoryRepository
9 10
     {
10 11
         ICollection<RestaurantCategory> Get();
12
+        List<Category> GetCategories();
11 13
         void Insert(RestaurantCategory RestaurantCategory);
12 14
         void Update(RestaurantCategory RestaurantCategory);
13 15
         void Remove(int id);

+ 4
- 2
ProRestaurant/Repository/Restaurants/IRestaurantRepository.cs 查看文件

@@ -11,10 +11,12 @@ namespace ProRestaurant.Repository.Restaurants
11 11
     {
12 12
         List<Restaurant> GetRestaurants();
13 13
         List<RestaurantCard> GetSearch();
14
-        Restaurant GetRestaurant(Func<Restaurant, bool> where);
14
+        List<TradingHours> GetTradingHours(int restaurantId);
15
+        RestaurantDetails GetRestaurant(Func<Restaurant, bool> where);
15 16
         void Insert(Restaurant restaurant);
16 17
         void Remove(Restaurant restaurant);
17
-        void Update(Restaurant restaurant);
18
+        void Update(RestaurantDetails restaurant);
19
+        void RemoveTradeHours(int id);
18 20
         void Save();
19 21
     }    
20 22
 }

+ 11
- 0
ProRestaurant/Repository/Restaurants/RestaurantCategoryRepository.cs 查看文件

@@ -1,5 +1,6 @@
1 1
 using Microsoft.EntityFrameworkCore;
2 2
 using ProRestaurant.Classes;
3
+using ProRestaurant.Containers;
3 4
 using ProRestaurant.DBContexts;
4 5
 using ProRestaurant.Models.Restaurants;
5 6
 using System.Collections.Generic;
@@ -29,6 +30,16 @@ namespace ProRestaurant.Repository.Restaurants
29 30
             return cats;
30 31
         }
31 32
 
33
+        public List<Category> GetCategories()
34
+        {
35
+            List<Category> categories = new List<Category>();
36
+            var cats = dBContext.RestaurantCategories.OrderBy(c => c.Description).ToList();
37
+            foreach (var cat in cats)
38
+                categories.Add(new Category() { Description = cat.Description });
39
+
40
+            return categories;
41
+        }
42
+
32 43
         public void Insert(RestaurantCategory RestaurantCategory)
33 44
         {
34 45
             dBContext.Add(RestaurantCategory);

+ 149
- 4
ProRestaurant/Repository/Restaurants/RestaurantRepository.cs 查看文件

@@ -5,6 +5,7 @@ using ProRestaurant.DBContexts;
5 5
 using ProRestaurant.Models.Restaurants;
6 6
 using System;
7 7
 using System.Collections.Generic;
8
+using System.IO;
8 9
 using System.Linq;
9 10
 
10 11
 namespace ProRestaurant.Repository.Restaurants
@@ -18,9 +19,64 @@ namespace ProRestaurant.Repository.Restaurants
18 19
             dBContext = db;
19 20
         }
20 21
 
21
-        public Restaurant GetRestaurant(Func<Restaurant, bool> where)
22
+        public RestaurantDetails GetRestaurant(Func<Restaurant, bool> where)
22 23
         {
23
-            return dBContext.Restaurants.Where(where).FirstOrDefault();
24
+            var restaurantDetails = new RestaurantDetails();
25
+            var restaurant = dBContext.Restaurants.Where(where).FirstOrDefault();
26
+
27
+            if (restaurant != null && !string.IsNullOrEmpty(restaurant.Logo))
28
+            {
29
+                if (!restaurant.Logo.Contains("data:image"))
30
+                    restaurant.Logo = ImageFormatter.ImageToBase64(restaurant.Logo);
31
+                else
32
+                    restaurant.Logo = restaurant.Logo;
33
+            }
34
+
35
+            foreach (var prop in restaurant.GetAllProperties())
36
+            {
37
+                if (prop != "Item")
38
+                    restaurantDetails[prop] = restaurant[prop];
39
+            }
40
+
41
+            if (!string.IsNullOrEmpty(restaurant.MethodsOfPayment) && restaurant.MethodsOfPayment.Contains("|"))
42
+            {
43
+                restaurantDetails.SelectedMethodsOfPayments = restaurant.MethodsOfPayment.Split("|").ToList();
44
+            }
45
+
46
+            if (!string.IsNullOrEmpty(restaurant.Categories))
47
+            {
48
+                var cats = restaurant.Categories.Replace(" ", "").Split("-").ToList();
49
+                restaurantDetails.SavedCategories = new List<Category>();
50
+                foreach(var cat in cats)
51
+                {
52
+                    restaurantDetails.SavedCategories.Add(new Category() { Description = cat });
53
+                }
54
+            }
55
+
56
+            if (!string.IsNullOrEmpty(restaurant.DeliveryTime))
57
+            {
58
+                var time = restaurant.DeliveryTime.Replace("Min", "").Replace(" ", "").Split("-");
59
+                restaurantDetails.DeliveryFrom = int.Parse(time[0]);
60
+                restaurantDetails.DeliveryTo = int.Parse(time[1]);
61
+            }
62
+
63
+            var trading = dBContext.TradingHours.Where(th => th.RestaurantId == restaurant.Id).ToList();
64
+            restaurantDetails.SavedTradingHours = new List<TradingHoursContainer>();
65
+            foreach(var trade in trading)
66
+            {
67
+                var item = new TradingHoursContainer
68
+                {
69
+                    Id = trade.Id,
70
+                    Description = trade.Description,
71
+                    From = string.Format("{0:hh:mm}", trade.OpeningTime),
72
+                    To = string.Format("{0:hh:mm}", trade.ClosingTime),
73
+                    Closed = trade.Closed,
74
+                    Open24 = trade.Opened24H
75
+                };
76
+                restaurantDetails.SavedTradingHours.Add(item);
77
+            }
78
+           
79
+            return restaurantDetails;
24 80
         }
25 81
 
26 82
         public List<RestaurantCard> GetSearch()
@@ -51,6 +107,12 @@ namespace ProRestaurant.Repository.Restaurants
51 107
             return cards;
52 108
         }
53 109
 
110
+        public List<TradingHours> GetTradingHours(int restaurantId)
111
+        {
112
+            var hours = dBContext.TradingHours.Where(t => t.RestaurantId == restaurantId).ToList();
113
+            return hours;
114
+        }
115
+
54 116
         public void Insert(Restaurant restaurant)
55 117
         {
56 118
             dBContext.Add(restaurant);
@@ -63,14 +125,97 @@ namespace ProRestaurant.Repository.Restaurants
63 125
             Save();
64 126
         }
65 127
 
128
+        public void RemoveTradeHours(int id)
129
+        {
130
+            var tHours = dBContext.TradingHours.Where(t => t.Id == id).FirstOrDefault();
131
+            dBContext.TradingHours.Remove(tHours);
132
+            Save();
133
+        }
134
+
66 135
         public void Save()
67 136
         {
68 137
             dBContext.SaveChanges();
69 138
         }
70 139
 
71
-        public void Update(Restaurant restaurant)
140
+        public void Update(RestaurantDetails restaurant)
72 141
         {
73
-            dBContext.Entry(restaurant).State = EntityState.Modified;
142
+            var resturantObj = dBContext.Restaurants.Where(r => r.Id == restaurant.Id).FirstOrDefault();
143
+
144
+            foreach (var prop in resturantObj.GetAllProperties())
145
+            {
146
+                if (prop != "Item")
147
+                    resturantObj[prop] = restaurant[prop];
148
+            }
149
+
150
+            resturantObj.DeliveryTime = string.Format("{0} - {1} Min", restaurant.DeliveryFrom, restaurant.DeliveryTo);
151
+
152
+            if (!string.IsNullOrEmpty(restaurant.Logo))
153
+            {
154
+                bool saveFile = false;
155
+                var loc = dBContext.Locations.FirstOrDefault()?.ImageStore;
156
+                if (!string.IsNullOrEmpty(loc))
157
+                {
158
+                    var folderName = restaurant.Name + "-" + restaurant.Suburb;
159
+                    saveFile = true;
160
+                    loc += string.Format("{0}", folderName);
161
+                    if (!Directory.Exists(loc))
162
+                    {
163
+                        Directory.CreateDirectory(loc);
164
+                    }
165
+
166
+                    if (saveFile)
167
+                    {
168
+                        string path = ImageFormatter.Base64ToImage(restaurant.Logo, loc, restaurant.Name.Trim());
169
+                        resturantObj.Logo = path;
170
+                    }
171
+                }
172
+
173
+                if (!saveFile)
174
+                    resturantObj.Logo = restaurant.Logo;
175
+            }
176
+
177
+            if (!string.IsNullOrEmpty(restaurant.MethodsOfPayment))
178
+            {
179
+                resturantObj.MethodsOfPayment = restaurant.MethodsOfPayment.Substring(0, restaurant.MethodsOfPayment.Length - 1);
180
+            }
181
+
182
+            if (!string.IsNullOrEmpty(restaurant.Categories))
183
+            {
184
+                resturantObj.Categories = resturantObj.Categories.Substring(0, restaurant.Categories.Length - 1).Trim();
185
+                resturantObj.Categories = resturantObj.Categories.Replace("|", " - ");
186
+            }
187
+
188
+            foreach (var trade in restaurant.SavedTradingHours)
189
+            {
190
+                if (trade.Id == 0)
191
+                {
192
+                    TradingHours tHours = new TradingHours()
193
+                    {
194
+                        Description = trade.Description,
195
+                        OpeningTime = DateTime.Parse(string.Format("{0} {1}", string.Format("{0:yyyy/MM/dd}", DateTime.Now), trade.From)),
196
+                        ClosingTime = DateTime.Parse(string.Format("{0} {1}", string.Format("{0:yyyy/MM/dd}", DateTime.Now), trade.To)),
197
+                        Closed = trade.Closed,
198
+                        Opened24H = trade.Open24,
199
+                        RestaurantId = restaurant.Id
200
+                    };
201
+                    dBContext.Add(tHours);
202
+                }    
203
+                else
204
+                {
205
+                    var tHours = dBContext.TradingHours.Where(t => t.Id == trade.Id).FirstOrDefault();
206
+                    if (tHours != null)
207
+                    {
208
+                        tHours.Description = trade.Description;
209
+                        tHours.OpeningTime = DateTime.Parse(string.Format("{0} {1}", string.Format("{0:yyyy/MM/dd}", DateTime.Now), trade.From));
210
+                        tHours.ClosingTime = DateTime.Parse(string.Format("{0} {1}", string.Format("{0:yyyy/MM/dd}", DateTime.Now), trade.To));
211
+                        tHours.Closed = trade.Closed;
212
+                        tHours.Opened24H = trade.Open24;
213
+                    }
214
+                    dBContext.Entry(tHours).State = EntityState.Modified;
215
+                }
216
+            }
217
+
218
+            dBContext.Entry(resturantObj).State = EntityState.Modified;
74 219
             Save();
75 220
         }
76 221
 

二进制
ProRestaurant/bin/Debug/netcoreapp2.2/ProRestaurant.dll 查看文件


二进制
ProRestaurant/bin/Debug/netcoreapp2.2/ProRestaurant.pdb 查看文件


二进制
ProRestaurant/obj/Debug/netcoreapp2.2/ProRestaurant.csprojAssemblyReference.cache 查看文件


二进制
ProRestaurant/obj/Debug/netcoreapp2.2/ProRestaurant.dll 查看文件


二进制
ProRestaurant/obj/Debug/netcoreapp2.2/ProRestaurant.pdb 查看文件


正在加载...
取消
保存