Пример #1
0
        public async Task UpdateWebSource()
        {
            await InitializeAsync();

            using (var service = this.GetService())
            {
                var recipe = await DbContext.Recipes.AsNoTracking().Include(x => x.Source).ThenInclude(x => x.Source).FirstAsync(x => x.Source.Source is RecipeCookbookSource);

                var source = await DbContext.RecipeUrlSources.FirstAsync();

                var sourceModel = new WebSourceViewModel()
                {
                    Id        = source.Id,
                    Name      = source.Name + "1",
                    SourceUrl = source.Url
                };

                await service.UpdateWebSourceAsync(recipe.Id, source.Id, sourceModel);

                var recipeAfterChange = await DbContext.Recipes.AsNoTracking().Include(x => x.Source).ThenInclude(x => x.Source).SingleAsync(x => x.Id.Equals(recipe.Id));

                Assert.True(recipeAfterChange.Source.Source is RecipeUrlSource);
                Assert.Equal(sourceModel.Name, recipeAfterChange.Source.Source.Name);
            }
        }
Пример #2
0
        public async Task UpdateWebSourceAsync(int recipeId, int sourceId, WebSourceViewModel source)
        {
            await this._webSourceAdapter.UpdateAsync(sourceId, source);

            var dbsource = await this._rep.WebSources.FindAsync(sourceId, x => x.RecipeSourceRecipes);

            var recipe = await this._recipeRep.FindAsync(recipeId, x => x.Source);

            if (recipe == null)
            {
                throw new DataObjectNotFoundException($"No Recipe with id '{recipeId}' found");
            }
            recipe.Source = new RecipeSourceRecipe()
            {
                RecipeId = recipeId, SourceId = dbsource.Id
            };
            await this._recipeRep.SaveChangesAsync();
        }
Пример #3
0
        public void Convert_WebSourceViewModel_To_RecipeUrlSource()
        {
            Initalize();

            var input = new WebSourceViewModel()
            {
                Id        = 1,
                Name      = "TestDomain",
                SourceUrl = "http://www.test.de/source"
            };

            var output = Mapper.Map <RecipeUrlSource>(input);

            Assert.IsType <RecipeUrlSource>(output);
            Assert.Equal(input.Name, output.Name);
            Assert.Equal(input.SourceUrl, output.Url);
            Assert.Equal(input.Id, output.Id);

            Assert.NotNull(output.RecipeSourceRecipes);
            Assert.Empty(output.RecipeSourceRecipes);
        }
Пример #4
0
        public async Task <WebSourceViewModel> AddWebSourceAsync(int recipeId, WebSourceCreationViewModel source)
        {
            WebSourceViewModel result = null;

            try
            {
                if (source == null)
                {
                    throw new ArgumentNullException(nameof(source));
                }
                result = await this._webSourceAdapter.AddAsync(new WebSourceCreationViewModel()
                {
                    Name = source.Name, SourceUrl = source.SourceUrl
                });

                var dbsource = await this._rep.WebSources.FindAsync(result.Id, x => x.RecipeSourceRecipes);

                var recipe = await this._recipeRep.FindAsync(recipeId, x => x.Source);

                if (recipe == null)
                {
                    throw new DataObjectNotFoundException($"No Recipe with id '{recipeId}' found");
                }
                recipe.Source = new RecipeSourceRecipe()
                {
                    RecipeId = recipeId, SourceId = dbsource.Id
                };
                await this._recipeRep.SaveChangesAsync();
            }
            catch (Exception e)
            {
                var message = "An error on creating a web source";
                _log.LogError(new EventId(), e, message);
                throw new Exception(message);
            }
            return(result);
        }
Пример #5
0
        public async Task <IActionResult> UpdateWebSourceAsync(int recipeId, int sourceId, [FromBody] WebSourceViewModel model)
        {
            await _service.UpdateWebSourceAsync(recipeId, sourceId, model);

            return(NoContent());
        }
Пример #6
0
 /// <summary>
 /// Updates an existing web source of a recipe
 /// </summary>
 /// <param name="recipeId"></param>
 /// <param name="sourceId"></param>
 /// <param name="model"></param>
 /// <returns></returns>
 public async Task UpdateWebSourceForRecipeAsync(int recipeId, int sourceId, WebSourceViewModel model)
 {
     await this.Client.PutAsJsonAsync(model, $"Recipes/{recipeId}/WebSource/{sourceId}");
 }