public async Task <IViewComponentResult> InvokeAsync(int id) { HotelRoomImagesViewModel model = null; List <HotelRoomImagesViewModel> list = new List <HotelRoomImagesViewModel>(); if (id == 0) { } var hotelimages = _context.roomsImages.Where(p => p.HotelRoom.HotelRoomId == id) .ToList(); if (hotelimages == null) { } foreach (var image in hotelimages) { model = new HotelRoomImagesViewModel() { HotelRoomimage = image.images }; list.Add(model); } return(View(list)); }
public IActionResult _UploadImage(int id) { if (id == 0) { } var model = new HotelRoomImagesViewModel() { HotelRoomId = id }; return(PartialView(model)); }
public IActionResult _UploadImage(HotelRoomImagesViewModel model) { if (!ModelState.IsValid) { } var roomimage = new RoomsImage(); using (var memoryStream = new MemoryStream()) { model.hotelRoomimage.CopyToAsync(memoryStream); roomimage.images = memoryStream.ToArray(); } roomimage.HotelRoom = _context.hotelRooms.FirstOrDefault(p => p.HotelRoomId == model.HotelRoomId); _context.Add(roomimage); _context.SaveChanges(); return(RedirectToAction("Index", new { area = "Manager", controller = "HotelRoomProfile", id = model.HotelRoomId })); }