public async Task <IActionResult> PutThanhVienModel(int id, ThanhVienModel thanhVienModel) { if (id != thanhVienModel.Id) { return(BadRequest()); } _context.Entry(thanhVienModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ThanhVienModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <bool> > PostThanhVienModel(DangKy val) { ThanhVienModel thanhVien = new ThanhVienModel(); thanhVien.Ten = val.name; thanhVien.MatKhau = StringProcessing.CreateMD5Hash(val.password); thanhVien.TaiKhoan = val.username; thanhVien.GioiTinh = val.sex; thanhVien.SDT = val.phone; thanhVien.Email = val.email; thanhVien.TrangThai = true; thanhVien.HinhAnh = "not available"; if (!UsernameExists(thanhVien.TaiKhoan)) { _context.tb_ThanhVien.Add(thanhVien); await _context.SaveChangesAsync(); } else { return(false); } var str = JsonConvert.SerializeObject(thanhVien); HttpContext.Session.SetString("user", str); if (str != null) { return(true); } return(false); }
// // GET: /Admin/ThanhVien/ public ActionResult Index() { var iplTV = new ThanhVienModel(); var model = iplTV.ListAll(); return(View(model)); }
// GET: Admin/ThanhVien public async Task <IActionResult> Index(int?id, string?s_name, string?s_stt) { ThanhVienModel thanhVien = null; if (id != null) { thanhVien = await _context.tb_ThanhVien.FirstOrDefaultAsync(m => m.Id == id && m.TrangThai == true); } if (s_name != null) { if (s_stt == null) { ViewBag.ListTV = (from m in _context.tb_ThanhVien where m.Ten.IndexOf(s_name) >= 0 select m).ToList(); } else { ViewBag.ListTV = (from m in _context.tb_ThanhVien where m.Ten.IndexOf(s_name) >= 0 && m.TrangThai == Convert.ToBoolean(s_stt) select m).ToList(); } } else { ViewBag.ListTV = (from n in _context.tb_ThanhVien where n.TrangThai == true select n).ToList(); } return(View(thanhVien)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Ten,HinhAnh,GioiTinh,SDT,Email,TaiKhoan,MatKhau,TrangThai")] ThanhVienModel thanhVienModel, IFormFile ful, string matkhau) { if (id != thanhVienModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(thanhVienModel); if (ful != null) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/template_admin/images/thanhvien", thanhVienModel.HinhAnh); System.IO.File.Delete(path); path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot/template_admin/images/thanhvien", thanhVienModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(path, FileMode.Create)) { await ful.CopyToAsync(stream); } thanhVienModel.HinhAnh = thanhVienModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]; _context.Update(thanhVienModel); } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ThanhVienModelExists(thanhVienModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(thanhVienModel)); }
public async Task <IActionResult> Create([Bind("Id,Ten,HinhAnh,GioiTinh,SDT,Email,TaiKhoan,MatKhau,TrangThai")] ThanhVienModel thanhVienModel, IFormFile ful, string matkhau) { if (ModelState.IsValid) { thanhVienModel.MatKhau = StringProcessing.CreateMD5Hash(matkhau); _context.Add(thanhVienModel); await _context.SaveChangesAsync(); var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot/template_admin/images/thanhvien", thanhVienModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]); using (var stream = new FileStream(path, FileMode.Create)) { await ful.CopyToAsync(stream); } thanhVienModel.HinhAnh = thanhVienModel.Id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]; _context.Update(thanhVienModel); await _context.SaveChangesAsync(); } return(View("Index")); }