public async Task BookLocker(int lockerId) { var locker = await DbContext.Whlockers.Include(l => l.Whcells).FirstOrDefaultAsync(i => i.Id == lockerId); if (locker == null) { throw new Exception("No entity found"); } var bookStatus = new StatusStrings { Value = "Booked", Key = locker.Id, Object = nameof(Whlockers) }; DbContext.Add(bookStatus); await DbContext.SaveChangesAsync(); }
public async Task BookZone(int zoneId, int amount) { var zone = await DbContext.Whzones.Include(z => z.Whlockers).ThenInclude(l => l.Whcells).FirstOrDefaultAsync(i => i.Id == zoneId); if (zone == null) { throw new Exception("No entity found"); } if (zone.Whlockers.SelectMany(l => l.Whcells).Where(c => c.ItemId == null).Count() < amount) { throw new Exception("Zone does not have enough free space"); } var bookStatus = new StatusStrings { Value = "Booked", Key = zone.Id, Object = nameof(Whzones) }; DbContext.Add(bookStatus); await DbContext.SaveChangesAsync(); }