示例#1
0
        public MealType UpdateMealType(MealType mealType)
        {
            var mealTypes = GetMealTypes();

            if (mealType.Id != Guid.Empty)
            {
                var toUpdate = mealTypes.FirstOrDefault(i => i.Id == mealType.Id);
                if (toUpdate != null)
                {
                    int index = mealTypes.IndexOf(toUpdate);
                    mealTypes[index] = mealType;
                }

                SaveMealTypes(mealTypes);
                return(mealType);
            }

            // mealType.Id == Guid.Empty

            var newMealType = new MealType(Guid.NewGuid());

            newMealType.CopyPropertiesFrom(mealType);
            mealTypes.Add(newMealType);

            SaveMealTypes(mealTypes);
            return(newMealType);
        }