コード例 #1
0
        public async Task <int> CreateAsync(
            string name,
            string instructionForPreparation,
            string imageUrl,
            bool vegan,
            bool vegetarian,
            PartOfMeal partOfMeal,
            GlycemicIndex glycemicIndex,
            int calories)
        {
            var recipe = new Recipe
            {
                Name = name,
                InstructionForPreparation = instructionForPreparation,
                ImageUrl      = imageUrl,
                Vegan         = vegan,
                Vegetarian    = vegetarian,
                PartOfMeal    = partOfMeal,
                GlycemicIndex = glycemicIndex,
                Calories      = calories,
            };

            await this.recipesRepository.AddAsync(recipe);

            await this.recipesRepository.SaveChangesAsync();

            return(recipe.Id);
        }
コード例 #2
0
        public async Task <int> ModifyAsync(
            int id,
            string name,
            string instructionForPreparation,
            string imageUrl,
            bool vegan,
            bool vegetarian,
            PartOfMeal partOfMeal,
            GlycemicIndex glycemicIndex,
            int calories)
        {
            var recipe = await this.recipesRepository
                         .All()
                         .Where(r => r.Id == id)
                         .FirstOrDefaultAsync();

            recipe.Name = name;
            recipe.InstructionForPreparation = instructionForPreparation;
            recipe.ImageUrl      = imageUrl;
            recipe.Vegan         = vegan;
            recipe.Vegetarian    = vegetarian;
            recipe.PartOfMeal    = partOfMeal;
            recipe.GlycemicIndex = glycemicIndex;
            recipe.Calories      = calories;

            this.recipesRepository.Update(recipe);
            await this.recipesRepository.SaveChangesAsync();

            return(recipe.Id);
        }