private void SignUp() { if (DangNhapViewModel.User == null) { DangNhapWindow dangNhapWindow = new DangNhapWindow(); dangNhapWindow.Show(); this.Window.Close(); } else { if (this.HoiNghi.SOLUONG >= this.SucChua) { MessageBox.Show("Số lượng tham gia hội nghị đã đạt giới hạn."); return; } try { using (DBQuanLiHoiNghiEntities db = new DBQuanLiHoiNghiEntities()) { DANGKITHAMGIA dktg = (from dk in db.DANGKITHAMGIAs where dk.IDUSER == DangNhapViewModel.User.IDUSER && dk.IDHN == this.HoiNghi.IDHN select dk).FirstOrDefault(); if (dktg != null && dktg.TRANGTHAI == 1) { MessageBox.Show("Bạn đã bị chặn."); return; } DANGKITHAMGIA dangky = new DANGKITHAMGIA(); dangky.IDHN = this.HoiNghi.IDHN; dangky.IDUSER = DangNhapViewModel.User.IDUSER; dangky.TRANGTHAI = 0; dangky.THOIGIANDK = DateTime.Now; db.DANGKITHAMGIAs.Add(dangky); db.SaveChanges(); } Status = 1; SignUpCommand = new RelayCommand(UnSignUp); } catch { MessageBox.Show("Đã có lỗi xảy ra."); } } }
private void UnSignUp() { if (DangNhapViewModel.User == null) { DangNhapWindow dangNhapWindow = new DangNhapWindow(); dangNhapWindow.Show(); this.Window.Close(); } else { try { using (DBQuanLiHoiNghiEntities db = new DBQuanLiHoiNghiEntities()) { var dky = from dk in db.DANGKITHAMGIAs where dk.IDHN == this.HoiNghi.IDHN && dk.IDUSER == DangNhapViewModel.User.IDUSER select dk; if (dky.Count() > 0) { if (dky.First().TRANGTHAI == 2) { HOINGHI hn = db.HOINGHIs.Where(o => o.IDHN == this.HoiNghi.IDHN).FirstOrDefault(); hn.SOLUONG -= 1; } db.DANGKITHAMGIAs.Remove(dky.First()); db.SaveChanges(); Status = 0; SignUpCommand = new RelayCommand(SignUp); } } } catch { MessageBox.Show("Đã có lỗi xảy ra."); } } }