public async Task <ResponseEntity> ThemNguoiDung(NguoiDungVM nd) { nd.MaNhom = nd.MaNhom.ToUpper(); bool ckbLoaiND = db.LoaiNguoiDung.Any(n => n.MaLoaiNguoiDung == nd.MaLoaiNguoiDung); if (!ckbLoaiND) { return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Loại người dùng không hợp lệ!", MessageConstant.ERROR)); //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Loại người dùng không hợp lệ!"); //return response; } bool ckNhom = db.Nhom.Any(n => n.MaNhom == nd.MaNhom); if (!ckNhom) { return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Nhóm người dùng không hợp lệ!", MessageConstant.ERROR)); //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Nhóm người dùng không hợp lệ!"); //return response; } bool ckEmail = db.NguoiDung.Any(n => n.Email == nd.Email); if (ckEmail) { return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Email đã tồn tại!", MessageConstant.ERROR)); //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Email đã tồn tại!"); //return response; } var nguoiDung = db.NguoiDung.SingleOrDefault(n => n.TaiKhoan == nd.TaiKhoan); if (nguoiDung != null) { return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Tài khoản đã tồn tại!", MessageConstant.ERROR)); //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Tài khoản đã tồn tại!"); //return response; } try { NguoiDung ndInsert = Mapper.Map <NguoiDungVM, NguoiDung>(nd); ndInsert.BiDanh = LoaiBoKyTu.bestLower(ndInsert.HoTen); db.NguoiDung.Add(ndInsert); db.SaveChanges(); return(new ResponseEntity(StatusCodeConstants.OK, nd, MessageConstant.MESSAGE_SUCCESS_200)); //return Ok(nd); } catch (Exception ex) { return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Dữ liệu không hợp lệ!", MessageConstant.ERROR)); //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Dữ liệu không hợp lệ!"); //return response; } }
public async Task <ActionResult> ThemNguoiDung(NguoiDungVM nd) { nd.MaNhom = nd.MaNhom.ToUpper(); bool ckbLoaiND = db.LoaiNguoiDung.Any(n => n.MaLoaiNguoiDung == nd.MaLoaiNguoiDung); if (!ckbLoaiND) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Loại người dùng không hợp lệ!"); return(response); } bool ckNhom = db.Nhom.Any(n => n.MaNhom == nd.MaNhom); if (!ckNhom) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Nhóm người dùng không hợp lệ!"); return(response); } bool ckEmail = db.NguoiDung.Any(n => n.Email == nd.Email); if (ckEmail) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Email đã tồn tại!"); return(response); } var nguoiDung = db.NguoiDung.SingleOrDefault(n => n.TaiKhoan == nd.TaiKhoan); if (nguoiDung != null) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Tài khoản đã tồn tại!"); return(response); } try { NguoiDung ndInsert = Mapper.Map <NguoiDungVM, NguoiDung>(nd); ndInsert.BiDanh = LoaiBoKyTu.bestLower(ndInsert.HoTen); db.NguoiDung.Add(ndInsert); db.SaveChanges(); return(Ok(nd)); } catch (Exception ex) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Dữ liệu không hợp lệ!"); return(response); } }
public IActionResult Index(string Ten, string TenDangNhap, string VaiTro, int TrangThai, string currentSort, string currentFilterTen, string currentFilterTenDangNhap, string currentFilterVaiTro, string currentFilterTrangThai, int pageIndex = 1) { if (KiemTraDangNhap() == false) { return(View("../Login/Index")); } if (!String.IsNullOrEmpty(Ten) || !String.IsNullOrEmpty(TenDangNhap) || !String.IsNullOrEmpty(VaiTro) || !TrangThai.Equals(0)) { pageIndex = 1; } if (String.IsNullOrEmpty(Ten)) { Ten = currentFilterTen; } if (String.IsNullOrEmpty(TenDangNhap)) { TenDangNhap = currentFilterTenDangNhap; } if (String.IsNullOrEmpty(VaiTro)) { VaiTro = currentFilterVaiTro; } if (TrangThai.Equals(0) && !String.IsNullOrEmpty(currentFilterTrangThai)) { TrangThai = Convert.ToInt32(currentFilterTrangThai); } ViewBag.CurrentFilterTen = Ten; ViewBag.CurrentFilterTenDangNhap = TenDangNhap; ViewBag.CurrentFilterVaiTro = VaiTro; ViewBag.CurrentFilterTrangThai = TrangThai; if (String.IsNullOrEmpty(currentSort)) { currentSort = "Ten_DESC"; } ViewBag.CurrentSortTen = currentSort.Equals("Ten_DESC") ? "Ten_ASC" : "Ten_DESC"; ViewBag.CurrentSortTenDangNhap = currentSort.Equals("TenDangNhap_DESC") ? "TenDangNhap_ASC" : "TenDangNhap_DESC"; ViewBag.CurrentSortVaiTro = currentSort.Equals("VaiTro_DESC") ? "VaiTro_ASC" : "VaiTro_DESC"; ViewBag.CurrentSortTrangThai = currentSort.Equals("TrangThai_DESC") ? "TrangThai_ASC" : "TrangThai_DESC"; ViewBag.CurrentSort = currentSort; NguoiDungVM nguoiDungVM = _servicesIndexVM.GetNguoiDungVM(currentSort, Ten, TenDangNhap, VaiTro, TrangThai, pageIndex); return(View(nguoiDungVM)); }
public async Task <dynamic> dangKy(NguoiDungVM nguoiDung) { int nd; var p = new DynamicParameters(); try { using (var connection = new SqlConnection(connectionstr)) { p.Add("@TaiKhoan", nguoiDung.TaiKhoan); p.Add("@MatKhau", nguoiDung.MatKhau); p.Add("@CMND", nguoiDung.CMND); p.Add("@HoTen", nguoiDung.HoTen); p.Add("@NgaySinh", nguoiDung.NgaySinh); p.Add("@Email", nguoiDung.Email); p.Add("@SoDT", nguoiDung.SoDT); p.Add("@DiaChi", nguoiDung.DiaChi); p.Add("@LoaiND", nguoiDung.LoaiND); p.Add("Result", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue); nd = connection.QuerySingleOrDefault <int>("SP_DANGKY", p, commandType: CommandType.StoredProcedure); } int result = p.Get <int>("Result"); if (result == 1) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Account Name is exist!"); return(response.Content); } if (result == 2) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Type of user is unsuitable!"); return(response.Content); } return("success"); } catch (Exception ex) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Value wrong!"); return(response.Content); } }
public async Task <ResponseEntity> CapNhatThongTinNguoiDung(NguoiDungVM nd) { nd.MaNhom = nd.MaNhom.ToUpper(); bool ckbLoaiND = db.LoaiNguoiDung.Any(n => n.MaLoaiNguoiDung == nd.MaLoaiNguoiDung); if (!ckbLoaiND) { return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Loại người dùng không hợp lệ!", MessageConstant.ERROR)); //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Loại người dùng không hợp lệ!"); //return response; } bool ckNhom = db.Nhom.Any(n => n.MaNhom == nd.MaNhom); if (!ckNhom) { return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Nhóm người dùng không hợp lệ!", MessageConstant.ERROR)); //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Nhóm người dùng không hợp lệ!"); //return response; } bool ckEmail = db.NguoiDung.Any(n => n.Email == nd.Email && n.TaiKhoan != nd.TaiKhoan); if (ckEmail) { return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Email đã tồn tại!", MessageConstant.ERROR)); //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Email đã tồn tại!"); //return response; } NguoiDung nguoiDungCapNhat = db.NguoiDung.SingleOrDefault(n => n.TaiKhoan == nd.TaiKhoan); if (nguoiDungCapNhat == null) { return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Tài khoản đã tồn tại!", MessageConstant.ERROR)); //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Tài khoản không tồn tại!"); //return response; } try { if (nd.MatKhau == "") { nd.MatKhau = nguoiDungCapNhat.MatKhau; } //nguoiDungCapNhat.TaiKhoan = ndUpdate.TaiKhoan; nguoiDungCapNhat.HoTen = nd.HoTen; nguoiDungCapNhat.MatKhau = nd.MatKhau; nguoiDungCapNhat.BiDanh = LoaiBoKyTu.bestLower(nd.HoTen); nguoiDungCapNhat.SoDt = nd.SoDt; nguoiDungCapNhat.MaLoaiNguoiDung = nd.MaLoaiNguoiDung; nguoiDungCapNhat.Email = nd.Email; //nguoiDungCapNhat.MaNhom = ndUpdate.MaNhom; db.SaveChanges(); var result = new ThongTinTaiKhoanVM { TaiKhoan = nguoiDungCapNhat.TaiKhoan, MatKhau = nguoiDungCapNhat.MatKhau, HoTen = nguoiDungCapNhat.HoTen, Email = nguoiDungCapNhat.Email, SoDT = nguoiDungCapNhat.SoDt, MaNhom = nguoiDungCapNhat.MaNhom, LoaiNguoiDung = nguoiDungCapNhat.MaLoaiNguoiDungNavigation.TenLoai }; return(new ResponseEntity(StatusCodeConstants.OK, result, MessageConstant.MESSAGE_SUCCESS_200)); } catch (Exception ex) { return(new ResponseEntity(StatusCodeConstants.OK, "Dữ liệu không hợp lệ!", MessageConstant.MESSAGE_SUCCESS_200)); //var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Dữ liệu không hợp lệ!"); //return response; } }
public async Task <ActionResult> dangKy(NguoiDungVM ngDung) { dynamic result = await _quanLyNguoiDungRepository.dangKy(ngDung); return(Ok(result)); }
public async Task <ActionResult> CapNhatThongTinNguoiDung(NguoiDungVM nd) { nd.MaNhom = nd.MaNhom.ToUpper(); bool ckbLoaiND = db.LoaiNguoiDung.Any(n => n.MaLoaiNguoiDung == nd.MaLoaiNguoiDung); if (!ckbLoaiND) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Loại người dùng không hợp lệ!"); return(response); } bool ckNhom = db.Nhom.Any(n => n.MaNhom == nd.MaNhom); if (!ckNhom) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Nhóm người dùng không hợp lệ!"); return(response); } bool ckEmail = db.NguoiDung.Any(n => n.Email == nd.Email && n.TaiKhoan != nd.TaiKhoan); if (ckEmail) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Email đã tồn tại!"); return(response); } NguoiDung nguoiDungCapNhat = db.NguoiDung.SingleOrDefault(n => n.TaiKhoan == nd.TaiKhoan); if (nguoiDungCapNhat == null) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Tài khoản không tồn tại!"); return(response); } try { if (nd.MatKhau == "") { nd.MatKhau = nguoiDungCapNhat.MatKhau; } //nguoiDungCapNhat.TaiKhoan = ndUpdate.TaiKhoan; nguoiDungCapNhat.HoTen = nd.HoTen; nguoiDungCapNhat.MatKhau = nd.MatKhau; nguoiDungCapNhat.BiDanh = LoaiBoKyTu.bestLower(nd.HoTen); nguoiDungCapNhat.SoDt = nd.SoDt; nguoiDungCapNhat.MaLoaiNguoiDung = nd.MaLoaiNguoiDung; nguoiDungCapNhat.Email = nd.Email; //nguoiDungCapNhat.MaNhom = ndUpdate.MaNhom; db.SaveChanges(); return(Ok(new ThongTinTaiKhoanVM { TaiKhoan = nguoiDungCapNhat.TaiKhoan, MatKhau = nguoiDungCapNhat.MatKhau, HoTen = nguoiDungCapNhat.HoTen, Email = nguoiDungCapNhat.Email, SoDT = nguoiDungCapNhat.SoDt, MaNhom = nguoiDungCapNhat.MaNhom, LoaiNguoiDung = nguoiDungCapNhat.MaLoaiNguoiDungNavigation.TenLoai })); } catch (Exception ex) { var response = await tbl.TBLoi(ThongBaoLoi.Loi500, "Dữ liệu không hợp lệ!"); return(response); } }