예제 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            NhomNguoiDung nhomnguoidung = db.NhomNguoiDungs.Find(id);

            db.NhomNguoiDungs.Remove(nhomnguoidung);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
        //3. Xóa Nhóm Người Dùng
        public bool delete_NhomNguoiDung(int idNhom)
        {
            NhomNguoiDung nnd = db.NhomNguoiDungs.Single(p => p.id_nhom_nguoi_dung == idNhom);

            db.NhomNguoiDungs.DeleteOnSubmit(nnd);
            db.SubmitChanges();
            return(true);
        }
예제 #3
0
        //4. Sua Nhom
        public bool update_NhomNguoiDung(int idNhom, string TenNhom)
        {
            NhomNguoiDung nnd = db.NhomNguoiDungs.Single(p => p.id_nhom_nguoi_dung == idNhom);

            nnd.ten_nhom_nguoi_dung = TenNhom;

            db.SubmitChanges();
            return(true);
        }
예제 #4
0
        //2. Thêm Nhóm Người Dùng
        public bool insert_NhomNguoiDung(string TenNhom)
        {
            NhomNguoiDung nnd = new NhomNguoiDung();

            nnd.ten_nhom_nguoi_dung = TenNhom;

            db.NhomNguoiDungs.InsertOnSubmit(nnd);
            db.SubmitChanges();
            return(true);
        }
예제 #5
0
 public ActionResult Edit(NhomNguoiDung nhomnguoidung)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nhomnguoidung).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(nhomnguoidung));
 }
예제 #6
0
        //
        // GET: /NhomNguoiDung/Edit/5


        public ActionResult Edit(int id)
        {
            if (Session["isAdmin"] != null && Session["isAdmin"].ToString() == "1")
            {
                NhomNguoiDung nhomnguoidung = db.NhomNguoiDungs.Find(id);
                return(View(nhomnguoidung));
            }
            TempData["myMessage"] = "Bạn cần đăng nhập bằng tài khoản Admin để xe được trang này (^_^)";
            return(Redirect("~"));
        }
예제 #7
0
        public void ThemNhomNguoiDung(string pMaNhom, string pTenNhom, string pGhiChu)
        {
            NhomNguoiDung nhomNguoiDung = new NhomNguoiDung();

            nhomNguoiDung.MaNhom  = pMaNhom;
            nhomNguoiDung.TenNhom = pTenNhom;
            nhomNguoiDung.GhiChu  = pGhiChu;
            nhakhoa.NhomNguoiDungs.InsertOnSubmit(nhomNguoiDung);
            nhakhoa.SubmitChanges();
        }
예제 #8
0
        public ActionResult Create(NhomNguoiDung nhomnguoidung)
        {
            if (ModelState.IsValid)
            {
                db.NhomNguoiDungs.Add(nhomnguoidung);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(nhomnguoidung));
        }
        public ActionResult LuuHieuChinh(NhomNguoiDung nhomnguoidung)
        {
            NhomNguoiDungService _nhom = new NhomNguoiDungService();
            var nhom = _nhom.InsertOrUpdate(nhomnguoidung);

            return(Json(new
            {
                success = nhom != null,
                data = nhom
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult HieuChinh(int?id)
        {
            NhomNguoiDung nhom = new NhomNguoiDung();

            if (id.HasValue && id.Value > 0)
            {
                NhomNguoiDungService _nhom = new NhomNguoiDungService();
                nhom = _nhom.FindByKey(id.Value);
            }
            return(PartialView("_HieuChinhNhom", nhom));
        }
예제 #11
0
        public bool XoaNhomNguoiDung(string pMaNhom)
        {
            NhomNguoiDung nhomNguoiDung = nhakhoa.NhomNguoiDungs.Where(nnd => nnd.MaNhom == pMaNhom).FirstOrDefault();

            if (nhomNguoiDung != null)
            {
                nhakhoa.NhomNguoiDungs.DeleteOnSubmit(nhomNguoiDung);
                nhakhoa.SubmitChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public ActionResult Them(FormCollection collection)
 {
     if (SessionManager.CheckSession(ConstantValues.SessionKeyCurrentUser))
     {
         NotifyModel thongBao = new NotifyModel();
         try
         {
             if (!string.IsNullOrEmpty(collection["save"].ToString()))
             {
                 NhomNguoiDung nhomNguoiDung = new NhomNguoiDung();
                 nhomNguoiDung.Ten     = collection["ten"].ToString();
                 nhomNguoiDung.MoTa    = collection["moTa"].ToString();
                 nhomNguoiDung.IdDonVi = collection["donVi"].ToString();
                 //nguoi dung chi co the phan quyen nhung chuc nang ma ho co
                 var chucNangList = collection["chucNang"].Split(',');
                 nhomNguoiDung.DanhSachChucNang = chucNangList.ToList();
                 nhomNguoiDung.IdNguoiTao       = currentUser.Id.ToString();
                 nhomNguoiDung.IdNguoiCapNhat   = currentUser.Id.ToString();
                 if (xlNhomNguoiDung.Ghi(nhomNguoiDung))
                 {
                     thongBao.TypeNotify = "alert-success";
                     thongBao.Message    = "Thêm thành công";
                 }
                 else
                 {
                     thongBao.TypeNotify = "alert-danger";
                     thongBao.Message    = "Thêm thất bại!";
                 }
             }
         }
         catch (Exception)
         {
             thongBao.TypeNotify = "alert-danger";
             thongBao.Message    = "Thêm thất bại!";
         }
         ViewBag.ThongBao = thongBao;
         var model = new NhomNguoiDungModel();
         model.DanhSachDonVi    = xlDonVi.DocDanhSachTuDonViCha(currentUser.IdDonVi, (bool)Session[ConstantValues.SessionKeyVaiTro]);
         model.DanhSachChucNang = DocDanhSachChucNang();
         return(View("Them", model));
     }
     if (Request.Url != null)
     {
         SessionManager.RegisterSession(ConstantValues.SessionKeyUrl, Request.Url.AbsolutePath);
     }
     return(RedirectToAction("Index", "Login"));
 }
예제 #13
0
        //
        // GET: /NhomNguoiDung/Details/5

        public ViewResult Details(int id)
        {
            NhomNguoiDung nhomnguoidung = db.NhomNguoiDungs.Find(id);

            return(View(nhomnguoidung));
        }
예제 #14
0
 public ActionResult ChinhSua(FormCollection collection)
 {
     if (SessionManager.CheckSession(ConstantValues.SessionKeyCurrentUser))
     {
         NotifyModel thongBao = new NotifyModel();
         string      id       = collection["nguoiDungId"].ToString();
         if (string.IsNullOrEmpty(id))
         {
             return(RedirectToAction("Index", "NguoiDung"));
         }
         NguoiDung nguoiDung = xlNguoiDung.Doc(id);
         try
         {
             if (!string.IsNullOrEmpty(collection["save"].ToString()))
             {
                 int kichHoat = 0;
                 if (collection["kich_hoat"] != null && !string.IsNullOrEmpty(collection["kich_hoat"].ToString()) && collection["kich_hoat"].ToString() == "on")
                 {
                     kichHoat = 1;
                 }
                 nguoiDung.Ten       = collection["ten"].ToString();
                 nguoiDung.Email     = collection["email"].ToString();
                 nguoiDung.DienThoai = collection["dienThoai"].ToString();
                 nguoiDung.IdVaiTro  = collection["vaiTro"].ToString();
                 nguoiDung.IdDonVi   = collection["donVi"].ToString();
                 var           nhomNguoiDungIds = collection["nhomNguoiDung"].Split(',');
                 List <string> nndIdList        = nhomNguoiDungIds.ToList();
                 nguoiDung.DanhSachNhom = nndIdList;
                 List <string> dsChucNang = nguoiDung.DanhSachChucNang;
                 foreach (var nndId in nndIdList)
                 {
                     NhomNguoiDung nhomNguoiDung = xlNhomNguoiDung.Doc(nndId);
                     foreach (var cn in nhomNguoiDung.DanhSachChucNang)
                     {
                         if (!dsChucNang.Contains(cn))
                         {
                             dsChucNang.Add(cn);
                         }
                     }
                 }
                 nguoiDung.DanhSachChucNang = dsChucNang;
                 nguoiDung.KichHoat         = kichHoat;
                 nguoiDung.IdNguoiCapNhat   = currentUser.Id.ToString();
                 if (xlNguoiDung.CapNhat(nguoiDung))
                 {
                     thongBao.TypeNotify = "alert-success";
                     thongBao.Message    = "Chỉnh sửa thông tin thành công";
                 }
                 else
                 {
                     thongBao.TypeNotify = "alert-danger";
                     thongBao.Message    = "Chỉnh sửa thông tin thất bại!";
                 }
             }
         }
         catch (Exception)
         {
             thongBao.TypeNotify = "alert-danger";
             thongBao.Message    = "Chỉnh sửa thông tin thất bại!";
         }
         ViewBag.ThongBao = thongBao;
         var model = new NguoiDungModel();
         model.DanhSachVaiTro        = DocDanhSachVaiTro();
         model.DanhSachDonVi         = DocDanhSachDonVi();
         model.DanhSachNhomNguoiDung = DocDanhSachNhomNguoiDung();
         model.NguoiDungHienTai      = nguoiDung;
         return(View("ChinhSua", model));
     }
     if (Request.Url != null)
     {
         SessionManager.RegisterSession(ConstantValues.SessionKeyUrl, Request.Url.AbsolutePath);
     }
     return(RedirectToAction("Index", "Login"));
 }
예제 #15
0
        public ActionResult Them(FormCollection collection)
        {
            if (SessionManager.CheckSession(ConstantValues.SessionKeyCurrentUser))
            {
                NotifyModel thongBao  = new NotifyModel();
                NguoiDung   nguoiDung = new NguoiDung();
                try
                {
                    if (!string.IsNullOrEmpty(collection["save"].ToString()))
                    {
                        string tenDangNhap = collection["tenDangNhap"].ToString();
                        int    kichHoat    = 0;
                        if (collection["kich_hoat"] != null && !string.IsNullOrEmpty(collection["kich_hoat"].ToString()) && collection["kich_hoat"].ToString() == "on")
                        {
                            kichHoat = 1;
                        }
                        nguoiDung.Ten         = collection["ten"].ToString();
                        nguoiDung.TenDangNhap = tenDangNhap;
                        nguoiDung.setMatKhau(collection["matKhau"].ToString());

                        nguoiDung.Email     = collection["email"].ToString();
                        nguoiDung.DienThoai = collection["dienThoai"].ToString();

                        nguoiDung.IdVaiTro = collection["vaiTro"].ToString();
                        nguoiDung.IdDonVi  = collection["donVi"].ToString();
                        string        nhomNguoiDungIds = collection["nhomNguoiDung"].ToString();
                        List <string> nndIdList        = nhomNguoiDungIds.Split(',').ToList();
                        nguoiDung.DanhSachNhom = nndIdList;
                        List <string> dsChucNang = new List <string>();
                        foreach (var nndId in nndIdList)
                        {
                            NhomNguoiDung nhomNguoiDung = xlNhomNguoiDung.Doc(nndId);
                            foreach (var cn in nhomNguoiDung.DanhSachChucNang)
                            {
                                if (!dsChucNang.Contains(cn))
                                {
                                    dsChucNang.Add(cn);
                                }
                            }
                        }
                        nguoiDung.DanhSachChucNang = dsChucNang;
                        nguoiDung.KichHoat         = kichHoat;
                        nguoiDung.IdNguoiTao       = currentUser.Id.ToString();
                        nguoiDung.IdNguoiCapNhat   = currentUser.Id.ToString();
                        var nguoiDungExists = xlNguoiDung.DocDanhSach(nd => nd.TenDangNhap == tenDangNhap);
                        if (nguoiDungExists.Count() > 0)
                        {
                            thongBao.TypeNotify = "alert-danger";
                            thongBao.Message    = "Tên người dùng đã tồn tại! Thêm thất bại!";
                        }
                        else
                        {
                            if (xlNguoiDung.Ghi(nguoiDung))
                            {
                                thongBao.TypeNotify = "alert-success";
                                thongBao.Message    = "Thêm thành công";
                                nguoiDung           = new NguoiDung();
                            }
                            else
                            {
                                thongBao.TypeNotify = "alert-danger";
                                thongBao.Message    = "Thêm thất bại!";
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    thongBao.TypeNotify = "alert-danger";
                    thongBao.Message    = "Thêm thất bại!";
                }
                ViewBag.ThongBao = thongBao;
                var model = new NguoiDungModel();
                model.DanhSachVaiTro        = DocDanhSachVaiTro();
                model.DanhSachDonVi         = DocDanhSachDonVi();
                model.DanhSachNhomNguoiDung = DocDanhSachNhomNguoiDung();
                model.NguoiDungHienTai      = nguoiDung;
                return(View("Them", model));
            }
            if (Request.Url != null)
            {
                SessionManager.RegisterSession(ConstantValues.SessionKeyUrl, Request.Url.AbsolutePath);
            }
            return(RedirectToAction("Index", "Login"));
        }
        public ActionResult ChinhSua(FormCollection collection)
        {
            if (SessionManager.CheckSession(ConstantValues.SessionKeyCurrentUser))
            {
                if (!string.IsNullOrEmpty(collection["save"].ToString()))
                {
                    string id = collection["nhomNguoiDungId"].ToString();
                    if (string.IsNullOrEmpty(id))
                    {
                        return(RedirectToAction("Index", "NhomNguoiDung"));
                    }
                    var           model         = new NhomNguoiDungModel();
                    NhomNguoiDung nhomNguoiDung = xlNhomNguoiDung.Doc(id);
                    model.NhomNguoiDungHienTai = nhomNguoiDung;
                    if (nhomNguoiDung == null)
                    {
                        return(RedirectToAction("Index", "NhomNguoiDung"));
                    }
                    NotifyModel thongBao = new NotifyModel();
                    var         user     = (NguoiDung)SessionManager.ReturnSessionObject(ConstantValues.SessionKeyCurrentUser);
                    try
                    {
                        nhomNguoiDung.Ten     = collection["ten"].ToString();
                        nhomNguoiDung.MoTa    = collection["moTa"].ToString();
                        nhomNguoiDung.IdDonVi = collection["donVi"].ToString();
                        //nguoi dung chi co the phan quyen nhung chuc nang ma ho co
                        if (collection["chucNang"] != null)
                        {
                            var chucNangList = collection["chucNang"].Split(',');
                            nhomNguoiDung.DanhSachChucNang = chucNangList.ToList();
                        }
                        else
                        {
                            nhomNguoiDung.DanhSachChucNang = new List <string>();
                        }

                        nhomNguoiDung.IdNguoiCapNhat = user.Id.ToString();
                        if (xlNhomNguoiDung.CapNhat(nhomNguoiDung))
                        {
                            thongBao.TypeNotify = "alert-success";
                            thongBao.Message    = "Cập nhật thông tin thành công";
                        }
                        else
                        {
                            thongBao.TypeNotify = "alert-danger";
                            thongBao.Message    = "Cập nhật thông tin thất bại!";
                        }
                    }
                    catch (Exception)
                    {
                        thongBao.TypeNotify = "alert-danger";
                        thongBao.Message    = "Cập nhật thông tin thất bại!";
                    }

                    ViewBag.ThongBao       = thongBao;
                    model.DanhSachDonVi    = xlDonVi.DocDanhSachTuDonViCha(user.IdDonVi, (bool)Session[ConstantValues.SessionKeyVaiTro]);
                    model.DanhSachChucNang = DocDanhSachChucNang();
                    return(View("ChinhSua", model));
                }
                return(RedirectToAction("Index", "NhomNguoiDung"));
            }
            if (Request.Url != null)
            {
                SessionManager.RegisterSession(ConstantValues.SessionKeyUrl, Request.Url.AbsolutePath);
            }
            return(RedirectToAction("Index", "Login"));
        }