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)); }
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)); }
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 })); }
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 })); }