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