Changeset cc4db18 for resTools_backend/backend/Services
- Timestamp:
- 07/06/22 13:13:35 (2 years ago)
- Branches:
- master
- Children:
- 899b19d
- Parents:
- d76b7ee
- Location:
- resTools_backend/backend/Services
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
resTools_backend/backend/Services/ReservationService.cs
rd76b7ee rcc4db18 11 11 public Task ChangeReservationStatus(int resId, ReservationStatus status); 12 12 public Task<List<ReservationResponse>> GetReservatins(DateTime from, DateTime to); 13 public Task<List<ReservationResponse>> GetNewReservations(); 14 public Task AssignTable(int tableId, int reservationId); 13 15 } 14 16 public class ReservationService : IReservationService … … 21 23 _context = context; 22 24 _smsService = smsService; 25 } 26 27 public async Task AssignTable(int tableId, int reservationId) 28 { 29 var reservation = await _context.Reservations.FindAsync(reservationId); 30 reservation.Table = tableId; 31 _context.Update(reservation); 32 await _context.SaveChangesAsync(); 23 33 } 24 34 … … 50 60 } 51 61 62 public async Task<List<ReservationResponse>> GetNewReservations() 63 { 64 Restaurant res = await _context.Restoraunts 65 .Include(x => x.Reservations 66 .Where(x => x.ReservationStatus == ReservationStatus.New)) 67 .FirstOrDefaultAsync(); 68 var reservations = res.Reservations.Select(t => new ReservationResponse() 69 { 70 ContactName = t.ContactName, 71 ContactNumber = t.ContactNumber, 72 Persons = t.Persons, 73 StartDate = t.StartDate, 74 ReservationStatus = t.ReservationStatus, 75 Table = t.Table, 76 Id = t.Id, 77 ReservationPlace = t.ReservationPlace, 78 ReservationType = t.ReservationType 79 }).OrderByDescending(x => x.ReservationStatus == ReservationStatus.New).ToList(); 80 return reservations; 81 } 82 52 83 public async Task<List<ReservationResponse>> GetReservatins(DateTime from, DateTime to) 53 84 { … … 63 94 StartDate = t.StartDate, 64 95 ReservationStatus = t.ReservationStatus, 96 Table = t.Table, 65 97 Id = t.Id, 66 98 ReservationPlace = t.ReservationPlace, -
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.