public async Task <IActionResult> Create([Bind("Id,TourImage,TourIcon,TourName,TourTitle,TourTime,TourAction,TourDuration")] Azerbaijan azerbaijan, IFormFile TourImage) { CustomDateTimeFile customDateTimeFile = new CustomDateTimeFile(); string fileName = customDateTimeFile.GetFileName(TourImage.FileName); if (ModelState.IsValid) { azerbaijan.TourImage = fileName; if (_IsAcceptedFormat(TourImage.ContentType)) { string path = Path.Combine(hostingEnvironment.WebRootPath, "images", fileName); byte[] data = new byte[TourImage.Length]; using (FileStream fileStream = new FileStream(path, FileMode.Create)) { await TourImage.CopyToAsync(fileStream); } } await _context.AddAsync(azerbaijan); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(azerbaijan)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,TourImage,TourIcon,TourName,TourTitle,TourTime,TourAction,TourDuration")] Azerbaijan azerbaijan) { if (id != azerbaijan.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(azerbaijan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AzerbaijanExists(azerbaijan.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(azerbaijan)); }