コード例 #1
0
        public async Task <Event> Add(Event ev)
        {
            await _dataContext.AddAsync(ev);

            await _dataContext.SaveChangesAsync();

            return(ev);
        }
コード例 #2
0
        public async Task <Recipe> Add(Recipe recipe)
        {
            var newRecipe = new Recipe
            {
                Image       = recipe.Image,
                Servings    = recipe.Servings,
                Time        = recipe.Time,
                Title       = recipe.Title,
                Description = recipe.Description,
                FkUser      = recipe.FkUser
            };
            await _dataContext.AddAsync(newRecipe);

            await _dataContext.SaveChangesAsync();


            foreach (var item in recipe.Products)
            {
                var product = new Product
                {
                    Name     = item.Name,
                    Quantity = item.Quantity,
                    FkRecipe = newRecipe.Id
                };
                await _dataContext.Product.AddAsync(product);
            }
            await _dataContext.SaveChangesAsync();

            return(newRecipe);
        }
コード例 #3
0
        public async Task <Comment> Add(Comment comment)
        {
            await _dataContext.AddAsync(comment);

            await _dataContext.SaveChangesAsync();

            return(comment);
        }