public IActionResult UpdateRestaurant(int restaurantId,
                                              [FromBody] RestaurantUpdateDto updatedRestaurant)
        {
            this.RestaurantRepository.UpdateRestaurant(restaurantId, updatedRestaurant);

            return(NoContent());
        }
Exemple #2
0
        public async Task Update(int id, RestaurantUpdateDto model)
        {
            var entry = await _context.Restaurants.SingleAsync(x => x.RestaurantId == id);

            entry.Name        = model.Name;
            entry.Address     = model.Address;
            entry.PhoneNumber = model.PhoneNumber;

            await _context.SaveChangesAsync();
        }
Exemple #3
0
        public void UpdateRestaurantUpdatesRestaurantData(int restaurantId)
        {
            using var scope = this.CustomConfigurationFactory.Services.CreateScope();
            var restaurantRepository = scope.ServiceProvider.GetRequiredService <IRestaurantRepository>();

            var restaurant = restaurantRepository.GetRestaurant(restaurantId);
            var restaurantTitleBeforeUpdate   = restaurant.Title;
            var restaurantEmailBeforeUpdate   = restaurant.Email;
            var restaurantWebsiteBeforeUpdate = restaurant.Website;

            var restaurantUpdateDto = new RestaurantUpdateDto
            {
                OldPassword                      = $"TestPassword{restaurantId}",
                NewPassword                      = string.Empty,
                Email                            = $"{restaurant.Email}{restaurantId}",
                Title                            = $"{restaurant.Title}{restaurantId}",
                Description                      = restaurant.Description + restaurantId,
                PhoneNumber                      = restaurant.PhoneNumber + restaurantId,
                ParkingType                      = restaurant.ParkingType + restaurantId,
                AdditionalInformation            = restaurant.ParkingType + restaurantId,
                Website                          = restaurant.Website + restaurantId,
                MinimumPeopleForReservation      = restaurant.MinimumPeopleForReservation,
                MaximumPeopleForReservation      = restaurant.MaximumPeopleForReservation,
                AgeLimit                         = restaurant.AgeLimit,
                AllowedTimeForReservationInWeeks = restaurant.AllowedTimeForReservationInWeeks,
                CuisineId                        = restaurant.CuisineId,
                PriceId                          = restaurant.PriceId,
                Status                           = restaurant.Status,
                BusinessHours                    = new List <BusinessHoursUpdateDto> {
                },
                Addresses                        = new List <AddressUpdateDto>
                {
                    new AddressUpdateDto
                    {
                        CityId        = 1,
                        StreetAddress = $"Test st. {restaurantId}"
                    }
                }
            };

            restaurantRepository.UpdateRestaurant(restaurantId, restaurantUpdateDto);
            var restaurantAfterUpdate = restaurantRepository.GetRestaurant(restaurantId);

            Assert.Equal(restaurantTitleBeforeUpdate + restaurantId, restaurantAfterUpdate.Title);
            Assert.Equal(restaurantEmailBeforeUpdate + restaurantId, restaurantAfterUpdate.Email);
            Assert.Equal(restaurantWebsiteBeforeUpdate + restaurantId, restaurantAfterUpdate.Website);
        }
Exemple #4
0
        public void UpdateRestaurant(int restaurantId, RestaurantUpdateDto updatedRestaurant)
        {
            var restaurant = this.GetRestaurant(restaurantId);

            if (restaurant == null)
            {
                throw new Exception();
            }

            var isPasswordVerified = Crypt.Verify(updatedRestaurant.OldPassword, restaurant.Password);

            if (!isPasswordVerified)
            {
                throw new Exception();
            }

            restaurant.Email                            = updatedRestaurant.Email;
            restaurant.Title                            = updatedRestaurant.Title;
            restaurant.Description                      = updatedRestaurant.Description;
            restaurant.PhoneNumber                      = updatedRestaurant.PhoneNumber;
            restaurant.ParkingType                      = updatedRestaurant.ParkingType;
            restaurant.AdditionalInformation            = updatedRestaurant.AdditionalInformation;
            restaurant.Website                          = updatedRestaurant.Website;
            restaurant.MinimumPeopleForReservation      = updatedRestaurant.MinimumPeopleForReservation;
            restaurant.MaximumPeopleForReservation      = updatedRestaurant.MaximumPeopleForReservation;
            restaurant.AgeLimit                         = updatedRestaurant.AgeLimit;
            restaurant.Status                           = updatedRestaurant.Status;
            restaurant.AllowedTimeForReservationInWeeks = updatedRestaurant.AllowedTimeForReservationInWeeks;
            restaurant.PriceId                          = updatedRestaurant.PriceId;
            restaurant.CuisineId                        = updatedRestaurant.CuisineId;

            // Currently supports only 1 address.
            restaurant.Addresses.ElementAt(0).CityId        = updatedRestaurant.Addresses.ElementAt(0).CityId;
            restaurant.Addresses.ElementAt(0).StreetAddress = updatedRestaurant.Addresses.ElementAt(0).StreetAddress;

            foreach (var oldBusinessHours in restaurant.BusinessHours)
            {
                var updatedBusinessHours = updatedRestaurant.BusinessHours.FirstOrDefault(bh => bh.DayOfWeek == oldBusinessHours.DayOfWeek);

                if (updatedBusinessHours == null)
                {
                    this.Context.BusinessHours.Remove(oldBusinessHours);
                }
                else
                {
                    oldBusinessHours.OpeningTime = TimeSpan.Parse(updatedBusinessHours.OpeningTime);
                    oldBusinessHours.ClosingTime = TimeSpan.Parse(updatedBusinessHours.ClosingTime);
                }

                updatedRestaurant.BusinessHours.Remove(updatedBusinessHours);
            }

            foreach (var newBusinessHours in updatedRestaurant.BusinessHours)
            {
                restaurant.BusinessHours.Add(this.Mapper.Map <BusinessHours>(newBusinessHours));
            }

            if (!string.IsNullOrEmpty(updatedRestaurant.NewPassword))
            {
                restaurant.Password = Crypt.HashPassword(updatedRestaurant.NewPassword);
            }

            this.Context.SaveChanges();
        }