Пример #1
0
        public async Task <TEntity> Add(TEntity entity)
        {
            await _context.Set <TEntity>().AddAsync(entity);

            await _context.SaveChangesAsync();

            return(entity);
        }
Пример #2
0
        public async Task AddUser(string username, string password, string email)
        {
            await cookbookDbContext.Users.AddAsync(new User()
            {
                Username = username, Password = password, EmailAddress = email
            });

            await cookbookDbContext.SaveChangesAsync();
        }
Пример #3
0
        public async Task AddRecipe(string name, string description, string imagePath)
        {
            var recipe = new Recipe()
            {
                Name = name, Description = description, ImagePath = imagePath
            };

            cookbookDbContext.Recipes.Add(recipe);
            await cookbookDbContext.SaveChangesAsync();
        }
Пример #4
0
        public async Task Seed()
        {
            if (await _context.Database.CanConnectAsync())
            {
                var pendingMigrations = await _context.Database.GetPendingMigrationsAsync();

                if (pendingMigrations != null && pendingMigrations.Any())
                {
                    await _context.Database.MigrateAsync();
                }

                if (!await _context.Categories.AnyAsync())
                {
                    var categories = await GetCategories();

                    await _context.Categories.AddRangeAsync(categories);

                    await _context.SaveChangesAsync();
                }

                if (!await _context.Areas.AnyAsync())
                {
                    var areas = await GetAreas();

                    await _context.Areas.AddRangeAsync(areas);

                    await _context.SaveChangesAsync();
                }

                if (!await _context.Ingredients.AnyAsync())
                {
                    var ingredients = await GetIngredients();

                    await _context.Ingredients.AddRangeAsync(ingredients);

                    await _context.SaveChangesAsync();
                }

                if (!await _context.Recipes.AnyAsync())
                {
                    var recipes = await GetRecipes();

                    await _context.Recipes.AddRangeAsync(recipes);

                    await _context.SaveChangesAsync();
                }
            }
        }
Пример #5
0
        public async Task InsertRecipe(string userId, Core.Models.Recipe recipe)
        {
            var recipeEntity = new Recipe
            {
                UserId = userId,
                Name   = recipe.Name
            };

            _db.Recipes.Add(recipeEntity);
            await _db.SaveChangesAsync();

            var ingredients = new List <RecipeIngredient>();

            recipe.Ingredients.ForEach(ingredient =>
                                       ingredients.Add(new RecipeIngredient
            {
                IngredientId = ingredient,
                RecipeId     = recipeEntity.Id
            })
                                       );
            _db.RecipeIngredients.AddRange(ingredients);
            await _db.SaveChangesAsync();
        }
Пример #6
0
 public override async Task SaveChangeAsync()
 {
     await _dbContext.SaveChangesAsync();
 }