public IActionResult Create(ReservationViewModel reservationVM)
        {
            if (!ModelState.IsValid)
            {
                return(View(reservationVM));
            }
            Reservation reservation = new Reservation
            {
                Id                = reservationVM.Id,
                AllInclusive      = reservationVM.AllInclusive,
                BreakfastIncluded = reservationVM.BreakfastIncluded,
                LeaveDate         = reservationVM.LeaveDate,
                AccommodationDate = reservationVM.AccommodationDate,
                Cost              = reservationVM.Cost,
                RoomId            = reservationVM.RoomViewModel.Id,
                Room              = _roomRepo.GetById(reservationVM.RoomViewModel.Id),
                Clients           = (ICollection <Client>)reservationVM.ClientsViewModels.Select(c => new Client()
                {
                    Id            = c.Id,
                    Email         = c.Email,
                    FirstName     = c.FirstName,
                    IsAdult       = c.IsAdult,
                    LastName      = c.LastName,
                    PhoneNumber   = c.PhoneNumber,
                    ReservationId = reservationVM.Id,
                    Reservation   = _reservationRepo.GetById(reservationVM.Id)
                })
            };

            _reservationRepo.Add(reservation);
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 2
0
        public IActionResult Edit(RoomViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            Room room = _repo.GetById(vm.Id);

            room.Id = vm.Id;
            room.BedPriceForAdult = vm.BedPriceForAdult;
            room.BedPriceForKid   = vm.BedPriceForKid;
            room.Capacity         = vm.Capacity;
            room.IsFree           = vm.IsFree;
            room.Number           = vm.Number;
            room.Type             = vm.Type;
            room.Reservation      = _context.Reservations.Find(vm.ReservationId);
            room.ReservationId    = vm.ReservationId;



            _repo.Update(room);
            return(RedirectToAction("Index", "Rooms"));
        }