Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [FromQuery] int articleId = 0)
        {
            var form = Mapper.Map <ResourceFormModel>(await this.resources.GetByIdAsync(id));

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

            var model = new ResourceFormContainerModel
            {
                Form      = form,
                ArticleId = articleId
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public IActionResult Create(int id)
        {
            var articleExists = this.articles.Exists(id);

            if (!articleExists)
            {
                return(NotFound());
            }

            var model = new ResourceFormContainerModel
            {
                Form      = new ResourceFormModel {
                },
                ArticleId = id
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [FromQuery] int articleId, ResourceFormModel model)
        {
            if (!ModelState.IsValid)
            {
                var returnModel = new ResourceFormContainerModel
                {
                    Form      = model,
                    ArticleId = articleId
                };

                return(View(returnModel));
            }

            var result = await this.resources.EditAsync(id, model.Title, model.Url, model.ResourceType);

            if (!result)
            {
                return(NotFound());
            }

            TempData[TempDataSuccessMessageKey] = $"{model.Title} was edited successfully.";
            return(RedirectToAction(nameof(Details), new { Id = id }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create(int id, ResourceFormModel model)
        {
            if (!ModelState.IsValid)
            {
                var returnModel = new ResourceFormContainerModel
                {
                    ArticleId = id,
                    Form      = model
                };
                return(View(returnModel));
            }

            if (id <= 0)
            {
                return(NotFound());
            }

            var articleExists = this.articles.Exists(id);

            if (!articleExists)
            {
                return(NotFound());
            }

            var newId = await this.resources.CreateAsync(model.Title, model.Url, model.ResourceType);

            if (newId <= 0)
            {
                throw new InvalidOperationException("The resource was not saved in the database.");
            }

            await this.resources.LinkToArticleAsync(newId, id);

            TempData[TempDataSuccessMessageKey] = $"{model.Title} was added to the resources.";
            return(RedirectToAction("Edit", "Articles", new { Area = WebConstants.AdminArea, Id = id }));
        }