public async Task <IActionResult> Edit(string id, NewsEditBindingModel newsEditBindingModel) { if (!this.ModelState.IsValid) { var allNewsCategories = await this.newsService.GetAllNewsCategory().ToListAsync(); this.ViewData["categories"] = allNewsCategories .Select(newsCategories => new NewsCreateNewsCategoryViewModel { Name = newsCategories.Name, }) .ToList(); return(this.View(newsEditBindingModel)); } string pictureUrl = await this.cloudinaryService .UploadPictureAync(newsEditBindingModel.Picture, newsEditBindingModel.Title); NewsServiceModel newsServiceModel = newsEditBindingModel.To <NewsServiceModel>(); newsServiceModel.Picture = pictureUrl; await this.newsService.Edit(id, newsServiceModel); return(this.Redirect($"/News/Details/{id}")); }
public async Task <IActionResult> Edit(string id) { NewsEditBindingModel newsEditBindingModel = (await this.newsService.GetById(id)).To <NewsEditBindingModel>(); if (newsEditBindingModel == null) { //TODO: Error Handling return(this.Redirect("/")); } var allNewsCategories = await this.newsService.GetAllNewsCategory().ToListAsync(); this.ViewData["categories"] = allNewsCategories .Select(newsCategories => new NewsCreateNewsCategoryViewModel { Name = newsCategories.Name, }) .ToList(); return(this.View(newsEditBindingModel)); }