public async Task <ActionResult> Index() { var rooms = (await _repository.GetAllAsync()).OrderBy(r => r.Address).Select(RoomViewModel.FromRoom).ToList(); var getRoomTypeTasks = new List <Task>(); foreach (var room in rooms) { getRoomTypeTasks.Add(_roomTypeRepository .GetByIdAsync(room.RoomTypeId) .ContinueWith(roomType => { room.RoomType = roomType.Result.Name; })); } await Task.WhenAll(getRoomTypeTasks); return(View(rooms)); }
public async Task GetByIdAsyncTest() { var roomType = _repository.GetAll().FirstOrDefault(); Assert.NotNull(roomType); var nRoomType = await _repository.GetByIdAsync(roomType.Id); Assert.NotNull(nRoomType); Assert.Equal(roomType.Id, nRoomType.Id); }
public async Task <RoomTypeViewModel> GetRoomTypeByIdAsync(int id) { RoomType model = await _roomTypeRepository.GetByIdAsync(id); return(_mapper.Map <RoomTypeViewModel>(model)); }