public async Task <IActionResult> Update(string id) { var categories = await _catalogService.GetAllCategoryAsync(); var course = await _catalogService.GetCourseByCourseId(id); if (course == null) { return(RedirectToAction(nameof(Index))); } ViewBag.categoryList = new SelectList(categories, "Id", "Name", course.Id); CourseUpdateInput courseUpdateInput = new CourseUpdateInput() { Id = course.Id, Name = course.Name, Description = course.Description, Price = course.Price, Feature = course.Feature, CategoryId = course.CategoryId, UserId = course.UserId, Picture = course.Picture }; return(View(courseUpdateInput)); }
public async Task <IActionResult> Update(CourseUpdateInput courseUpdateInput) { var categories = await _catalogService.GetAllCategoryAsync(); ViewBag.categoryList = new SelectList(categories, "Id", "Name", courseUpdateInput.Id); if (!ModelState.IsValid) { return(View()); } await _catalogService.UpdateCourseAsync(courseUpdateInput); return(RedirectToAction(nameof(Index))); }
public async Task <bool> UpdateCourseAsync(CourseUpdateInput courseUpdateInput) { var resultPhotoService = await _photoStockService.UplaodPhoto(courseUpdateInput.PhotoFormFile); if (resultPhotoService != null) { await _photoStockService.DeletePhoto(courseUpdateInput.Picture); courseUpdateInput.Picture = resultPhotoService.Url; } var response = await _httpClient.PutAsJsonAsync <CourseUpdateInput>("courses", courseUpdateInput); return(response.IsSuccessStatusCode); }