Skip to content

Instantly share code, notes, and snippets.

@pkellner
Created December 7, 2019 05:13
Show Gist options
  • Save pkellner/b05f7817adfc3fed9338e89ad0262c90 to your computer and use it in GitHub Desktop.
Save pkellner/b05f7817adfc3fed9338e89ad0262c90 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EFLibSvcc.Models;
using Microsoft.EntityFrameworkCore;
namespace CarvedRock.Api.Repositories
{
public class RoomRepository
{
private readonly svcodecampContext _dbContext;
public RoomRepository(svcodecampContext dbContext)
{
_dbContext = dbContext;
}
public async Task<IEnumerable<LectureRooms>> GetAll()
{
return await _dbContext.LectureRooms.ToListAsync();
}
public async Task<IEnumerable<LectureRooms>> GetByCodeCampYear(string year)
{
var LectureRoomsIds = await (from session in _dbContext.Sessions
join ccy in _dbContext.CodeCampYear on session.CodeCampYearId equals ccy.Id
where ccy.UrlPostToken == year
select session.LectureRoomsId).Distinct().ToListAsync();
return await (from room in _dbContext.LectureRooms
orderby room.Number.ToLower()
where LectureRoomsIds.Contains(room.Id)
select room)
.ToListAsync();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment