public async Task CreateAccountAsync(Taikhoan account, byte role) { if (account == null) { throw new ArgumentNullException(nameof(account)); } // Validate if (role != 2 && role != 3) { return; } // Create account _context.Taikhoans.Add(account); await _context.SaveChangesAsync(); // Get account Id var MaNd = await _context.Taikhoans.Where(p => p.Email == account.Email).Select(p => p.MaTk).FirstOrDefaultAsync(); // Create User _context.Nguoidungs.Add(new Nguoidung { Vaitro = role, MaNd = MaNd }); await _context.SaveChangesAsync(); }
private void Dangnhap() { try { var tb = LoadData.KiemTraTaiKhoan(txtTaiKhoan.Text, MaHoaMd5.Md5(txtMatKhau.Text)); if (tb.Rows.Count > 0) { var taikhoan = new Taikhoan { ID = int.Parse(tb.Rows[0]["ID"].ToString()), TaiKhoan = tb.Rows[0]["TaiKhoan"].ToString(), MatKhau = tb.Rows[0]["MatKhau"].ToString(), HoTen = tb.Rows[0]["HoTen"].ToString(), Quyen = tb.Rows[0]["Quyen"].ToString() }; CheckDangNhap(this, true, taikhoan); } else { MessageBox.Show(FormResource.FrmDangNhap_Dangnhap_, @"Thông báo"); txtMatKhau.Clear(); } } catch (Exception ex) { MessageBox.Show(ex.Message.Contains(FormResource.msgLostConnect) ? FormResource.txtLoiDB : ex.Message); Log2File.LogExceptionToFile(ex); } }
public async Task <IActionResult> dangnhap([Bind("TaiKhoan1,MatKhau")] Taikhoan taikhoan) { Taikhoan taiKhoanGetFromAPI = null; HttpResponseMessage respond = await GetAPI("KhachHangUrl").GetAsync($"{pathKH}/{taikhoan.TaiKhoan1}"); if (respond.IsSuccessStatusCode) { // Gán dữ liệu API đọc đượcs taiKhoanGetFromAPI = await respond.Content.ReadAsAsync <Taikhoan>(); if (taikhoan.MatKhau == taiKhoanGetFromAPI.MatKhau) { HttpContext.Session.SetString("userName", taiKhoanGetFromAPI.TaiKhoan1); HttpContext.Session.SetString("power", taiKhoanGetFromAPI.Quyen); return(Redirect("/")); } else { ModelState.AddModelError("", "Đăng nhập không thành công"); } } else { ModelState.AddModelError("", "Đăng nhập không thành công"); } return(View(taikhoan)); }
public async Task <IActionResult> PutTaikhoan([FromRoute] string id, [FromBody] Taikhoan taikhoan) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != taikhoan.TaiKhoan1) { return(BadRequest()); } _context.Entry(taikhoan).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaikhoanExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(string id, [Bind("TkMa,TkEmail,TkMatkhau,TkHoten")] Taikhoan taikhoan) { if (id != taikhoan.TkMa) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(taikhoan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaikhoanExists(taikhoan.TkMa)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(taikhoan)); }
public bool Update(Taikhoan entity) { try { var user = db.Taikhoans.Find(entity.UserID); if (string.IsNullOrEmpty(entity.Password)) { user.Password = entity.Password; } user.DiaChi = entity.DiaChi; user.HovaTen = entity.HovaTen; user.Email = entity.Email; user.Phone = entity.Phone; user.Status = entity.Status; user.CreatedDate = DateTime.Now.Date; db.SaveChanges(); return(true); } catch (Exception) { //logging return(false); } }
public ActionResult Create(Taikhoan user) { if (ModelState.IsValid) { var dao = new UserDao(); var encryptedMd5Pas = Encryptor.MD5Hash(user.Password); user.Password = encryptedMd5Pas; int id = dao.Insert(user); if (id == 1) { SetAlert("Them user thành công", "success"); return(RedirectToAction("Index", "User")); } else { ModelState.AddModelError("", "Thêm user không thành công"); } } else { return(View(user)); } return(View("Index")); }
public List<Phanhoi> ThemPhanHoi(int BinhLuanId,string NoiDung){ var dbContext = new shopContext(); var userName = HttpContext.Session.GetString("username"); var taiKhoan = (from tk in dbContext.Taikhoan where tk.Username == userName select tk).ToList(); var phanHoi = new Phanhoi(){ BinhLuanId = BinhLuanId, TaiKhoanId = taiKhoan[0].TaiKhoanId, NoiDung = NoiDung }; dbContext.Phanhoi.Add(phanHoi); dbContext.SaveChanges(); var DSPhanHoi = (from ph in dbContext.Phanhoi join tk in dbContext.Taikhoan on ph.TaiKhoanId equals tk.TaiKhoanId where ph.BinhLuanId == BinhLuanId orderby ph.PhanHoiId descending select new { NoiDung = ph.NoiDung, userName = tk.Username }).ToList(); List<Phanhoi> ListPhanHoi = new List<Phanhoi>(); foreach (var item in DSPhanHoi) { Phanhoi ph = new Phanhoi(); ph.BinhLuanId = BinhLuanId; ph.NoiDung = item.NoiDung; Taikhoan tk = new Taikhoan(); tk.Username = item.userName; ph.TaiKhoan = tk; ListPhanHoi.Add(ph); } dbContext.SaveChanges(); return ListPhanHoi; }
public ActionResult DeleteConfirmed(string id) { Taikhoan taikhoan = db.Taikhoans.Find(id); db.Taikhoans.Remove(taikhoan); db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult AddStaff(NhanvienViewModel command, Taikhoan taikhoan) { if (ModelState.IsValid) { this._staffService.AddStaff(command, taikhoan); return(RedirectToAction("AllStaff", "Admin")); } return(View()); }
public async Task <ActionResult <AccountReadDto> > CreateAccountAsync(AccountCreateDto account, byte role) { Taikhoan accountModel = _mapper.Map <Taikhoan>(account); await _accountService.CreateAccountAsync(accountModel, role); AccountReadDto accountDto = _mapper.Map <AccountReadDto>(accountModel); return(CreatedAtRoute(nameof(GetAccountByIdAsync), new { id = accountModel.MaTk }, accountDto)); }
public ActionResult Edit([Bind(Include = "Mataikhoan,Tendangnhap,Matkhau,Phanquyen")] Taikhoan taikhoan) { if (ModelState.IsValid) { db.Entry(taikhoan).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(taikhoan)); }
public IActionResult ThemNhanVien(Nhanvien model, string Username, string Password) { var dbContext = new shopContext(); var taikhoan1 = (from tk in dbContext.Taikhoan where tk.Username == Username select tk).ToList(); if (taikhoan1.Count > 0) { ModelState.AddModelError("Username", "Username da ton tai"); ViewBag.errUsername = "******"; } if (ModelState.IsValid) { // chuyển mật khẩu nhập vào thành mã băm MD5 mh = MD5.Create(); byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(Password); byte[] hash = mh.ComputeHash(inputBytes); StringBuilder sb = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { sb.Append(hash[i].ToString("x2")); } string newPassword = sb.ToString(); var taikhoan = new Taikhoan() { Username = Username, Password = newPassword, NgayTao = DateTime.Now, KichHoat = 0, LoaiTaiKhoanId = 1 }; //cập nhật mật khẩu mới dbContext.Taikhoan.Add(taikhoan); dbContext.SaveChanges(); var tk = (from x in dbContext.Taikhoan where x.Username == Username select x).ToList(); var nhanvien = new Nhanvien() { HoTen = model.HoTen, NgaySinh = model.NgaySinh, Email = model.Email, Sdt = model.Sdt, DiaChi = model.DiaChi, TaiKhoanId = tk[0].TaiKhoanId }; dbContext.Nhanvien.Add(nhanvien); dbContext.SaveChanges(); string success = "Thêm nhân viên thành công"; return(RedirectToAction("ThemNhanVien", "NhanVien", new{ success = success })); } string alert = "Thêm nhân viên không thành công"; return(RedirectToAction("ThemNhanVien", "NhanVien", new{ alert = alert })); }
private void uG_DanhSach_AfterExitEditMode(object sender, EventArgs e) { try { if (DeleteAndUpdate) { DeleteAndUpdate = false; return; } var indexcell = dgv_DanhSach.ActiveCell.Column.Index; var id = dgv_DanhSach.ActiveRow.Cells["ID"].Text; var ht = dgv_DanhSach.ActiveRow.Cells["HoTen"].Text; var qu = dgv_DanhSach.ActiveRow.Cells["Quyen"].Text; if (indexcell == 3) { var mk = dgv_DanhSach.ActiveRow.Cells["MatKhau"].Text; if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(mk)) { foreach (var item in _listUpdatepass.Where(item => item.ID == int.Parse(id))) { item.MatKhau = MaHoaMd5.Md5(mk); return; } var hs = new Taikhoan { ID = int.Parse(id), MatKhau = MaHoaMd5.Md5(mk) }; _listUpdatepass.Add(hs); } } else if (!string.IsNullOrEmpty(id)) { foreach (var item in _listUpdate.Where(item => item.ID == int.Parse(id))) { item.HoTen = ht; item.Quyen = qu; return; } var hs = new Taikhoan { ID = int.Parse(id), HoTen = ht, Quyen = qu }; _listUpdate.Add(hs); } } catch (Exception ex) { Log2File.LogExceptionToFile(ex); } }
public ActionResult Create([Bind(Include = "Mataikhoan,Tendangnhap,Matkhau,Phanquyen")] Taikhoan taikhoan) { if (ModelState.IsValid) { db.Taikhoans.Add(taikhoan); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(taikhoan)); }
private static void UpdateMatKhau(Taikhoan item) { try { Conn.ExcuteQuerySql("Update TAIKHOAN set MatKhau = N'" + item.MatKhau + "' where ID = " + item.ID + ""); } catch (Exception ex) { Log2File.LogExceptionToFile(ex); } }
public ActionResult Edit([Bind(Include = "Mataikhoan,Tendangnhap,Matkhau,Role_id")] Taikhoan taikhoan) { if (ModelState.IsValid) { db.Entry(taikhoan).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Role_id = new SelectList(db.Roles, "Role_id", "Role_name", taikhoan.Role_id); return(View(taikhoan)); }
public async Task <IActionResult> Create([Bind("TkMa,TkEmail,TkMatkhau,TkHoten")] Taikhoan taikhoan) { if (ModelState.IsValid) { _context.Add(taikhoan); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(taikhoan)); }
public ActionResult Create([Bind(Include = "Mataikhoan,Tendangnhap,Matkhau,Role_id")] Taikhoan taikhoan) { if (ModelState.IsValid) { db.Taikhoans.Add(taikhoan); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Role_id = new SelectList(db.Roles, "Role_id", "Role_name", taikhoan.Role_id); return(View(taikhoan)); }
/// <summary> /// Update thông tin 1 tài khoản /// </summary> /// <returns>true</returns> private static void UpdateTaiKhoan(Taikhoan item) { try { Conn.ExcuteQuerySql("Update TAIKHOAN set HoTen = N'" + item.HoTen + "', Quyen = N'" + item.Quyen + "' where ID = " + item.ID + ""); } catch (Exception ex) { Log2File.LogExceptionToFile(ex); } }
// GET: Admin/Taikhoan_Ad/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Taikhoan taikhoan = db.Taikhoans.Find(id); if (taikhoan == null) { return(HttpNotFound()); } return(View(taikhoan)); }
public ActionResult DangKy(RegisterModel model) { if (ModelState.IsValid) { var dao = new UserDao(); if (dao.CheckUserName(model.UserName)) { ModelState.AddModelError("", "Tên đăng nhập đã tồn tại"); } else if (dao.CheckEmail(model.Email)) { ModelState.AddModelError("", "Email đã tồn tại"); } else { var user = new Taikhoan(); string diachi = null; user.HovaTen = model.Name; user.Password = Encryptor.MD5Hash(model.Password); user.Phone = model.Phone; user.Email = model.Email; user.Username = model.UserName; user.CreatedDate = DateTime.Now; user.MaCV = 3; user.Status = true; if (!string.IsNullOrEmpty(model.ProvinceID)) { diachi = ProvinceModel1(Convert.ToInt32(model.ProvinceID)); } if (!string.IsNullOrEmpty(model.DistrictID)) { diachi = DistrictModel1(Convert.ToInt32(model.ProvinceID), Convert.ToInt32(model.DistrictID)) + " " + diachi; } user.DiaChi = model.Address + " " + diachi; var result = dao.Insert(user); if (result > 0) { ViewBag.Success = "Đăng ký thành công"; model = new RegisterModel(); return(Redirect("/user")); } else { ModelState.AddModelError("", "Đăng ký không thành công."); } } } return(View(model)); }
public bool Suataikhoan(Taikhoan entity) { var res = db.Taikhoans.Find(entity.Tentaikhoan); if (res != null) { res.Matkhau = entity.Matkhau; res.Mail = entity.Mail; res.Machucvu = entity.Machucvu; db.SaveChanges(); return(true); } return(false); }
// GET: Admin/Taikhoan_Ad/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Taikhoan taikhoan = db.Taikhoans.Find(id); if (taikhoan == null) { return(HttpNotFound()); } ViewBag.Role_id = new SelectList(db.Roles, "Role_id", "Role_name", taikhoan.Role_id); return(View(taikhoan)); }
public bool Themtaikhoan(Taikhoan entity) { var x = db.Taikhoans.Find(entity.Tentaikhoan); entity.TGdangki = System.DateTime.Now; entity.Trangthaihd = "Offline"; if (x != null) { return(false); } var res = db.Taikhoans.Add(entity); db.SaveChanges(); return(true); }
/// <summary> /// Thêm 1 người dùng mới /// </summary> /// <returns></returns> public static bool ThemTaiKhoan(Taikhoan item) { try { Conn.ExcuteQuerySql("INSERT INTO TAIKHOAN(TaiKhoan,MatKhau,HoTen,Quyen) values(N'" + item.TaiKhoan + "',N'" + item.MatKhau + "',N'" + item.HoTen + "',N'" + item.Quyen + "')"); return(true); } catch (Exception ex) { Log2File.LogExceptionToFile(ex); return(false); } }
protected override void SaveDetail() { try { if (ValidateData()) { MessageBox.Show(@"Vui lòng nhập đầy đủ thông tin", @"Lỗi"); } else { foreach (var row in dgv_DanhSach.Rows.Where(row => string.IsNullOrEmpty(row.Cells["ID"].Text))) { var hs = new Taikhoan { TaiKhoan = row.Cells["TaiKhoan"].Value.ToString(), HoTen = row.Cells["HoTen"].Value.ToString(), Quyen = row.Cells["Quyen"].Value.ToString(), MatKhau = MaHoaMd5.Md5(row.Cells["MatKhau"].Value.ToString()) }; _listAdd.Add(hs); } if (_listAdd.Count <= 0 && _listUpdate.Count <= 0 && _listUpdatepass.Count <= 0) { return; } if (_listUpdate.Count > 0) { UpdateData.UpdateTaiKhoan(_listUpdate); } if (_listUpdatepass.Count > 0) { UpdateData.UpdateMatKhau(_listUpdatepass); } if (_listAdd.Count > 0) { InsertData.ThemTaiKhoan(_listAdd); } MessageBox.Show(FormResource.MsgThongbaothanhcong, FormResource.MsgCaption, MessageBoxButtons.OK, MessageBoxIcon.Information); LoadFormDetail(); } } catch (Exception ex) { Log2File.LogExceptionToFile(ex); } }
public int checkUserLogin(Taikhoan user) { // Sai tài khoản hoặc mật khẩu if (user == null) { return(0); } // Tài khoản khóa if (user.Khoa == "0") { return(1); } return(2); }
public async Task <Taikhoan> ValidateAccountAsync(Taikhoan account) { if (account == null) { throw new ArgumentNullException(nameof(account)); } var check = await _context.Taikhoans.Where(p => p.Email.ToLower() == account.Email.ToLower() && p.MatKhau == account.MatKhau).FirstOrDefaultAsync(); if (check == null) { return(new Taikhoan()); } return(check); }
public void AddStaff(NhanvienViewModel nhanvien, Taikhoan taikhoan) { var newStaff = new Nguoidung(); var newaccount = new Taikhoan(); { newStaff.Hoten = nhanvien.Hoten; newStaff.Sdt = nhanvien.Sdt; newStaff.Email = nhanvien.Email; newStaff.Gioitinh = nhanvien.Gioitinh; newaccount.Email = newStaff.Email; newaccount.Matkhau = taikhoan.Matkhau; newaccount.Vaitro = taikhoan.Vaitro; } _db.Taikhoans.Add(newaccount); _db.Nguoidungs.Add(newStaff); _db.SaveChanges(); }
private static void UpdateMatKhau(Taikhoan item) { try { Conn.ExcuteQuerySql("Update nhanvien set tennguoidung = N'" + item.HoTen + "' where username = "******""); } catch (Exception ex) { LogExceptionToFile(ex); } }
// public event CustomHandler CheckDangNhap; private void Dangnhap() { try { var tb = KiemTraTaiKhoan(txtTaiKhoan.Text, MaHoaMD5.Md5(txtMatKhau.Text)); if (tb.Rows.Count > 0) { var taikhoan = new Taikhoan { TaiKhoan = tb.Rows[0]["username"].ToString(), MatKhau = tb.Rows[0]["pass"].ToString() }; // CheckDangNhap(this, true, taikhoan); this.send(this.txtTaiKhoan.Text); this.send1(this.txtMatKhau.Text); this.Close(); } else { MessageBox.Show("Bạn đã nhập sai tên đăng nhập hoặc mật khẩu hoặc sai cấu hình server. Xin vui lòng thử lại", @"Thông báo"); txtMatKhau.Clear(); } } catch (Exception ex) { MessageBox.Show("Không kết nối được tới CSDL"); LogExceptionToFile(ex); } }