예제 #1
0
        public async Task <IActionResult> AddAmenity(Guid roomId, string amenityType)
        {
            var room = await _context.Rooms
                       .Include(r => r.Amenities)
                       .FirstOrDefaultAsync(r => r.Id == roomId);

            if (room == null)
            {
                return(NotFound());
            }

            List <string> amenityTypes = AmenityTools.AmenitiesForRoom(room.RoomType.ToString());

            if (amenityTypes.Contains(amenityType))
            {
                room.Amenities.Add(new Amenity {
                    AmenityType = (AmenityTypes)Enum.Parse(typeof(AmenityTypes), amenityType, true)
                });
                _context.Update(room);
                await _context.SaveChangesAsync();
            }
            else
            {
                TempData["AlertType"] = "warning";
                TempData["AlertMsg"]  = "Equipement non valide !";
            }

            return(RedirectToAction("ManageAmenities", new { roomId }));
        }
예제 #2
0
        public async Task <IActionResult> ManageAmenities(Guid?roomId)
        {
            if (roomId == null)
            {
                return(NotFound());
            }

            var room = await _context.Rooms
                       .Include(r => r.Amenities)
                       .FirstOrDefaultAsync(r => r.Id == roomId);

            if (room == null)
            {
                return(NotFound());
            }

            if (TempData["AlertType"] != null && TempData["AlertMsg"] != null)
            {
                ViewBag.AlertType = TempData["AlertType"];
                ViewBag.AlertMsg  = TempData["AlertMsg"];
            }

            string roomType = room.RoomType.ToString();

            ViewBag.AmenityTypes = AmenityTools.AmenitiesForRoom(roomType);

            return(View(room));
        }