private void btnThemHS_Click(object sender, EventArgs e) { if (_hocSinhRepository.FindByCondition(p => p.MaHS.Equals(txtMaHS.Text)).SingleOrDefault() != null) { MessageBox.Show("Mã học sinh này đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (_nguoiDungRepository.FindByCondition(p => p.TenTaiKhoan.Equals(txtTenTaiKhoanHS.Text)).SingleOrDefault() != null) { MessageBox.Show("Tên tài khoản này đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } NguoiDung nd = new NguoiDung(); nd.TenTaiKhoan = txtTenTaiKhoanHS.Text; nd.MatKhauHash = txtMatKhauHS.Text; nd.Quyen = 3; _nguoiDungRepository.Create(nd); _nguoiDungRepository.Update(); HocSinh hs = new HocSinh(); hs.MaHS = txtMaHS.Text; hs.Lop = txtLop.Text; hs.HoTen = txtHoTenHS.Text; hs.DiaChi = txtDiaChiHS.Text; hs.NgaySinh = dtpNgaySinhHS.Value; hs.NguoiDungID = nd.IDNguoiDung; _hocSinhRepository.Create(hs); _hocSinhRepository.Update(); LoadHocSinh(); }
public ActionResult Create([FromBody] NguoiDungInsert c) { try { NguoiDung nguoiDung = new NguoiDung(); nguoiDung.TenTaiKhoan = c.tenTaiKhoan; nguoiDung.MatKhau = c.matKhau; if (c.kichHoat != null) { nguoiDung.KichHoat = Convert.ToBoolean(c.kichHoat); } nguoiDung.MaNhanSu = c.maNhanSu; nguoidungRepo.Create(nguoiDung); return(Json(c)); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } return(View(c)); }