Exemplo n.º 1
0
        public ActionResult Create(DIEN dien)
        {
            if (ModelState.IsValid)
            {
                var dao = new QLDModel();

                if (dao.getByMaDien(dien.MaDien) != null)
                {
                    SetAlert("Mã điện đã tồn tại", "error");
                    return(RedirectToAction("Create", "QLD"));
                }

                String result = dao.Insert(dien);
                if (!String.IsNullOrEmpty(result))
                {
                    SetAlert("Thêm điện thành công", "success");
                    return(RedirectToAction("Index", "QLD"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm điện không thành công");
                }
            }
            return(View());
        }
Exemplo n.º 2
0
 public String Insert(DIEN entityDien)
 {
     db.DIENs.Add(entityDien);
     try { db.SaveChanges(); }
     catch (Exception e)
     {
         Console.WriteLine("Mã phòng không có trong CSDL!", e.Message);
     }
     return(entityDien.MaDien);
 }
Exemplo n.º 3
0
        public ActionResult Edit(DIEN dien)
        {
            if (ModelState.IsValid)
            {
                var dao = new QLDModel();


                var result = dao.Update(dien);
                if (result == true)
                {
                    SetAlert("Cập thông tin điện thành công", "success");
                    return(RedirectToAction("Index", "QLD"));
                }
                else
                {
                    ModelState.AddModelError("", "Cập nhật thông tin điện không thành công");
                }
            }
            return(View());
        }
Exemplo n.º 4
0
        public bool Update(DIEN entityDien)
        {
            try
            {
                var dien = db.DIENs.Select(x => x).Where(x => x.MaDien == entityDien.MaDien).FirstOrDefault();

                dien.MaPhong = entityDien.MaPhong;
                dien.NgayGhi = entityDien.NgayGhi;
                dien.CSD     = entityDien.CSD;
                dien.CSC     = entityDien.CSC;
                dien.DonGia  = entityDien.DonGia;
                db.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Sửa không thành công vui lòng kiểm tra lại!", e.Message);
                return(false);
            }
            return(true);
        }