public ActionResult Edit(SMS.Models.NGUOI_DUNG nguoiDung)
        {
            if (ModelState.IsValid)
            {
                var db        = new SmsContext();
                var nguoidung = db.NGUOI_DUNG.Find((int)nguoiDung.MA_NGUOI_DUNG);
                nguoidung.TEN_NGUOI_DUNG = nguoiDung.TEN_NGUOI_DUNG;
                nguoidung.NGAY_SINH      = nguoiDung.NGAY_SINH;
                nguoidung.SO_CHUNG_MINH  = nguoiDung.SO_CHUNG_MINH;
                nguoidung.DIA_CHI        = nguoiDung.DIA_CHI;
                nguoidung.SO_DIEN_THOAI  = nguoiDung.SO_DIEN_THOAI;
                nguoidung.MA_KHO         = nguoiDung.MA_KHO;
                nguoidung.NGAY_VAO_LAM   = nguoiDung.NGAY_VAO_LAM;

                if (Request.Files[0].InputStream.Length != 0)
                {
                    Stream fileStream = Request.Files[0].InputStream;
                    byte[] bytes      = new byte[fileStream.Length];
                    fileStream.Read(bytes, 0, bytes.Length);
                    nguoidung.HINH_ANH = bytes;
                }
                nguoidung.MA_NHOM_NGUOI_DUNG = nguoiDung.MA_NHOM_NGUOI_DUNG;
                nguoidung.GHI_CHU            = nguoiDung.GHI_CHU;
                nguoidung.EMAIL     = nguoiDung.EMAIL;
                nguoidung.ACTIVE    = "A";
                nguoidung.UPDATE_AT = DateTime.Now;
                nguoidung.UPDATE_BY = (int)Session["UserId"];
                db.SaveChanges();
                return(RedirectToAction("Index").Success("Lưu thành công"));
            }
            var        ctx        = new SmsContext();
            NGUOI_DUNG nguoidung1 = ctx.NGUOI_DUNG.Find((int)nguoiDung.MA_NGUOI_DUNG);

            if (nguoidung1.ACTIVE.Equals("A"))
            {
                //Ma Kho
                BindKho();

                //Ma Nhom
                BindNhomNguoiDung();

                ViewBag.nguoiDung = nguoidung1;
                ctx.Dispose();
                return(View(nguoidung1));
            }
            ctx.Dispose();
            return(View());
        }
        public ActionResult AddNew(SMS.Models.NGUOI_DUNG nguoiDung)
        {
            //var errors = ModelState.Values.SelectMany(v => v.Errors);
            if (ModelState.IsValid)
            {
                var db        = new SmsContext();
                var crypto    = new SimpleCrypto.PBKDF2();
                var nguoidung = db.NGUOI_DUNG.Create();
                nguoidung.TEN_NGUOI_DUNG = nguoiDung.TEN_NGUOI_DUNG;
                nguoidung.NGAY_SINH      = nguoiDung.NGAY_SINH;
                nguoidung.SO_CHUNG_MINH  = nguoiDung.SO_CHUNG_MINH;
                nguoidung.DIA_CHI        = nguoiDung.DIA_CHI;
                nguoidung.SO_DIEN_THOAI  = nguoiDung.SO_DIEN_THOAI;
                nguoidung.EMAIL          = nguoiDung.EMAIL;
                nguoidung.MA_KHO         = nguoiDung.MA_KHO;
                nguoidung.USER_NAME      = nguoiDung.USER_NAME;
                nguoidung.MAT_KHAU       = crypto.Compute(nguoiDung.MAT_KHAU);
                nguoidung.SALT           = crypto.Salt;
                nguoidung.NGAY_VAO_LAM   = nguoiDung.NGAY_VAO_LAM;

                if (Request.Files[0].InputStream.Length != 0)
                {
                    Stream fileStream = Request.Files[0].InputStream;
                    byte[] bytes      = new byte[fileStream.Length];
                    fileStream.Read(bytes, 0, bytes.Length);
                    nguoidung.HINH_ANH = bytes;
                }
                nguoidung.MA_NHOM_NGUOI_DUNG = nguoiDung.MA_NHOM_NGUOI_DUNG;
                nguoidung.GHI_CHU            = nguoiDung.GHI_CHU;
                nguoidung.ACTIVE             = "A";
                nguoidung.UPDATE_AT          = DateTime.Now;
                nguoidung.CREATE_AT          = DateTime.Now;
                nguoidung.UPDATE_BY          = (int)Session["UserId"];
                nguoidung.CREATE_BY          = (int)Session["UserId"];
                db.NGUOI_DUNG.Add(nguoidung);
                db.SaveChanges();
                return(RedirectToAction("Index").Success("Lưu thành công."));
            }
            //Ma Kho
            BindKho();

            //Ma Nhom
            BindNhomNguoiDung();
            return(View());
        }