public UserProfile UpdateFoods(List <long> foodIds) { if (!foodIds.IsNullOrZero()) { if (Foods.IsNullOrZero()) { Foods = new List <UserFood>(); } Foods.RemoveAll(p => !foodIds.Contains(p.Id)); var _foods = Foods; foodIds.ForEach(item => { try { var result = _foods.Where(p => p.Id == item).FirstOrDefault(); if (result.IsNull()) { Foods.Add(new UserFood().Create(item, Id)); } } catch (Exception e) { throw e; } }); } else { Foods.Clear(); } return(this); }