public async Task <IActionResult> Create([Bind("IDBlog,TieuDe,HinhAnh,TomTat,NoiDung,IDLoai,IDNguoiTao,NgayTao,NgayDuyet,View,IDNguoiDuyet,TrangThai")] CauHoi cauhoi, IFormFile ful) { if (ModelState.IsValid) { _context.Add(cauhoi); await _context.SaveChangesAsync(); var parth = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/cauhoi", cauhoi.IDBlog + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(parth, FileMode.Create)) { await ful.CopyToAsync(stream); } cauhoi.HinhAnh = cauhoi.IDBlog + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]; _context.Update(cauhoi); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDLoai"] = new SelectList(_context.Loais, "IDLoai", "TieuDe", cauhoi.IDLoai); return(View(cauhoi)); }
public async Task <IActionResult> Create([Bind("IDLoai,TieuDe,NgayTao,IDNguoiTao")] Loai loai) { if (ModelState.IsValid) { _context.Add(loai); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(loai)); }
public async Task <IActionResult> Create([Bind("IDBlog,TieuDe,HinhAnh,TomTat,NoiDung,IDLoai,IDNguoiTao,NgayTao,NgayDuyet,View,IDNguoiDuyet,TrangThai")] CauHoi cauHoi) { if (ModelState.IsValid) { _context.Add(cauHoi); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDLoai"] = new SelectList(_context.Loais, "IDLoai", "IDLoai", cauHoi.IDLoai); return(View(cauHoi)); }
public async Task <IActionResult> Create([Bind("IDBL,IDTK,IDBV,IDCH,NgayTao,NoiDung,TrangThai")] BinhLuan binhLuan) { if (ModelState.IsValid) { _context.Add(binhLuan); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IDTK"] = new SelectList(_context.TaiKhoans, "IDTK", "IDTK", binhLuan.IDTK); return(View(binhLuan)); }
public async Task <IActionResult> Create([Bind("IDLoai,TieuDe,NgayTao,IDNguoiTao")] Loai loai) { if (ModelState.IsValid) { _context.Add(loai); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.IDTK = _context.TaiKhoans; ViewData["IDTK"] = new SelectList(_context.TaiKhoans, "IDTK", "Ten"); return(View(loai)); }
public async Task <IActionResult> Create([Bind("IDBL,IDTK,IDBV,NgayTao,NoiDung,TrangThai")] BinhLuan binhLuan) { HttpContext.Session.SetString("idbaiviet", binhLuan.IDBV.ToString()); if (ModelState.IsValid) { _context.Add(binhLuan); await _context.SaveChangesAsync(); return(Redirect(Request.Headers["Referer"].ToString())); } ViewData["IDTK"] = new SelectList(_context.TaiKhoans, "IDTK", "IDTK", binhLuan.IDTK); return(View(binhLuan)); }
public async Task <IActionResult> Create([Bind("IDTK,Ten,Password,HinhAnh,Quyen,TrangThai")] TaiKhoan taiKhoan) { if (ModelState.IsValid) { taiKhoan.Password = StringProcess.CreateMD5Hash(taiKhoan.Password); _context.Add(taiKhoan); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(taiKhoan)); }
public async Task <IActionResult> Create([Bind("IDTK,Ten,Password,HinhAnh,Quyen,TrangThai")] TaiKhoan taiKhoan, IFormFile ful) { if (ModelState.IsValid) { _context.Add(taiKhoan); await _context.SaveChangesAsync(); var parth = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Admin/avatar", taiKhoan.IDTK + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(parth, FileMode.Create)) { await ful.CopyToAsync(stream); } taiKhoan.HinhAnh = taiKhoan.IDTK + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]; _context.Update(taiKhoan); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(taiKhoan)); }