示例#1
0
        public async Task <MealDto> UpdateMeal(int id, MealDto model)
        {
            using (var db = NewDb())
            {
                var meal = await db.Meal.Include(x => x.MealAddOnRela).FirstAsync(x => x.Id == id);

                _mapper.Map <MealDto, Meal>(model, meal);
                db.Meal.Update(meal);
                await db.SaveChangesAsync();

                return(await GetMeal(id));

                //return model;
            }
        }
示例#2
0
        public async Task <MealDto> CreateMeal(MealDto model)
        {
            using (var db = NewDb())
            {
                var meal = _mapper.Map <MealDto, Meal>(model);
                ///方法二
                ///var addOn = model.MealAddOnDtos.Select(x => new MealAddOnRela { AddOnId = x.Id });
                ///meal.MealAddOnRela = addOn.ToList();

                db.Meal.Add(meal);
                await db.SaveChangesAsync();

                return(await GetMeal(meal.Id));

                //retutn model;
            }
        }