public async Task <IActionResult> Create([Bind("Id,ImagePath,ImageTitle,AboutTourText,AboutTourNumber")] BronBilgeh bronBilgeh, IFormFile ImagePath) { CustomDateTimeFile customDateTimeFile = new CustomDateTimeFile(); string fileName = customDateTimeFile.GetFileName(ImagePath.FileName); if (ModelState.IsValid) { bronBilgeh.ImagePath = fileName; if (_IsAcceptedFormat(ImagePath.ContentType)) { string path = Path.Combine(hostingEnvironment.WebRootPath, "images", fileName); byte[] data = new byte[ImagePath.Length]; using (FileStream fileStream = new FileStream(path, FileMode.Create)) { await ImagePath.CopyToAsync(fileStream); } } await _context.AddAsync(bronBilgeh); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bronBilgeh)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ImagePath,ImageTitle,AboutTourText,AboutTourNumber")] BronBilgeh bronBilgeh) { if (id != bronBilgeh.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(bronBilgeh); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BronBilgehExists(bronBilgeh.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(bronBilgeh)); }