private void btnSubmit_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtID.Text) | string.IsNullOrEmpty(txtPass.Text) | string.IsNullOrEmpty(txtPass2.Text) | string.IsNullOrEmpty(txtFullname.Text))
     {
         MessageBox.Show("Không được để trống các trường");
     }
     else
     {
         if (string.Compare(txtPass.Text, txtPass2.Text) == 0)
         {
             GUEST gNew = new GUEST()
             {
                 guestid       = txtID.Text,
                 guestpassword = txtPass.Text,
                 guestName     = txtFullname.Text
             };
             if (TracNghiem.ThemGuest(gNew))
             {
                 MessageBox.Show("Thêm thành công");
             }
             else
             {
                 MessageBox.Show("Thêm thất bại");
             }
         }
         else
         {
             MessageBox.Show("Mật khẩu nhập lại chưa đúng");
         }
     }
 }
        public ActionResult DeleteConfirmed(int id)
        {
            GUEST gUEST = tpdb.GUESTs.Find(id);

            tpdb.GUESTs.Remove(gUEST);
            tpdb.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "GuestID,FirstName,LastName,DateOfBirth")] GUEST gUEST)
 {
     if (ModelState.IsValid)
     {
         tpdb.Entry(gUEST).State = EntityState.Modified;
         tpdb.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(gUEST));
 }
        public ActionResult Create([Bind(Include = "GuestID,FirstName,LastName,DateOfBirth")] GUEST gUEST)
        {
            if (ModelState.IsValid)
            {
                tpdb.GUESTs.Add(gUEST);
                tpdb.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(gUEST));
        }
        // GET: Guests/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GUEST gUEST = tpdb.GUESTs.Find(id);

            if (gUEST == null)
            {
                return(HttpNotFound());
            }
            return(View(gUEST));
        }
        public static bool ThemGuest(GUEST t)
        {
            bool rt = true;

            using (var httn = new DBTracNghiemDataContext())
            {
                httn.GUESTs.InsertOnSubmit(t);
                try
                {
                    httn.SubmitChanges();
                }
                catch (Exception)
                {
                    rt = false;
                }
            }
            return(rt);
        }
Beispiel #7
0
 public ActionResult Create(GUEST model)
 {
     db.GUESTs.Add(model);
     db.SaveChanges();
     return(RedirectToAction("/Home/Index"));
 }