- Timestamp:
- 07/06/22 13:13:35 (2 years ago)
- Branches:
- master
- Children:
- 899b19d
- Parents:
- d76b7ee
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
resTools_backend/backend/Services/RestaurantService.cs
rd76b7ee rcc4db18 10 10 public Task CreateRestaurant(string name, int userId); 11 11 public Task<RestaurantResponse> GetRestaurant(); 12 public Task UploadImage(IFormFile file); 13 public Task UpdateRestaurant(UpdateRestaurantRequest req); 12 14 } 13 15 public class RestaurantService : IRestaurantService … … 32 34 .Select(x => new RestaurantResponse() 33 35 { 34 Id = x.Id,35 36 Name = x.Name, 36 OwnerId = x.OwnerFk, 37 Address = x.Address, 38 Phone = x.Phone, 39 Base64Image = String.Format("data:image/png;base64,{0}", Convert.ToBase64String(x.Image)), 40 Menu = x.Menu.Select(x => new MenuItemResponse() 41 { 42 Id = x.Id, 43 Title = x.Title, 44 Description = x.Description, 45 Price = x.Price 46 }).ToList() 37 47 }) 38 48 .FirstOrDefaultAsync(); 39 49 return res; 40 50 } 51 52 public async Task UpdateRestaurant(UpdateRestaurantRequest req) 53 { 54 var restaurant = await _context.Restoraunts.FirstOrDefaultAsync(); 55 restaurant.Name = req.Name; 56 restaurant.Address = req.Address; 57 restaurant.Phone = req.Phone; 58 _context.Restoraunts.Update(restaurant); 59 await _context.SaveChangesAsync(); 60 } 61 62 public async Task UploadImage(IFormFile file) 63 { 64 using (var memoryStream = new MemoryStream()) 65 { 66 await file.CopyToAsync(memoryStream); 67 var restaurant = await _context.Restoraunts.FirstOrDefaultAsync(); 68 restaurant.Image = memoryStream.ToArray(); 69 _context.Restoraunts.Update(restaurant); 70 _context.SaveChanges(); 71 } 72 } 41 73 } 42 74 }
Note:
See TracChangeset
for help on using the changeset viewer.