public async Task <IActionResult> DeletePost(int?id) { if (id == null) { return(NotFound()); } Product product = await _remindb.Products.FirstOrDefaultAsync(p => p.Id == id); if (product == null) { return(NotFound()); } var image = _remindb.Images.Where(x => x.ProductId == id); foreach (var item in image) { DeleteImage.DeleteFromFolder(_env.WebRootPath, item.PathImage); _remindb.Images.Remove(item); } _remindb.Products.Remove(product); await _remindb.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Update(int?id, Team upteanm) { if (id == null) { return(NotFound()); } Team teamdb = await _remindb.Teams.FirstOrDefaultAsync(x => x.Id == id); if (teamdb == null) { return(NotFound()); } if (ModelState["Name"].ValidationState == ModelValidationState.Invalid || ModelState["Job"].ValidationState == ModelValidationState.Invalid || ModelState["About"].ValidationState == ModelValidationState.Invalid) { return(RedirectToAction(nameof(Index))); } if (upteanm.ChangePhoto != null) { if (!upteanm.ChangePhoto.IsImage()) { ModelState.AddModelError("ChangePhoto", "You can chose only image format"); return(View()); } if (!upteanm.ChangePhoto.CheckSize(2)) { ModelState.AddModelError("ChangePhoto", "You can chose only small 2 MB"); return(View()); } string updateimage = await upteanm.ChangePhoto.CopyImage(_env.WebRootPath, "team"); upteanm.ImagePath = updateimage; DeleteImage.DeleteFromFolder(_env.WebRootPath, teamdb.ImagePath); } teamdb.Name = upteanm.Name; teamdb.Job = upteanm.Job; teamdb.About = upteanm.About; teamdb.ImagePath = upteanm.ImagePath; await _remindb.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Update(int?id, Blog updateblog) { if (id == null) { return(NotFound()); } Blog _dbblog = await _remindb.Blogs.FirstOrDefaultAsync(x => x.Id == id); if (_dbblog == null) { return(NotFound()); } if (ModelState["Title"].ValidationState == ModelValidationState.Invalid || ModelState["Photo"].ValidationState == ModelValidationState.Invalid) { return(RedirectToAction(nameof(Index))); } if (updateblog.ChangePhoto != null) { if (!updateblog.ChangePhoto.IsImage()) { ModelState.AddModelError("ChangePhoto", "You can chose only image format"); return(View()); } if (!updateblog.ChangePhoto.CheckSize(2)) { ModelState.AddModelError("ChangePhoto", "You can chose only small 2 MB"); return(View()); } string updateimage = await updateblog.ChangePhoto.CopyImage(_env.WebRootPath, "blog"); updateblog.ImagePath = updateimage; DeleteImage.DeleteFromFolder(_env.WebRootPath, _dbblog.ImagePath); } _dbblog.Title = updateblog.Title; _dbblog.Link = updateblog.Link; _dbblog.HeaderBig = updateblog.HeaderBig; _dbblog.HeaderSmall = updateblog.HeaderSmall; _dbblog.ImagePath = updateblog.ImagePath; await _remindb.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Update(int?id, HomeSliderBig homeSlider) { if (id == null) { return(NotFound()); } HomeSliderBig _dbslider = await _remindb.HomeSliderBigs.FirstOrDefaultAsync(x => x.Id == id); if (_dbslider == null) { return(NotFound()); } if (ModelState["Title"].ValidationState == ModelValidationState.Invalid || ModelState["SubTitle"].ValidationState == ModelValidationState.Invalid || ModelState["Link"].ValidationState == ModelValidationState.Invalid) { return(RedirectToAction(nameof(Index))); } if (homeSlider.ChangePhoto != null) { if (!homeSlider.ChangePhoto.IsImage()) { ModelState.AddModelError("ChangePhoto", "You can chose only image format"); return(View()); } if (!homeSlider.ChangePhoto.CheckSize(2)) { ModelState.AddModelError("ChangePhoto", "You can chose only small 2 MB"); return(View()); } string updateimage = await homeSlider.ChangePhoto.CopyImage(_env.WebRootPath, "homefirst"); homeSlider.ImgPath = updateimage; DeleteImage.DeleteFromFolder(_env.WebRootPath, _dbslider.ImgPath); } _dbslider.Title = homeSlider.Title; _dbslider.SubTitle = homeSlider.SubTitle; _dbslider.Link = homeSlider.Link; _dbslider.ImgPath = homeSlider.ImgPath; await _remindb.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> DelImage(int id) { Image delete = await _remindb.Images.FirstOrDefaultAsync(x => x.Id == id); if (delete == null) { return(NotFound()); } DeleteImage.DeleteFromFolder(_env.WebRootPath, delete.PathImage); _remindb.Images.Remove(delete); await _remindb.SaveChangesAsync(); return(Json(id)); }
public async Task <IActionResult> Update(int?id, AboutSlider upslider) { if (id == null) { return(NotFound()); } AboutSlider _sliderdb = await _remindb.AboutSliders.FirstOrDefaultAsync(x => x.Id == id); if (upslider == null) { return(NotFound()); } if (upslider.ChangePhoto != null) { if (!upslider.ChangePhoto.IsImage()) { ModelState.AddModelError("ChangePhoto", "You can chose only image format"); return(View()); } if (!upslider.ChangePhoto.CheckSize(2)) { ModelState.AddModelError("ChangePhoto", "You can chose only small 2 MB"); return(View()); } string updateimage = await upslider.ChangePhoto.CopyImage(_env.WebRootPath, "team"); upslider.ImagePath = updateimage; DeleteImage.DeleteFromFolder(_env.WebRootPath, _sliderdb.ImagePath); } _sliderdb.ImagePath = upslider.ImagePath; await _remindb.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }