public async Task <IActionResult> Create(Rservation_Content rservationcontent) { if (ModelState["Title"].ValidationState == ModelValidationState.Invalid || ModelState["Description"].ValidationState == ModelValidationState.Invalid || ModelState["Photo"].ValidationState == ModelValidationState.Invalid) { return(View()); } if (!rservationcontent.Photo.IsImage()) { ModelState.AddModelError("Photo", "Shekil novunu duz secin"); return(View()); } if (!rservationcontent.Photo.CheckImageSize(2)) { ModelState.AddModelError("Photo", "Shekil hecmi coxdur"); return(View()); } string filename = await rservationcontent.Photo.CopyImage(_env.WebRootPath, "slider"); rservationcontent.Image = filename; await _context.Rservation_Contents.AddAsync(rservationcontent); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Update(int?id) { if (id == null) { return(NotFound()); } Rservation_Content rservationcontent = await _context.Rservation_Contents.FindAsync(id); if (rservationcontent == null) { return(NotFound()); } return(View(rservationcontent)); }
public async Task <IActionResult> DeletePost(int?id) { Rservation_Content rservationcontent = await _context.Rservation_Contents.FindAsync(id); if (rservationcontent == null) { return(RedirectToAction(nameof(Index))); } Utility.DeleteImgFromFolder(_env.WebRootPath, rservationcontent.Image); _context.Rservation_Contents.Remove(rservationcontent); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Update(int?id, Rservation_Content rservationcontent) { Rservation_Content rservationcontentDb = await _context.Rservation_Contents.FindAsync(id); if (rservationcontentDb == null) { return(RedirectToAction(nameof(Index))); } if (ModelState["Title"].ValidationState == ModelValidationState.Invalid ) { return(View(rservationcontentDb)); } if (rservationcontent.PhotoUpdate != null) { if (!rservationcontent.PhotoUpdate.IsImage()) { ModelState.AddModelError("Photo", "Content type must be image"); return(View()); } if (!rservationcontent.PhotoUpdate.CheckImageSize(2)) { ModelState.AddModelError("Photo", "Image size not more than 2 Mb"); return(View()); } string filename = await rservationcontent.PhotoUpdate.CopyImage(_env.WebRootPath, "slider"); Utility.DeleteImgFromFolder(_env.WebRootPath, rservationcontentDb.Image); rservationcontentDb.Image = filename; } rservationcontentDb.Title = rservationcontent.Title; rservationcontentDb.Description = rservationcontent.Description; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }