小记
public void UpdateWarhouse(Administrator admin)
{
var warhouseStr = Request["warhouse"];
if (!string.IsNullOrEmpty(warhouseStr))
{ var storageListAll = CacheAccess.GetStorages(_storageContract); int[] selectedId = warhouseStr.Split(',').Select(c => Convert.ToInt32(c)).ToArray();
List<Storage> selectStorages=storageListAll.Where(c=> selectedId.Contains(c.Id)).ToList();
List<Storage> removeStorages = admin.Stoages.Where(c => !selectStorages.Contains(c)).ToList();
List<Storage> newAddStorages = selectStorages.Where(c => !admin.Stoages.Contains(c)).ToList(); foreach (var item in removeStorages)
{
admin.Stoages.Remove(item);
}
foreach(var item in newAddStorages)
{
admin.Stoages.Add(item);
} } }
selectedId 是从画面上取得的选中的值 string 类型 “1,2,3,4”