コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("AmenityID,RoomID")] RoomAmenity roomAmenity)
        {
            if (id != roomAmenity.AmenityID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(roomAmenity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoomAmenityExists(roomAmenity.AmenityID, roomAmenity.RoomID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AmenityID"] = new SelectList(_context.Amenities, "ID", "Name", roomAmenity.AmenityID);
            ViewData["RoomID"]    = new SelectList(_context.Rooms, "ID", "Name", roomAmenity.RoomID);
            return(View(roomAmenity));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] Amenity amenity)
        {
            if (id != amenity.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(amenity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AmenityExists(amenity.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(amenity));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,PhoneNumber,Email,IsAdult")] Client client)
        {
            if (id != client.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(client);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientExists(client.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,HotelName,Address,City,State,Zip")] Hotel hotel)
        {
            if (id != hotel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(hotel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HotelExists(hotel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(hotel));
        }
コード例 #5
0
ファイル: RoomsController.cs プロジェクト: Bewtan/WebProject
        public async Task <IActionResult> Edit(int id, [Bind("Id,Capacity,Type,PriceForAdult,PriceForKid,Number")] Room room)
        {
            if (id != room.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(room);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RoomExists(room.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(room));
        }
コード例 #6
0
        public async Task <IActionResult> Edit(int hotelID, int roomID, [Bind("HotelID,RoomID,RoomNumber,Rate,PetFriendly")] HotelRoom hotelRoom)
        {
            if (hotelID != hotelRoom.HotelID || roomID == hotelRoom.RoomID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(hotelRoom);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HotelRoomExists(hotelRoom.HotelID, hotelRoom.RoomID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HotelID"] = new SelectList(_context.Hotels, "ID", "Name", hotelRoom.HotelID);
            ViewData["RoomID"]  = new SelectList(_context.Rooms, "ID", "Name", hotelRoom.RoomID);
            return(View(hotelRoom));
        }
コード例 #7
0
 public Hotel UpdateHotel(Hotel hotel)
 {
     using (var context = new HotelDbContext())
     {
         context.Update(hotel);
         return(hotel);
     }
 }
コード例 #8
0
        public async Task UpdateHotelInfo(HotelModel hotelInfo)
        {
            var hotel = await _dataContext.Hotels.FirstOrDefaultAsync(h => h.HotelId == hotelInfo.HotelId);

            if (hotel == null)
            {
                throw new ArgumentException();
            }

            await UpdateLocation(hotel.LocationId, hotelInfo.Location);

            hotel.Name     = hotelInfo.Name;
            hotel.Stars    = hotelInfo.Stars;
            hotel.Services = await GetUpdatedServices(hotelInfo.HotelId, hotelInfo.Services);

            hotel.Images = GetUpdatedHotelImages(hotelInfo.HotelId, hotelInfo.ImageIds);
            _dataContext.Update(hotel);
            await _dataContext.SaveChangesAsync();
        }
コード例 #9
0
        public async Task <PaymentDomain> UpdateAsync(PaymentUpdateModel model)
        {
            var existing = await Get(model);

            Context.Entry(existing).State = EntityState.Modified;
            var result = Mapper.Map(model, existing);

            Context.Update(result);
            await Context.SaveChangesAsync();

            return(Mapper.Map <PaymentDomain>(result));
        }
コード例 #10
0
        public async Task <TEntity> UpdateAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null");
            }

            try
            {
                _context.Update(entity);
                await _context.SaveChangesAsync();

                return(entity);
            }
            catch (Exception ex)
            {
                throw new Exception($"{nameof(entity)} could not be updated: {ex.Message}");
            }
        }
コード例 #11
0
ファイル: Repository.cs プロジェクト: observer36/HotelApp_MVC
 public virtual void Update(TEntity item)
 {
     context.Update <TEntity>(item);
 }
コード例 #12
0
ファイル: AmenitiesService.cs プロジェクト: trecain/Async-Inn
 /// <summary>
 /// updates the amenity
 /// </summary>
 /// <param name="amenities">amenity that needs to be updated</param>
 /// <returns></returns>
 public async Task UpdateAmenity(Amenity amenities)
 {
     _context.Update(amenities);
     await _context.SaveChangesAsync();
 }
コード例 #13
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,RoomId,ClientsIDs,DateOfArrival,DateOfLeaving,IsBreakfastIncluded,IsAllInclusive")] Reservation reservation)
        {
            if (id != reservation.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var current_User = _userManager.GetUserAsync(HttpContext.User).Result;
                    reservation.UserId = current_User.Id;
                    List <int> ids = reservation.ClientsIDs.ToList <int>();
                    _context.Update(reservation);
                    _context.SaveChanges();
                    reservation = _context.Reservations.Include(r => r.Clients).First(i => i.Id == reservation.Id);
                    reservation.Clients.Clear();
                    _context.SaveChanges(); //pain
                    foreach (var ID in ids)
                    {
                        reservation.Clients.Add(_context.Clients.Find(ID));
                    }

                    reservation.Cost = CalculateCost(reservation);
                    _context.Update(reservation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReservationExists(reservation.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["Room"] = new List <SelectListItem>();
            foreach (var room in _context.Rooms)
            {
                ViewBag.Room.Add(new SelectListItem {
                    Text = room.Number.ToString(), Value = room.Id.ToString()
                });
            }
            ViewData["User"] = new List <SelectListItem>();
            foreach (var user in _context.Users)
            {
                ViewBag.User.Add(new SelectListItem {
                    Text = user.UserName, Value = user.Id
                });
            }
            ViewData["Client"] = new List <SelectListItem>();
            foreach (var client in _context.Clients)
            {
                ViewBag.Client.Add(new SelectListItem {
                    Text = client.FirstName + client.LastName, Value = client.Id.ToString()
                });
            }
            return(View(reservation));
        }