Beispiel #1
0
        // GET: HotelRooms/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var hotelRoom = new HotelRoomVM(_hotelRoomRepository.GetWhereId(id));

            if (hotelRoom == null)
            {
                return(HttpNotFound());
            }

            return(View(hotelRoom));
        }
        private void CheckIfYouCanBookRoom(HotelBookingVM hotelBookingVM)
        {
            var hotelroom = _hotelRoomRepository.GetWhereId(hotelBookingVM.HotelRoomId);

            if (hotelBookingVM.TamagotchisIds != null)
            {
                if (!(hotelBookingVM.TamagotchisIds.Count() <= hotelroom.RoomSize))
                {
                    ModelState.AddModelError("", $"Amount of tamagotchis is to big for this room(room size: {hotelroom.RoomSize})");
                }

                var tamagotchisVM = hotelBookingVM.TamagotchisIds.Select(ti => new TamagotchiVM(_tamagotchiRepository.GetWhereId(ti))).ToList();

                foreach (var tamagotchi in tamagotchisVM)
                {
                    if (tamagotchi.Money < hotelroom.HotelRoomType.RoomTypeCost)
                    {
                        ModelState.AddModelError("", $"{tamagotchi.Name} does not have enough money for this room ( room cost: {hotelroom.HotelRoomType.RoomTypeCost} , tamagotchi money: {tamagotchi.Money})");
                        break;
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Amount of tamagotchis can not be 0");
            }
        }