예제 #1
0
 public async Task <IActionResult> Edit(ReservationView reservationview)
 {
     if (ModelState.IsValid)
     {
         try
         {
             reservationview.StayRooms.ToList().ForEach(r => r.Arrival   = reservationview.Arrival);
             reservationview.StayRooms.ToList().ForEach(r => r.Departure = reservationview.Departure);
             reservationview.StayRooms.ToList().ForEach(r => _context.Update(r));
             _context.Update(reservationview.Reservation);
             await _context.SaveChangesAsync();
         }
         catch (Exception ex)
         {
             if (!ReservationExists(reservationview.Reservation.ReservationID))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction("Index"));
     }
     ViewData["HotelID"] = new SelectList(_context.Hotels, "HotelID", "Name", reservationview.Reservation.HotelID);
     return(View(reservationview));
 }
예제 #2
0
        public async Task <IActionResult> EditPost(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(NotFound());
            }
            var hotelgrouptoupdate = await _context.HotelGroups.SingleOrDefaultAsync(s => s.HotelGroupID == id);

            if (await TryUpdateModelAsync(hotelgrouptoupdate, "", s => s.Name))
            {
                try
                {
                    _context.Update(hotelgrouptoupdate);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                catch (DbUpdateException)
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            return(View(hotelgrouptoupdate));
        }