public IActionResult Update(int?id) { if (id == null) { return(NotFound()); } HomeBio bio = _db.HomeBios.FirstOrDefault(p => p.Id == id); if (bio == null) { return(NotFound()); } return(View(bio)); }
public async Task <IActionResult> Update(int?id, HomeBio homeBio) { if (id == null) { return(NotFound()); } HomeBio dbHomeBio = await _db.HomeBios.FindAsync(id); if (dbHomeBio == null) { return(NotFound()); } if (homeBio.Photo != null) { if (ModelState["Photo"].ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid) { return(View()); } if (!homeBio.Photo.IsImage()) { ModelState.AddModelError("Photo", "Zehmet olmasa shekil formati sechin"); return(View()); } if (homeBio.Photo.MaxLength(2000)) { ModelState.AddModelError("Photo", "Shekilin olchusu max 2mg ola biler"); return(View()); } string path = Path.Combine("img", "logo"); Helper.DeleteImage(_env.WebRootPath, path, dbHomeBio.Logo); string fileName = await homeBio.Photo.SaveImg(_env.WebRootPath, path); dbHomeBio.Logo = fileName; } dbHomeBio.Number = homeBio.Number; dbHomeBio.Facebook = homeBio.Facebook; dbHomeBio.Vcontact = homeBio.Vcontact; dbHomeBio.Twitter = homeBio.Twitter; dbHomeBio.Pinterest = homeBio.Pinterest; await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Update(HomeBio bio) { HomeBio dbHomeBio = _db.HomeBios.FirstOrDefault(p => p.Id == bio.Id); if (dbHomeBio == null) { return(NotFound()); } if (bio.Photo != null) { if (ModelState["Photo"].ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid) { return(View()); } if (!bio.Photo.IsImage()) { ModelState.AddModelError("Photo", "Zehmet olmasa shekil formati sechin"); return(View()); } if (bio.Photo.MaxLength(2000)) { ModelState.AddModelError("Photo", "Shekilin olchusu max 2mg ola biler"); return(View()); } string path = Path.Combine("img", "logo"); Helper.DeleteImage(_env.WebRootPath, path, dbHomeBio.HeaderLogo); string fileName = await bio.Photo.SaveImg(_env.WebRootPath, path); dbHomeBio.HeaderLogo = fileName; } dbHomeBio.Adress = bio.Adress; dbHomeBio.Telephone = bio.Telephone; dbHomeBio.Email = bio.Email; dbHomeBio.WebSite = bio.WebSite; dbHomeBio.Facebook = bio.Facebook; dbHomeBio.Instagram = bio.Instagram; dbHomeBio.Twitter = bio.Twitter; dbHomeBio.Youtube = bio.Youtube; await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public IActionResult Index() { HomeBio bio = _db.HomeBios.FirstOrDefault(); return(View(bio)); }