public async Task <IActionResult> Register(Member m) { if (ModelState.IsValid) { bool isEmailAndUsernameAvailable = true; if (await MemberDb.IsEmailTaken(_context, m.EmailAddress)) { isEmailAndUsernameAvailable = false; ModelState.AddModelError(string.Empty, "Email address is taken"); } if (await MemberDb.IsUsernameTaken(_context, m.Username)) { isEmailAndUsernameAvailable = false; ModelState.AddModelError(string.Empty, "Username is taken"); } if (!isEmailAndUsernameAvailable) { return(View(m)); } await MemberDb.Add(_context, m); SessionHelper.LogUserIn(_httpAccessor, m.MemberId, m.Username); TempData["Message"] = "You registered sucessfully"; return(RedirectToAction("Index", "Home")); } return(View(m)); }
public void TestMethod1() { using (var db = new MemberDb()) { var members = db.Members.ToList(); } }
public void 交易() { this.Inserts(); var memberToDb = new Member { ID = 1, NAME = "yao", AGE = 20, REMARK = TestHook.TestData }; using (var db = new MemberDb()) { db.BeginTransaction(); try { db.Insert(memberToDb); throw new Exception(); db.CommitTransaction(); } catch (Exception e) { db.RollbackTransaction(); } } }
public bool SuaBanDoc(MemberDb bd) { try { String sql = "UPDATE [BanDoc]" + " SET [HoTen] = @HoTen" + " ,[Email] = @Email" + " ,[DiaChi] = @DiaChi" + " ,[NamSinh] = @NamSinh" + " ,[SoDienThoai] = @SoDienThoai" + " WHERE ID = @ID"; DatabaseParamCls[] newVariable = null; newVariable = new DatabaseParamCls[] { new DatabaseParamCls("HoTen", bd.HoTen), new DatabaseParamCls("Email", bd.Email), new DatabaseParamCls("DiaChi", bd.DiaChi), new DatabaseParamCls("NamSinh", Common.convertDateFormat(bd.NamSinh, "yyyy-MM-dd")), new DatabaseParamCls("SoDienThoai", bd.SoDienThoai), new DatabaseParamCls("ID", bd.ID) }; dt = dpro.GetRecordSet(sql, newVariable); return(true); } catch (Exception e) { throw e; } return(false); }
public MemberDb GetMemberById(int iD) { try { String sql = "select * from BanDoc where id = @id"; dt = dpro.GetRecordSet(sql, new DatabaseParamCls[] { new DatabaseParamCls("id", iD) }); if (dt.Rows.Count >= 0) { var item = dt.Rows[0]; MemberDb mem = new MemberDb(); mem.ID = Convert.ToInt16(item["id"].ToString()); mem.HoTen = item["HoTen"].ToString(); mem.Email = item["Email"].ToString(); mem.DiaChi = item["DiaChi"].ToString(); mem.NamSinh = (item["NamSinh"] != null) ? Convert.ToDateTime(item["NamSinh"].ToString()) : DateTime.Now; mem.SoDienThoai = item["SoDienThoai"].ToString(); return(mem); } } catch (Exception e) { Console.WriteLine(e.Message); } return(null); }
private void updateUser(int idMemberSelect) { // validate if (!validateMember()) { return; } // Kiem tra lai ban doc co ton tai khong? bd = bdBLL.GetMemberById(idMemberSelect); if (bd == null) { MessageBox.Show("Không tồn tại dữ liệu người dùng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bd.HoTen = txtHoTen.Text; bd.SoDienThoai = txtSoDienThoai.Text; bd.DiaChi = txtDiaChi.Text; bd.Email = txtEmail.Text; bd.NamSinh = DateTime.Parse(dtNamSinh.Text).Date; if (bdBLL.SuaBanDoc(bd)) { //MessageBox.Show("Đã cập nhật thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); ucMangerMember.LoadGridView(); ucMangerMember.DisposeDialog(); return; } else { MessageBox.Show("Bạn đã nhập sai thông tin nhân viên cần sửa, yêu cầu nhập lại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void createMember() { // validate if (!validateMember()) { return; } bd = new MemberDb(); bd.HoTen = txtHoTen.Text; bd.Email = txtEmail.Text; bd.DiaChi = txtDiaChi.Text; bd.NamSinh = dtNamSinh.DateTime; bd.SoDienThoai = txtSoDienThoai.Text; if (bdBLL.ThemBanDoc(bd)) { //MessageBox.Show("Đã thêm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); ucMangerMember.LoadGridView(); ucMangerMember.DisposeDialog(); return; } else { MessageBox.Show("Có lỗi xảy ra trong quá trình thêm mới", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public async Task <IActionResult> RegisterAsync(Member m) { if (ModelState.IsValid) { await MemberDb.AddAsync(_context, m); TempData["Message"] = "You registered sucessfully"; return(RedirectToAction("Index", "Home")); } return(View(m)); }
private void setDataInfo(int memberId) { MemberDb memberDb = bdBll.GetMemberById(memberId); txtMemberId.Text = memberDb.ID.ToString(); txtMemberName.Text = memberDb.HoTen; txtMemberBirthday.Text = Common.convertDateFormat(memberDb.NamSinh, "dd/MM/yyyy"); txtMemberEmail.Text = memberDb.Email; txtMemberAddr.Text = memberDb.HoTen; removeDataTab1(); setDataTab2(memberId); }
public async Task <IActionResult> Register(Member m) { if (ModelState.IsValid) { await MemberDb.Add(_context, m); SessionHelper.LogUserIn(_httpAccessor, m.MemberId, m.Username); TempData["Message"] = $"Welcome {m.Username} to Tanner's Game Emporium!"; return(RedirectToAction("Index", "Home")); } return(View(m)); }
public IActionResult Register(Member m) { if (ModelState.IsValid) { //add to db MemberDb.AddMember(m, _context); //redirect to index page return(RedirectToAction("Index", "Home")); } //returning view, with error messages return(View(m)); }
public IActionResult Register(Member m) { if (ModelState.IsValid) { //Add to DB MemberDb.AddMember(m, _context); SessionHelper.LogUserIn(_accessor, m.MemberID); //Redirect to index page return(RedirectToAction("Index", "Home")); } //Returning the same View, with error messages return(View(m)); }
private void setInfoDialog(int idMember) { bd = bdBLL.GetMemberById(idMember); if (bd == null) { MessageBox.Show("Không tồn tại dữ liệu bạn đọc", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //set info user in dialog txtHoTen.Text = bd.HoTen; dtNamSinh.Text = bd.NamSinh != null ? bd.NamSinh.Day + "/" + bd.NamSinh.Month + "/" + bd.NamSinh.Year : ""; txtDiaChi.Text = bd.DiaChi; txtSoDienThoai.Text = bd.SoDienThoai; txtEmail.Text = bd.Email; }
public void 修改部分() { var fromDb = this.Insert(); var name = "yao2"; using (var db = new MemberDb()) { var updateCount = db.Members .Where(p => p.ID == fromDb.ID) .Set(p => p.NAME, name) .Update(); Console.WriteLine(db.LastQuery); Assert.AreEqual(1, updateCount); } }
public void 新增() { var memberToDb = new Member { ID = 1, NAME = "yao", AGE = 20, REMARK = TestHook.TestData }; using (var db = new MemberDb()) { var insertCount = db.Insert(memberToDb); Console.WriteLine(db.LastQuery); Assert.AreEqual(1, insertCount); } }
private Member Insert() { var memberToDb = new Member { ID = 12, NAME = "yao", AGE = 13, REMARK = TestHook.TestData }; using (var db = new MemberDb()) { db.Insert(memberToDb); } return(memberToDb); }
public void 修改一整筆() { var fromDb = this.Insert(); var updateDb = new Member { ID = fromDb.ID, NAME = "yao1", REMARK = TestHook.TestData }; using (var db = new MemberDb()) { var updateCount = db.Update(updateDb); Console.WriteLine(db.LastQuery); Assert.AreEqual(1, updateCount); } }
private void Inserts() { var membersToDb = new List <Member>(); var identitiesToDb = new List <Identity>(); for (int i = 0; i < 10; i++) { membersToDb.Add(new Member { ID = i + 1, NAME = Name.FullName(), AGE = RandomNumber.Next(1, 120), REMARK = TestHook.TestData }); identitiesToDb.Add(new Identity { MEMBER_ID = membersToDb[i].ID, ACCOUNT = Name.First(), PASSWORD = "******", REMARK = TestHook.TestData }); } using (var db = new MemberDb()) { db.BeginTransaction(); try { //db.BulkCopy(membersToDb); for (int i = 0; i < membersToDb.Count; i++) { var member = membersToDb[i]; var identity = identitiesToDb[i]; db.Insert(member); db.Insert(identity); } db.CommitTransaction(); } catch (Exception e) { Console.WriteLine(db.LastQuery); db.RollbackTransaction(); } } }
public async Task <IActionResult> Login(LoginViewModel model) { if (ModelState.IsValid) { Member member = await MemberDb.IsLoginValid(model, _context); if (member != null) { TempData["Message"] = "Logged in successfully"; SessionHelper.LogUserIn(_httpContext, member.MemberId, member.UserName); } else//Credentials invalid { //Adding model error with no key, will display error //message in the validation summary ModelState.AddModelError("BadCredentials", "i'm sorry, your credential did not match any record in our database"); } } return(View(model)); }
public async Task <IActionResult> Login(LoginViewModel model) { if (ModelState.IsValid) { Member member = await MemberDb.IsLoginValid(model, _context); if (member != null) { TempData["Message"] = $"Welcome back {model.UsernameOrEmail}!"; // Create session for user SessionHelper.LogUserIn(_httpAccessor, member.MemberId, member.Username); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError(string.Empty, "Sorry, we are unable to find your credentials within our database."); } } return(View(model)); }
public static void Delete() { using (var db = new MemberDb()) { db.BeginTransaction(); try { db.Members.Where(p => p.REMARK == TestData).Delete(); db.Identities.Where(p => p.REMARK == TestData).Delete(); db.CommitTransaction(); } catch (Exception e) { Console.WriteLine(db.LastQuery); Console.WriteLine(e); db.RollbackTransaction(); throw; } } }
public void 查詢IDENTITY_InnerJoin() { this.Inserts(); using (var db = new MemberDb()) { var filter = db.Identities .Select(p => new { p.MEMBER.ID, p.MEMBER.AGE, p.MEMBER.NAME, p.PASSWORD, p.ACCOUNT }) .Where(p => p.ID > 0) .ToList() ; Console.WriteLine(db.LastQuery); } }
public async Task <IActionResult> Login(LoginViewModel model) { if (ModelState.IsValid) { Member member = await MemberDb.IsLoginValid(model, _context); if (member != null) { TempData["Message"] = "Logged in successfully"; SessionHelper.LogUserIn(_httpAccessor, member.MemberId, member.Username); return(RedirectToAction("Index", "Home")); } else // Credentials invalid { // Adding model error with no key, will display error message in the validation summary ModelState.AddModelError(string.Empty, "Username or Password is incorrect"); } } return(View(model)); }
public bool ThemBanDoc(MemberDb bd) { try { String sql = "INSERT INTO [BanDoc]([HoTen],[Email],[DiaChi],[NamSinh],[SoDienThoai]) " + " VALUES(@HoTen,@Email,@DiaChi,@NamSinh,@SoDienThoai)"; dt = dpro.GetRecordSet(sql, new DatabaseParamCls[] { new DatabaseParamCls("HoTen", bd.HoTen), new DatabaseParamCls("Email", bd.Email), new DatabaseParamCls("DiaChi", bd.DiaChi), new DatabaseParamCls("NamSinh", Common.convertDateFormat(bd.NamSinh, "yyyy-MM-dd")), new DatabaseParamCls("SoDienThoai", bd.SoDienThoai) }); return(true); } catch (Exception e) { throw e; } return(false); }
public async Task <IActionResult> Login(LoginViewModel model) { if (ModelState.IsValid) { Member member = await MemberDb.IsLoginValid(model, _context); if (member != null) { TempData["Message"] = "Logged in successfully"; // use SessionHelper methods SessionHelper.LogUserIn(_httpAccessor, member.MemberId, member.Username); return(RedirectToAction("Index", "Home")); } else { // credentials invalid but password and username is supplied // AddModelError without key displays error message in the validation summary that is auto generated and for modelErrors ModelState.AddModelError(string.Empty, "I'm sorry, you're credentials did not match any records in our database"); } } return(View(model)); }
public bool ThemBanDoc(MemberDb bd) { return(memberDAL.ThemBanDoc(bd)); }
public bool SuaBanDoc(MemberDb bd) { return(memberDAL.SuaBanDoc(bd)); }