public async Task <Auditorium> GetById(string housingId, string auditoriumId) { var filter = Builders <Housing> .Filter.Eq("Id", housingId); var housing = await Housings.Find(filter).FirstOrDefaultAsync(); return(housing?.Auditoriums?.FirstOrDefault(a => string.Equals(a.Id, auditoriumId))); }
public async Task <bool> IsHousingExists(int number) { var filter = Builders <Housing> .Filter.Eq("Number", number); return(await Housings .Find(filter) .FirstOrDefaultAsync() != null); }
public async Task <Housing> GetById(string id) { var filter = Builders <Housing> .Filter.Eq("Id", id); return(await Housings .Find(filter) .FirstOrDefaultAsync()); }
public async Task RemoveAsync(Auditorium auditorium) { var filter = Builders <Housing> .Filter.Eq("Id", auditorium.HousingId); var housing = await Housings.Find(filter).FirstAsync(); housing.Auditoriums.Remove(housing.Auditoriums.FirstOrDefault(a => string.Equals(a.Id, auditorium.Id))); await Housings.ReplaceOneAsync(h => string.Equals(h.Id, housing.Id), housing); }
public async Task <bool> IsAuditoriumExists(string housingId, int number, string exceptAuditoriumId) { var filter = Builders <Housing> .Filter.ElemMatch( f => f.Auditoriums, f => string.Equals(f.HousingId, housingId) && !string.Equals(f.Id, exceptAuditoriumId) && f.Number == number); return((await Housings .Find(filter) .FirstOrDefaultAsync()) != null); }
public async Task <IEnumerable <Auditorium> > GetAllAsync(string housingId) { var filter = Builders <Housing> .Filter.Eq("Id", housingId); var housing = await Housings.Find(filter).FirstOrDefaultAsync(); if (housing != null) { return(housing.Auditoriums?.ToList() ?? new List <Auditorium>()); } return(null); }
public async Task <Auditorium> AddAsync(Auditorium auditorium) { var filter = Builders <Housing> .Filter.Eq("Id", auditorium.HousingId); var housing = await Housings.Find(filter).FirstAsync(); if (housing == null) { return(null); } if (housing.Auditoriums == null) { housing.Auditoriums = new List <Auditorium>(); } auditorium.Id = ObjectId.GenerateNewId().ToString(); housing.Auditoriums.Add(auditorium); await Housings.ReplaceOneAsync(h => string.Equals(h.Id, housing.Id), housing); return(auditorium); }
public async Task <IEnumerable <Housing> > GetAllAsync() { return(await Housings.Find(_ => true).ToListAsync()); }