public IEnumerable<Asset> GetAvailableAssets(DateTime date, Time time, IEnumerable<Asset> collection = null)
        {
            IEnumerable<Asset> assets = null;

            if (collection != null)
                assets = collection;
            else
                assets = db.Assets.ToList();

            var assigned_assets = db.AssetAssignments.ToList().Where(t => t.Date == date && t.Times.Any(s => s.Id == time.Id)).Select(t => t.AssignedAssets);

            foreach (var assigned_asset_set in assigned_assets)
            {
                foreach (var assigned_asset in assigned_asset_set)
                {
                    Asset asset = assets.SingleOrDefault(t => t.Id == assigned_asset.AssetId);

                    if (asset != null)
                    {
                        asset.Count -= assigned_asset.Count;
                    }
                }
            }

            assets = assets.Where(t => t.Count > 0);

            return assets;
        }
        public IEnumerable<Location> GetAvailableLocations(DateTime date, Time time, IEnumerable<Location> collection = null)
        {
            string weekday_name = date.DayOfWeek.ToString();
            int weekday_id = GetWeekDayIdByName(weekday_name);

            IEnumerable<Location> locations = null;

            if (collection != null)
                locations = collection;
            else
                locations = db.Locations.ToList();

            // 过滤掉被占用的场地
            var assigned_locations = db.LocationAssignments.ToList().Where(s => s.Date == date && s.Times.Any(t => t.Id == time.Id)).Select(t => t.Locations);
            locations = locations.Where(t => assigned_locations.All(s => s.All(f => f.Id != t.Id)));

            // 过滤掉当天当时间段不可用的场地
            locations = locations.Where(t => t.UnAvailableTimes.All(s => s.WeekDayId != weekday_id || s.TimeId != time.Id));

            return locations;
        }