Exemple #1
0
        public JsonResult LayChiTietTaiKhoan(int id)
        {
            try
            {
                db.Configuration.ProxyCreationEnabled = false;

                var taiKhoan = db.tblNhanViens.Find(id);

                tblChucVu modelChucVu = db.tblChucVus.Where(x => x.ma_chuc_vu == taiKhoan.ma_chuc_vu).SingleOrDefault();

                TaiKhoanViewModel taiKhoanViewModel = new TaiKhoanViewModel();
                taiKhoanViewModel.ID          = taiKhoan.ma_nv;
                taiKhoanViewModel.HoTen       = taiKhoan.ho_ten;
                taiKhoanViewModel.DiaChi      = taiKhoan.dia_chi;
                taiKhoanViewModel.SoDienThoai = taiKhoan.sdt;
                taiKhoanViewModel.TenTaiKhoan = taiKhoan.tai_khoan;
                taiKhoanViewModel.Email       = taiKhoan.mail;
                taiKhoanViewModel.MatKhau     = taiKhoan.mat_khau;
                taiKhoanViewModel.ChucVu      = modelChucVu.chuc_vu;

                return(Json(new
                {
                    data = taiKhoanViewModel,
                    status = true
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception error)
            {
                return(Json(new { status = false, message = error.ToString() }, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #2
0
        public JsonResult LuuTaiKhoan(TaiKhoanViewModel model)
        {
            bool   status  = false;
            string message = string.Empty;

            //tblLoaiPhong modelLoaiPhong = db.tblLoaiPhongs.Where(x => x.mo_ta == model.Type).SingleOrDefault();
            //tblTang modelTang = db.tblTangs.Where(x => x.ten_tang == model.Level).SingleOrDefault();
            tblChucVu modelChucVu = db.tblChucVus.Where(x => x.chuc_vu == model.ChucVu).SingleOrDefault();

            tblNhanVien nhanVien = new tblNhanVien();

            nhanVien.ma_nv                = model.ID;
            nhanVien.ho_ten               = model.HoTen;
            nhanVien.dia_chi              = model.DiaChi;
            nhanVien.sdt                  = model.SoDienThoai;
            nhanVien.tai_khoan            = model.TenTaiKhoan;
            nhanVien.mat_khau             = model.MatKhau;
            nhanVien.ma_chuc_vu           = modelChucVu.ma_chuc_vu;
            nhanVien.trang_thai_tai_khoan = true;
            nhanVien.mail                 = model.Email;

            if (model.ID == 0)
            {
                db.tblNhanViens.Add(nhanVien);
                try
                {
                    db.SaveChanges();
                    status = true;
                }
                catch (Exception ex)
                {
                    status  = false;
                    message = ex.Message;
                }
            }
            else
            {
                //Đang cập nhật dữ liệu
                var entity = db.tblNhanViens.Find(model.ID);
                entity.ho_ten     = model.HoTen;
                entity.dia_chi    = model.DiaChi;
                entity.sdt        = model.SoDienThoai;
                entity.tai_khoan  = model.TenTaiKhoan;
                entity.mat_khau   = model.MatKhau;
                entity.ma_chuc_vu = modelChucVu.ma_chuc_vu;
                entity.mail       = model.Email;

                try
                {
                    db.SaveChanges();
                    status = true;
                }
                catch (Exception ex)
                {
                    status  = false;
                    message = ex.Message;
                }
            }

            return(Json(new
            {
                status = status,
                message = message
            }));
        }