public async Task <IActionResult> Create([Bind("Id,ImagePath,ImageText,Title,SubTitle,Duration,Code,Price,AboutTourText,AboutTourNumber,TourImage,TourName,TourInformation,TourVideo,TourCheckIn,TourText,TourTime,TourAdditional,TourAdditionalSecond,Number,SecondNumber,Email,SiteAddress,Address")] BilgehPage bilgehPage, IFormFile ImagePath) { CustomDateTimeFile customDateTimeFile = new CustomDateTimeFile(); string fileName = customDateTimeFile.GetFileName(ImagePath.FileName); if (ModelState.IsValid) { bilgehPage.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(bilgehPage); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bilgehPage)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ImagePath,ImageText,Title,SubTitle,Duration,Code,Price,AboutTourText,AboutTourNumber,TourImage,TourName,TourInformation,TourVideo,TourCheckIn,TourText,TourTime,TourAdditional,TourAdditionalSecond,Number,SecondNumber,Email,SiteAddress,Address")] BilgehPage bilgehPage) { if (id != bilgehPage.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(bilgehPage); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BilgehPageExists(bilgehPage.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(bilgehPage)); }