Ejemplo n.º 1
0
        public async Task <bool> ReserveRestaurant(RestaurantInputModel input)
        {
            var restaurant = this.restaurantRepository.All().FirstOrDefault(x => x.IsDeleted == false);

            if (restaurant != null && input.NumberOfGuests <= restaurant.MaxCapacity && input.EventDate.Day >= DateTime.Now.Day)
            {
                var restaurantReservation = new RestaurantReservation()
                {
                    UserId         = input.UserId,
                    RestaurantId   = restaurant.Id,
                    NumberOfGuests = input.NumberOfGuests,
                    PhoneNumber    = input.PhoneNumber,
                    EventType      = input.EventType,
                    EventDate      = input.EventDate,
                    CheckIn        = input.CheckIn,
                    CheckOut       = input.CheckOut,
                    TotalPrice     = 0,
                    Message        = input.Message,
                };

                var totalHours = (decimal)(restaurantReservation.CheckIn - restaurantReservation.CheckOut).TotalHours;

                var price = Math.Abs(restaurant.Price * totalHours);

                restaurantReservation.TotalPrice = price;

                var allReservationsForDate = this.restaurantReservationRepository.All().Where(x => x.EventDate == input.EventDate);

                var allReservations = this.restaurantReservationRepository.All().Select(x => x.EventDate).ToList();

                if (allReservationsForDate.Count() != 0)
                {
                    foreach (var item in allReservationsForDate)
                    {
                        if (restaurantReservation.NumberOfGuests > restaurant.CurrentCapacity)
                        {
                            return(false);
                        }
                    }
                }

                if (allReservations.Contains(input.EventDate))
                {
                    restaurant.CurrentCapacity -= input.NumberOfGuests;
                }
                else
                {
                    restaurant.CurrentCapacity  = restaurant.MaxCapacity;
                    restaurant.CurrentCapacity -= input.NumberOfGuests;
                }

                await this.restaurantReservationRepository.AddAsync(restaurantReservation);

                await this.restaurantReservationRepository.SaveChangesAsync();

                return(true);
            }

            throw new InvalidOperationException(GlobalConstants.InvalidOperationExceptionForRestaurantReservation);
        }
        public async Task <IActionResult> PutRestaurantReservation(int id, RestaurantReservation restaurantReservation)
        {
            if (id != restaurantReservation.Id)
            {
                return(BadRequest());
            }

            _context.Entry(restaurantReservation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestaurantReservationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// edit a reservation
        /// </summary>
        /// <param name="restaurantReservation">object of restaurant reservation</param>
        /// <returns>restaurant reservation object</returns>
        public RestaurantReservation EditReservation(RestaurantReservation restaurantReservation)
        {
            Database db        = Database.Open(DatabaseName);
            var      dbCommand = "UPDATE RestaurantReservation SET (AmountOfPersons = @1, Date = @2) WHERE Id = @0";
            var      row       = db.QuerySingle(dbCommand, restaurantReservation.Id, restaurantReservation.AmountOfPersons,
                                                restaurantReservation.Date);

            db.Close();
            return(restaurantReservation);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// get a reservation
        /// </summary>
        /// <param name="Id">id</param>
        /// <returns>reservation object</returns>
        public RestaurantReservation GetReservation(int Id)
        {
            Database db            = Database.Open(DatabaseName);
            string   insertCommand = "SELECT * FROM RestaurantReservation WHERE Id = @0";
            var      row           = db.QuerySingle(insertCommand, Id);

            db.Close();
            var reservering =
                new RestaurantReservation(row.Id, row.RestaurantId, row.UserInfoId, row.AmountOfPerons, row.Date, row.Time);

            return(reservering);
        }
        public ActionResult Index(int Date, TimeSpan Time, int Amount, int RestaurantId)
        {
            Wishlist wishlist = wishlistRepository.GetWishlist(Wishlist.Instance.UID);

            Restaurant            restaurant = restaurantsRepository.GetRestaurant(RestaurantId);
            RestaurantReservation r          = restaurantsRepository.CreateReservation(restaurant, Amount, Time, Date);

            WishlistItem item = new WishlistItem(r, wishlist);

            wishlist.WishlistItems.Add(item);

            Wishlist.Instance = wishlist;
            return(RedirectToAction("Index", "Wishlist"));
        }
        /// <summary>
        /// If valid inputs, create a new restaurant reservation when the user clicks "Add Reservation" button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void AddReservation_Click(object sender, RoutedEventArgs args)
        {
            if (CheckValidInputs())
            {
                string   restaurantName  = Check.FormatName(uxRestaurantName.Text);
                DateTime reservationTime = new DateTime(((DateTime)uxReservationDate.SelectedDate).Year,
                                                        ((DateTime)uxReservationDate.SelectedDate).Month, ((DateTime)uxReservationDate.SelectedDate).Day,
                                                        int.Parse(uxReservationTime.Text.Split(':')[0]), int.Parse(uxReservationTime.Text.Split(':')[1]), 0);

                string cityName = Check.FormatName(uxCity.Text);
                string country  = Check.FormatName(uxCountry.Text);
                string region   = Check.FormatName(uxRegion.Text);

                SqlCommandExecutor executor = new SqlCommandExecutor(connectionString);

                int cityID = 0;

                //Lookup city
                City city = executor.ExecuteReader(new LocationGetCityDelegate(cityName, country, region));

                //If city does not exist, add
                if (city == null)
                {
                    city = executor.ExecuteNonQuery(new LocationCreateCityDelegate(cityName, region, country));
                }
                cityID = city.CityID;

                int restaurantID = 0;

                //Lookup restaurant
                Restaurant restaurant = executor.ExecuteReader(new RestaurantsGetResturantByNameDelegate(restaurantName, cityID));

                //If restaurant does not exist, add
                if (restaurant == null)
                {
                    restaurant = executor.ExecuteNonQuery(new RestaurantsCreateRestaurantDelegate(cityID, cityName));
                }
                restaurantID = restaurant.RestaurantID;

                //Add new restaurant reservation
                RestaurantReservation restaurantReservation =
                    executor.ExecuteNonQuery(new RestaurantsCreateRestaurantReservationDelegate(tripID, restaurantID, reservationTime));

                MessageBox.Show("Reservation successfully added for " + restaurantName);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// get all reservations from a restaurant
        /// </summary>
        /// <param name="RestaurantId">id</param>
        /// <returns>list of reservations</returns>
        public List <RestaurantReservation> GetAllReservationsFromRestaurant(int RestaurantId)
        {
            Database db            = Database.Open(DatabaseName);
            string   insertCommand = "SELECT * FROM RestaurantReservation WHERE RestaurantId = @0";
            var      rows          = db.Query(insertCommand, RestaurantId);

            db.Close();
            List <RestaurantReservation> reserveringen = new List <RestaurantReservation>();

            foreach (var row in rows)
            {
                var reservering = new RestaurantReservation(row.Id, row.RestaurantId, row.UserInfoId,
                                                            row.AmountOfPersons, row.Date, row.Time);
                reserveringen.Add(reservering);
            }

            return(reserveringen);
        }
Ejemplo n.º 8
0
        public RestaurantReservation CreateReservation(Restaurant r, int amount, TimeSpan time, int date)
        {
            //Create a new reservation locally
            RestaurantReservation reservation = new RestaurantReservation();
            DateTime d = new DateTime(2016, 6, date, time.Hours, time.Minutes, 0);

            reservation.Amount     = amount;
            reservation.Date       = d;
            reservation.EventId    = r.EventId;
            reservation.Restaurant = r;

            //Get reserving
            IQueryable <RestaurantReservation> dbRes = context.RestaurantReservations.Where(x => x.EventId == reservation.EventId && x.Date == reservation.Date && x.Amount == reservation.Amount);

            //If it doesn't exist, add it to the database
            if (dbRes.Count() == 0)
            {
                context.RestaurantReservations.Add(reservation);
                context.SaveChanges();
                return(reservation);
            }

            return(dbRes.FirstOrDefault());
        }
        public async Task <ActionResult <RestaurantReservation> > PostRestaurantReservation(RestaurantReservation restaurantReservation)
        {
            _context.RestaurantReservation.Add(restaurantReservation);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRestaurantReservation", new { id = restaurantReservation.Id }, restaurantReservation));
        }