public async Task <IActionResult> Create(BannerQuangCao bannerQuangCao, IFormFile Ffile) { if (ModelState.IsValid) { string s = ""; if (Ffile != null) { string fileName = $"{DateTime.Now.Ticks}{Ffile.FileName}"; s = fileName; bannerQuangCao.LinkBanner = s; string fullPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "user", "banner", fileName); using (var file = new FileStream(fullPath, FileMode.Create)) { Ffile.CopyTo(file); } } else { bannerQuangCao.LinkBanner = "macdinh.jpg"; } _context.Add(bannerQuangCao); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bannerQuangCao)); }
public async Task <IActionResult> Edit(int id, BannerQuangCao bannerQuangCao, IFormFile Ffile) { if (ModelState.IsValid) { try { string s = ""; if (Ffile != null) { string fileName = $"{DateTime.Now.Ticks}{Ffile.FileName}"; s = fileName; bannerQuangCao.LinkBanner = s; string fullPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "user", "banner", fileName); using (var file = new FileStream(fullPath, FileMode.Create)) { Ffile.CopyTo(file); } } else { bannerQuangCao.LinkBanner = "macdinh.jpg"; } bannerQuangCao.MaBanner = id; _context.Update(bannerQuangCao); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BannerQuangCaoExists(bannerQuangCao.MaBanner)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(bannerQuangCao)); }