public async Task <IActionResult> Create(SuccessStorie successStorie) { if (!ModelState.IsValid) { return(View()); } if (ModelState["Photo"].ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid) { return(View()); } if (!successStorie.Photo.IsImage()) { ModelState.AddModelError("Photo", "Shekilin olchusu max 1mg ola biler"); return(View()); } if (successStorie.Photo.MaxLength(1000)) { ModelState.AddModelError("Photo", "Shekilin olchusu max 1mg ola biler"); return(View()); } string path = Path.Combine("images", "testi"); string fileName = await successStorie.Photo.SaveImg(_env.WebRootPath, path); SuccessStorie newSuccesStorie = new SuccessStorie { Desc = successStorie.Desc, FullName = successStorie.FullName, Postion = successStorie.Postion }; newSuccesStorie.Image = fileName; await _context.SuccessStories.AddAsync(newSuccesStorie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Update(SuccessStorie successStorie) { //if (!ModelState.IsValid) return NotFound(); SuccessStorie dbSuccessStorie = _context.SuccessStories.FirstOrDefault(x => x.Id == successStorie.Id); if (dbSuccessStorie == null) { return(NotFound()); } dbSuccessStorie.Desc = successStorie.Desc; dbSuccessStorie.FullName = successStorie.FullName; dbSuccessStorie.Postion = successStorie.Postion; if (successStorie.Photo != null) { IFormFileExtension.DeletePath(_env.WebRootPath, "images/testi", dbSuccessStorie.Image); dbSuccessStorie.Image = await successStorie.Photo.SaveImg(_env.WebRootPath, "images/testi"); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }