Esempio n. 1
0
 private async void LoadData()
 {
     IsLoading = true;
     this.Repository = await RestaurantContextFactory.GetRestaurantContextAsync();
     OnDataLoaded();
     IsLoading = false;
 }
Esempio n. 2
0
        private async void LoadData()
        {
            //this.Repository = new RestaurantContext();
            //await this.Repository.InitializeContextAsync();

            this.Repository = await RestaurantContextFactory.GetRestaurantContextAsync();

            OnDataLoaded();
        }
 public static async Task<RestaurantContext> GetRestaurantContextAsync()
 {
     if(_restaurantContext == null)
     {
         _restaurantContext = new RestaurantContext();
         await _restaurantContext.InitializeContextAsync();
     }
     return _restaurantContext;
 }
Esempio n. 4
0
 private async void LoadData()
 {
     IsLoading = !IsDataLoaded();
     try
     {
         Repository = await RestaurantContextFactory.GetRestaurantContextAsync();
         OnDataLoaded();
     }
     finally
     {
         IsLoading = false;
     }
 }
Esempio n. 5
0
 public RestaurantAppService(RestaurantContext context, IMapper mapper)
 {
     _context = context ?? throw new System.ArgumentNullException(nameof(context));
     _mapper  = mapper ?? throw new ArgumentNullException(nameof(mapper));
 }
Esempio n. 6
0
 public async Task UpdateAsync(Dish dish)
 {
     using var ctx         = new RestaurantContext();
     ctx.Entry(dish).State = EntityState.Modified;
     await ctx.SaveChangesAsync();
 }
Esempio n. 7
0
 public async Task <Dish> ReadAsync(Guid id)
 {
     using var ctx = new RestaurantContext();
     return(await ctx.Dishes.FirstOrDefaultAsync(x => x.Id == id));
 }
Esempio n. 8
0
 public void Create(Dish dish)
 {
     using var ctx = new RestaurantContext();
     ctx.Dishes.Add(dish);
     ctx.SaveChanges();
 }
Esempio n. 9
0
 public List <Dish> List()
 {
     using var ctx = new RestaurantContext();
     return(ctx.Dishes.ToList());
 }
Esempio n. 10
0
        public void SeatCustomer(DateTime when, int reservationId, List <byte> tables, int waiterId)
        {
            var availableSeats = AvailableSeatingByDateTime(when.Date, when.TimeOfDay);

            using (var context = new RestaurantContext())
            {
                List <string> errors = new List <string>();
                // Rule checking:
                // - Reservation must be in Booked status
                // - Table must be available - typically a direct check on the table, but proxied based on the mocked time here
                // - Table must be big enough for the # of customers
                var reservation = context.Reservations.Find(reservationId);
                if (reservation == null)
                {
                    errors.Add("The specified reservation does not exist");
                }
                else if (reservation.ReservationStatus != Reservation.Booked)
                {
                    errors.Add("The reservation's status is not valid for seating. Only booked reservations can be seated.");
                }
                var capacity = 0;
                foreach (var tableNumber in tables)
                {
                    if (!availableSeats.Exists(x => x.Table == tableNumber))
                    {
                        errors.Add("Table " + tableNumber + " is currently not available");
                    }
                    else
                    {
                        capacity += availableSeats.Single(x => x.Table == tableNumber).Seating;
                    }
                }
                if (capacity < reservation.NumberInParty)
                {
                    errors.Add("Insufficient seating capacity for number of customers. Alternate tables must be used.");
                }
                if (errors.Count > 0)
                {
                    throw new BusinessRuleException("Unable to seat customer", errors);
                }
                // 1) Create a blank bill with assigned waiter
                Bill seatedCustomer = new Bill()
                {
                    BillDate      = when,
                    NumberInParty = reservation.NumberInParty,
                    WaiterID      = waiterId,
                    ReservationID = reservation.ReservationID
                };
                context.Bills.Add(seatedCustomer);
                // 2) Add the tables for the reservation and change the reservation's status to arrived
                foreach (var tableNumber in tables)
                {
                    reservation.Tables.Add(context.Tables.Single(x => x.TableNumber == tableNumber));
                }
                reservation.ReservationStatus = Reservation.Arrived;
                var updatable = context.Entry(context.Reservations.Attach(reservation));
                updatable.Property(x => x.ReservationStatus).IsModified = true;
                //updatable.Reference(x=>x.Tables).
                // 3) Save changes - All of the modifications to the context are processed as a transaction
                context.SaveChanges();
            }
            //string message = String.Format("Not yet implemented. Need to seat reservation {0} for waiter {1} at tables {2}", reservationId, waiterId, string.Join(", ", tables));
            //throw new NotImplementedException(message);
        }
 public HomeController()
 {
     dbContext = new RestaurantContext();
 }
 public MenuRepository()
 {
     ctx = new RestaurantContext();
 }
Esempio n. 13
0
 private async void LoadData()
 {
     this.Repository = new RestaurantContext();
     await this.Repository.InitializeContextAsync();
     OnDataLoaded();
 }
Esempio n. 14
0
 private async void LoadData()
 {
     this.Repository = await RestaurantContextFactory.GetRestaurantContextAsync();
     OnDataLoaded();
 }
 public GroupRepository(RestaurantContext context)
     : base(context)
 {
 }
Esempio n. 16
0
 public RestaurantRepository(RestaurantContext context)
 {
     _context = context;
 }
        public void Run(RestaurantContext db)
        {
            Console.WriteLine(this.description);
            Console.WriteLine("-------------------------------------\n");

            List <Restaurant> restaurants = db.Restaurants.ToList();

            if (!restaurants.Any())
            {
                Console.WriteLine("No restaurants");
                return;
            }

            Console.WriteLine("Listing all restaurants:");

            foreach (var toPrint in restaurants)
            {
                Console.WriteLine($"{toPrint.Name} - {toPrint.Address}");
            }

            Console.WriteLine("\nEnter address of restaurant to view:");
            string     input      = Console.ReadLine();
            Restaurant restaurant = db.Restaurants.Find(input);

            if (restaurant == null)
            {
                Console.WriteLine("The address you typed did not match any existing restaurants...");
                return;
            }

            Console.WriteLine("----------------------------");
            Console.WriteLine($"Showing menu for {restaurant.Name}:");
            Console.WriteLine("----------------------------");

            List <Dish> dishes = db.Dishes.Where(d => d.RestaurantAddress == restaurant.Address).ToList();

            if (dishes.Any())
            {
                foreach (var dish in dishes)
                {
                    Console.WriteLine($"{dish.Name} price: {dish.Price} dkk");
                }
            }

            List <Review> reviews = db.Reviews.Where(r => r.RestaurantAddress == restaurant.Address).ToList();
            List <int>    scores  = new List <int>();

            if (reviews.Any())
            {
                foreach (var review in reviews)
                {
                    scores.Add((review.Stars));
                }
                Console.WriteLine($"Avg. Score: {scores.Average()}");
            }
            else
            {
                Console.WriteLine("No reviews for this restaurant");
            }
            Console.WriteLine();
        }
Esempio n. 18
0
 public BanController(RestaurantContext context)
 {
     _context = context;
 }
Esempio n. 19
0
 public EmployeeRepository(RestaurantContext context)
 {
     _context = context;
 }
 public BaseController(RestaurantContext dbContext)
 {
     _dbContext = dbContext;
 }
Esempio n. 21
0
 public DishDataAccessObject()
 {
     _context = new RestaurantContext();
 }
Esempio n. 22
0
 public async Task <List <Dish> > ListAsync()
 {
     using var ctx = new RestaurantContext();
     return(await ctx.Dishes.ToListAsync());
 }
Esempio n. 23
0
 public ExtraRepository(RestaurantContext context) : base(context)
 {
 }
Esempio n. 24
0
 public Dish Read(Guid id)
 {
     using var ctx = new RestaurantContext();
     return(ctx.Dishes.FirstOrDefault(x => x.Id == id));
 }
 public ClientRecordDataAccessObject()
 {
     _context = new RestaurantContext();
 }
Esempio n. 26
0
 public void Update(Dish dish)
 {
     using var ctx         = new RestaurantContext();
     ctx.Entry(dish).State = EntityState.Modified;
     ctx.SaveChanges();
 }
 public MealDishRepository(RestaurantContext dbContext)
 {
     DbContext = dbContext;
 }
Esempio n. 28
0
 public void SeatCustomer(DateTime when, int reservationId, List<byte> tables, int waiterId)
 {
     var availableSeats = AvailableSeatingByDateTime(when.Date, when.TimeOfDay);
     using (var context = new RestaurantContext())
     {
         List<string> errors = new List<string>();
         // Rule checking:
         // - Reservation must be in Booked status
         // - Table must be available - typically a direct check on the table, but proxied based on the mocked time here
         // - Table must be big enough for the # of customers
         var reservation = context.Reservations.Find(reservationId);
         if (reservation == null)
             errors.Add("The specified reservation does not exist");
         else if (reservation != null && reservation.ReservationStatus != Reservation.Booked)
             errors.Add("The reservation's status is not valid for seating. Only booked reservations can be seated.");
         var capacity = 0;
         foreach (var tableNumber in tables)
         {
             if (!availableSeats.Exists(x => x.Table == tableNumber))
                 errors.Add("Table " + tableNumber + " is currently not available");
             else
                 capacity += availableSeats.Single(x => x.Table == tableNumber).Seating;
         }
         if (capacity < reservation.NumberInParty)
             errors.Add("Insufficient seating capacity for number of customers. Alternate tables must be used.");
         if (errors.Count > 0)
             throw new BusinessRuleException("Unable to seat customer", errors);
         // 1) Create a blank bill with assigned waiter
         Bill seatedCustomer = new Bill()
         {
             BillDate = when,
             NumberInParty = reservation.NumberInParty,
             WaiterID = waiterId,
             ReservationID = reservation.ReservationID
         };
         context.Bills.Add(seatedCustomer);
         // 2) Add the tables for the reservation and change the reservation's status to arrived
         foreach (var tableNumber in tables)
             reservation.Tables.Add(context.Tables.Single(x => x.TableNumber == tableNumber));
         reservation.ReservationStatus = Reservation.Arrived;
         var updatable = context.Entry(context.Reservations.Attach(reservation));
         updatable.Property(x => x.ReservationStatus).IsModified = true;
         //updatable.Reference(x=>x.Tables).
         // 3) Save changes
         context.SaveChanges();
     }
     //string message = String.Format("Not yet implemented. Need to seat reservation {0} for waiter {1} at tables {2}", reservationId, waiterId, string.Join(", ", tables));
     //throw new NotImplementedException(message);
 }
 public List <Title> List()
 {
     using var ctx = new RestaurantContext();
     return(ctx.Titles.ToList());
 }
 public StaffTitleDataAccessObject()
 {
     _context = new RestaurantContext();
 }
 public void Create(Title title)
 {
     using var ctx = new RestaurantContext();
     ctx.Titles.Add(title);
     ctx.SaveChanges();
 }
Esempio n. 32
0
 public HomeController(RestaurantContext context)
 {
     _context = context;
 }
Esempio n. 33
0
 public GestionRestaurantController(RestaurantContext context)
 {
     this.restService = new RestaurantService(context);
 }
Esempio n. 34
0
 /// <summary>
 /// Adds the adress to a restaurant
 /// </summary>
 /// <param name="restaurant"></param>
 /// <param name="adress"></param>
 public void AddAdress(Restaurant restaurant, Adress adress)
 {
     using var dbContext = new RestaurantContext();
     dbContext.Restaurants.Find(restaurant.ID).Adress = adress;
     dbContext.SaveChanges();
 }
Esempio n. 35
0
 public ChiTietDatBanController(RestaurantContext context)
 {
     _context = context;
 }
Esempio n. 36
0
 public DishRepository(RestaurantContext restaurantContext) : base(restaurantContext)
 {
 }
Esempio n. 37
0
        /// <summary>
        /// Initializes a new restaurant repository given a suitable restaurant data source.
        /// Creates the backing database if it doesn't exist.
        /// </summary>
        /// <param name="context">The EF Core restaurant database context</param>
        public RestaurantRepository(RestaurantContext context)
        {
            context.Database.EnsureCreated();

            _context = context ?? throw new ArgumentNullException(nameof(context));
        }
Esempio n. 38
0
 public CategoryRepository(RestaurantContext context)
     : base(context)
 {
 }
 public EmployeeController(RestaurantContext context)
 {
     _context = context;
 }
Esempio n. 40
0
        public List <SeatingSummary> SeatingByDateTime(DateTime date, TimeSpan time)
        {
            using (var context = new RestaurantContext())
            {
                // Step 1 - Get the table info along with any walk-in bills and reservation bills for the specific time slot
                var step1 = from data in context.Tables
                            select new
                {
                    Table   = data.TableNumber,
                    Seating = data.Capacity,
                    // This sub-query gets the bills for walk-in customers
                    Bills = from billing in data.Bills
                            where
                            billing.BillDate.Year == date.Year &&
                            billing.BillDate.Month == date.Month &&
                            billing.BillDate.Day == date.Day
                            //The following won't work EF to Entities - it will return this exception:
                            //"The specified type member 'TimeofDay' is not supported..."
                            //&& billing.BillDate.TimeOfDay <= time
                            && DbFunctions.CreateTime(billing.BillDate.Hour, billing.BillDate.Minute, billing.BillDate.Second) <= time &&
                            (!billing.OrderPaid.HasValue || billing.OrderPaid.Value >= time)
                            //                          && (!billing.PaidStatus || billing.OrderPaid >= time)
                            select billing,
                    // This sub-query gets the bills for reservations
                    Reservations = from booking in data.Reservations
                                   from billing in booking.Bills
                                   where
                                   billing.BillDate.Year == date.Year &&
                                   billing.BillDate.Month == date.Month &&
                                   billing.BillDate.Day == date.Day &&
                                   DbFunctions.CreateTime(billing.BillDate.Hour, billing.BillDate.Minute, billing.BillDate.Second) <= time &&
                                   (!billing.OrderPaid.HasValue || billing.OrderPaid.Value >= time)
                                   //                          && (!billing.PaidStatus || billing.OrderPaid >= time)
                                   select billing
                };


                // Step 2 - Union the walk-in bills and the reservation bills while extracting the relevant bill info
                // .ToList() helps resolve the "Types in Union or Concat are constructed incompatibly" error
                var step2 = from data in step1.ToList() // .ToList() forces the first result set to be in memory
                            select new
                {
                    Table         = data.Table,
                    Seating       = data.Seating,
                    CommonBilling = from info in data.Bills.Union(data.Reservations)
                                    select new             // info
                    {
                        BillID      = info.BillID,
                        BillTotal   = info.Items.Sum(bi => bi.Quantity * bi.SalePrice),
                        Waiter      = info.Waiter.FirstName,
                        Reservation = info.Reservation
                    }
                };


                // Step 3 - Get just the first CommonBilling item
                //         (presumes no overlaps can occur - i.e., two groups at the same table at the same time)
                var step3 = from data in step2.ToList()
                            select new
                {
                    Table   = data.Table,
                    Seating = data.Seating,
                    Taken   = data.CommonBilling.Count() > 0,
                    // .FirstOrDefault() is effectively "flattening" my collection of 1 item into a
                    // single object whose properties I can get in step 4 using the dot (.) operator
                    CommonBilling = data.CommonBilling.FirstOrDefault()
                };


                // Step 4 - Build our intended seating summary info
                var step4 = from data in step3
                            select new SeatingSummary()
                {
                    Table   = data.Table,
                    Seating = data.Seating,
                    Taken   = data.Taken,
                    // use a ternary expression to conditionally get the bill id (if it exists)
                    BillID = data.Taken ?                          // if(data.Taken)
                             data.CommonBilling.BillID             // value to use if true
                                       :                           // else
                             (int?)null,                           // value to use if false
                    //Note: going back to step 2 to be more selective of my Billing Information
                    BillTotal = data.Taken ?
                                data.CommonBilling.BillTotal : (decimal?)null,
                    Waiter          = data.Taken ? data.CommonBilling.Waiter : (string)null,
                    ReservationName = data.Taken ?
                                      (data.CommonBilling.Reservation != null ?
                                       data.CommonBilling.Reservation.CustomerName : (string)null)
                                : (string)null
                };
                return(step4.ToList());
            }
        }
 public TableRepository()
 {
     ctx = new RestaurantContext();
 }