예제 #1
0
        public async Task <IActionResult> Edit(int id, ArticleFormModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Resources = await this.GetResourceListItems();

                model.Tags = await this.GetTagsListItems();

                var returnModel = new ArticleContainerModel
                {
                    ArticleFormModel = model,
                    Resources        = await this.resources.GetForArticleAsync(id),
                    Tags             = await this.tags.GetForArticleAsync(id)
                };

                return(View(returnModel));
            }

            var result = await this.articles.Edit(id, model.Title, model.Description, model.Subject, model.Contents);

            if (result == false)
            {
                return(NotFound());
            }

            await this.LinkResources(id, model.ResourceIds);

            await this.LinkTags(id, model.TagIds);

            await this.LinkNewTags(id, model.NewTags);

            TempData[TempDataSuccessMessageKey] = $"'{model.Title}' was edited successfully.";
            return(RedirectToAction(nameof(Index)));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id)
        {
            var articleForm = Mapper.Map <ArticleFormModel>(await this.articles.GetById(id));

            if (articleForm == null)
            {
                return(NotFound());
            }

            articleForm.Resources = await this.GetResourceListItems();

            articleForm.Tags = await this.GetTagsListItems();

            var model = new ArticleContainerModel
            {
                ArticleFormModel = articleForm,
                Resources        = await this.resources.GetForArticleAsync(id),
                Tags             = await this.tags.GetForArticleAsync(id)
            };

            return(View(model));
        }