public async Task <IActionResult> Create(PortofolioAddDto portofolioAddDto, IFormFile imgFile, [FromServices] IWebHostEnvironment webHostEnvironment) { if (ModelState.IsValid) { if (imgFile != null) { var imgName = await ImageUploadHelper.ImageUploadAsync(webHostEnvironment, imgFile, "\\img\\portofolio"); portofolioAddDto.ImageUrl = imgName; } else { portofolioAddDto.ImageUrl = "no-image.png"; } await _portofolioService.InsertAsync(new Portofolio { SubCategoryId = portofolioAddDto.SubCategoryId, Text = portofolioAddDto.Text, Title = portofolioAddDto.Title, ImageUrl = portofolioAddDto.ImageUrl }); return(RedirectToAction("Index")); } portofolioAddDto.CategoryList = new SelectList(await _categoryService.GetListAsync(), "Id", "Name"); return(View(portofolioAddDto)); }
public async Task <IActionResult> Create() { TempData["active"] = "portofolio"; PortofolioAddDto portofolioAddDto = new PortofolioAddDto(); portofolioAddDto.CategoryList = new SelectList(await _categoryService.GetListAsync(), "Id", "Name"); return(View(portofolioAddDto)); }