[057037b] | 1 | using backend.Data;
|
---|
| 2 | using backend.DTOs;
|
---|
| 3 | using backend.Entities;
|
---|
| 4 | using Microsoft.EntityFrameworkCore;
|
---|
| 5 |
|
---|
| 6 | namespace backend.Services
|
---|
| 7 | {
|
---|
| 8 | public interface IReservationService
|
---|
| 9 | {
|
---|
| 10 | public Task CreateReservation(CreateReservationRequest req);
|
---|
| 11 | public Task ChangeReservationStatus(int resId, ReservationStatus status);
|
---|
| 12 | }
|
---|
| 13 | public class ReservationService : IReservationService
|
---|
| 14 | {
|
---|
| 15 | private readonly DataContext _context = null;
|
---|
| 16 | private readonly ISmsService _smsService = null;
|
---|
| 17 |
|
---|
| 18 | public ReservationService(DataContext context, ISmsService smsService)
|
---|
| 19 | {
|
---|
| 20 | _context = context;
|
---|
| 21 | _smsService = smsService;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | public async Task ChangeReservationStatus(int resId, ReservationStatus status)
|
---|
| 25 | {
|
---|
| 26 | var reservation = await _context.Reservations.FindAsync(resId);
|
---|
| 27 | reservation.ReservationStatus = status;
|
---|
| 28 | _context.Update(reservation);
|
---|
| 29 | await _context.SaveChangesAsync();
|
---|
| 30 | _smsService.ReservationStatusUpdate(reservation.ContactName, reservation.ContactNumber, reservation.ReservationStatus);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | public async Task CreateReservation(CreateReservationRequest req)
|
---|
| 34 | {
|
---|
| 35 | Restaurant res = await _context.Restoraunts.Include(x => x.Reservations).FirstOrDefaultAsync();
|
---|
| 36 | Reservation reservation = new Reservation()
|
---|
| 37 | {
|
---|
| 38 | ContactName = req.ContactName,
|
---|
| 39 | ContactNumber = req.ContactNumber,
|
---|
| 40 | ReservationPlace = req.ReservationPlace,
|
---|
| 41 | ReservationType = req.ReservationType,
|
---|
| 42 | StartDate = req.StartDate,
|
---|
| 43 | Persons = req.Persons,
|
---|
| 44 | ReservationStatus = ReservationStatus.New
|
---|
| 45 | };
|
---|
| 46 | res.Reservations.Add(reservation);
|
---|
| 47 | _context.Restoraunts.Update(res);
|
---|
| 48 | await _context.SaveChangesAsync();
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | }
|
---|