Beispiel #1
0
 public bool DeleteKHOATHI(int id)
 {
     try
     {
         KHOATHI u = dataContext.KHOATHIs.Single(p => p.id == id);
         dataContext.KHOATHIs.Remove(u);
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Debug.WriteLine("- Entity of type \"{0}\", in state \"{1}\" has the following validation errors: ", eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
             }
         }
         return(false);
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
         return(false);
     }
     return(true);
 }
Beispiel #2
0
 public bool UpdateKHOATHI(KHOATHI KHOATHIDAO)
 {
     try
     {
         KHOATHI u = dataContext.KHOATHIs.Where(p => p.id == KHOATHIDAO.id).SingleOrDefault();
         u.MaKhoaThi  = KHOATHIDAO.MaKhoaThi;
         u.TenKhoaThi = KHOATHIDAO.TenKhoaThi;
         u.TrangThai  = KHOATHIDAO.TrangThai;
         dataContext.SaveChanges();
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Debug.WriteLine("- Entity of type \"{0}\", in state \"{1}\" has the following validation errors: ", eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
             }
         }
         return(false);
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
         return(false);
     }
     return(true);
 }
Beispiel #3
0
 public bool AddKHOATHI(KHOATHI KHOATHI)
 {
     try
     {
         dataContext.KHOATHIs.Add(KHOATHI);
         dataContext.SaveChanges();
     }
     catch (DbUpdateException e)
     {
         Debug.WriteLine(e.ToString());
         return(false);
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Debug.WriteLine("- Entity of type \"{0}\", in state \"{1}\" has the following validation errors: ", eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage);
             }
         }
         return(false);
     }
     return(true);
 }
        public ActionResult Create(KHOATHI p)
        {
            bool idPHONG = false;

            if (ModelState.IsValid)
            {
                var dao = new KHOATHIDAO();
                idPHONG = dao.AddKHOATHI(p);
            }

            return(Json(idPHONG, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit(KHOATHI sub)
        {
            bool kq = false;

            if (ModelState.IsValid)
            {
                var dao = new KHOATHIDAO();

                if (dao.UpdateKHOATHI(sub))
                {
                    kq = true;
                }
                else
                {
                    kq = false;
                }
            }

            return(Json(kq, JsonRequestBehavior.AllowGet));
        }