Beispiel #1
0
        protected override void PopulateEntity(Reservation reservation, ReservationAddEditViewModel model)
        {
            reservation.Id              = model.Id;
            reservation.UserId          = model.UserId;
            reservation.RestaurantId    = model.RestaurantId;
            reservation.Comment         = model.Comment;
            reservation.PeopleCount     = model.PeopleCount;
            reservation.ReservationTime = model.ReservationTime;

            ReservationService service     = new ReservationService();
            RestaurantService  restService = new RestaurantService();

            reservation.RestaurantName = restService.GetById((model.RestaurantId)).Name;

            if (!service.CheckFreeSeats(reservation))
            {
                ModelState.AddModelError("PeopleCount", "There are no free seats");
                model.Restaurants = GetRestaurants();
                //return View(model);
            }
            else
            {
                service.Save(reservation);
                // return RedirectToAction("Index");
            }
        }
        public bool CheckFreeSeats(Reservation reservation)
        {
            RestaurantService  restService = new RestaurantService();
            Restaurant         restaurant  = restService.GetById(reservation.RestaurantId);
            ReservationService service     = new ReservationService();

            int totalPeople = service.GetAll(r => r.RestaurantId == reservation.RestaurantId &&
                                             r.ReservationTime == reservation.ReservationTime)

                              .Select(r => r.PeopleCount).ToList().Sum();

            if (reservation.PeopleCount < (restaurant.Capacity - totalPeople))
            {
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        public async Task G_GetByID_TakeFirstRestaurant_ReturnSameRestaurant()
        {
            //Arrange
            var restaurantService = new RestaurantService();

            restaurantsToDelete.Add(new Restaurant()
            {
                ID = Guid.NewGuid()
            });
            restaurantService.Create(restaurantsToDelete.First());

            //Act
            var result = restaurantService.GetById(restaurantsToDelete.First().ID);

            //Assert
            Assert.AreEqual(restaurantsToDelete.First().ID, result.ID);

            //Clean up database
            await deleteTestResto();
        }
 public Restaurant FindById(string id)
 {
     return(restaurant.GetById(id));
 }
Beispiel #5
0
        public async Task <ActionResult <Restaurant> > Get(int id)
        {
            var restaurant = await _restaurantService.GetById(id);

            return(restaurant);
        }