Esempio n. 1
0
        public ActionResult SaveRegist(String groupName, int[] moduleDanhMuc, int[] moduleTinTuc, int[] moduleVanBan, int[] moduleMedia, int[] moduleCuuSinhVien, int[] moduleNguoiDung, int[] moduleHeThong, int[] moduleDiemThi)
        {
            if (Session.getCurrentUser() == null)
                return Redirect("/admin/account/logon");
            if (!SercurityServices.HasPermission((int)TypeModule.MODULE_NGUOIDUNG, Session.getCurrentUser().username, TypeAudit.GroupUser))
            {
                return Redirect("/admin/error/error403");
            }
            gov_group groupInfo = new gov_group();
            groupInfo.hidden_flg = false;
            groupInfo.group_name = groupName;
            groupInfo.entry_username = Session.getCurrentUser().username;
            groupInfo.entry_datetime = DateTime.Now;
            groupInfo.update_username = Session.getCurrentUser().username;
            groupInfo.update_datetime = DateTime.Now;
            groupInfo = _cnttDB.gov_group.Add(groupInfo);
            int rs = _cnttDB.SaveChanges();
            if (rs > 0)
            {
                //Them moi quyen cho module danh muc
                int permissionNumber = 0;
                if (moduleDanhMuc != null)
                {
                    foreach (var permission in moduleDanhMuc)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 1;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module Tin tuc
                permissionNumber = 0;
                if (moduleTinTuc != null)
                {
                    foreach (var permission in moduleTinTuc)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 2;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module Van Ban
                permissionNumber = 0;
                if (moduleVanBan != null)
                {
                    foreach (var permission in moduleVanBan)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 3;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module Media
                permissionNumber = 0;
                if (moduleMedia != null)
                {
                    foreach (var permission in moduleMedia)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 4;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module Cuu Sinh Vien
                permissionNumber = 0;
                if(moduleCuuSinhVien != null){
                    foreach (var permission in moduleCuuSinhVien)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 8;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module Nguoi Dung
                permissionNumber = 0;
                if (moduleNguoiDung != null)
                {
                    foreach (var permission in moduleNguoiDung)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 6;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module He thong
                permissionNumber = 0;
                if (moduleHeThong != null)
                {
                    foreach (var permission in moduleHeThong)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 7;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module Diem Thi
                permissionNumber = 0;
                if (moduleDiemThi != null)
                {
                    foreach (var permission in moduleDiemThi)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 9;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }
                if (rs > 0)
                {
                    TempData["message"] = "Thêm mới thành công!";
                    insertHistory(AccessType.themMoiGroup, Constant.THEM(Constant.ITEM_GROUP, Constant.ID, groupInfo.id.ToString()));
                }
                else
                {
                    TempData["err"] = "Thêm mới thất bại!";
                }
                
            }
            return Redirect("Index");
        }
Esempio n. 2
0
        public ActionResult SaveEdit(int id, String groupName, int[] moduleDanhMuc, int[] moduleTinTuc, int[] moduleVanBan, int[] moduleMedia, int[] moduleCuuSinhVien, int[] moduleNguoiDung, int[] moduleHeThong, int[] moduleDiemThi)
        {
            if (Session.getCurrentUser() == null)
                return Redirect("/admin/account/logon");
            if (!SercurityServices.HasPermission((int)TypeModule.MODULE_NGUOIDUNG, Session.getCurrentUser().username, TypeAudit.GroupUser))
            {
                return Redirect("/admin/error/error403");
            }
            gov_group groupInfo = new gov_group();
            groupInfo = _cnttDB.gov_group.Find(id);
            groupInfo.group_name = groupName;
            groupInfo.update_username = Session.getCurrentUser().username;
            groupInfo.update_datetime = DateTime.Now;
            int rs = _cnttDB.SaveChanges();

            List<gov_group_permission> lstPermission = _cnttDB.gov_group_permission.Where(g => g.group_id == id).ToList();
            foreach (var item in lstPermission)
            {
                _cnttDB.gov_group_permission.Remove(item);
                _cnttDB.SaveChanges();
            }
            {
                //Them moi quyen cho module danh muc
                int permissionNumber = 0;
                if (moduleDanhMuc != null)
                {
                    foreach (var permission in moduleDanhMuc)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 1;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module Tin tu
                permissionNumber = 0;
                if (moduleTinTuc != null)
                {
                    foreach (var permission in moduleTinTuc)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 2;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module Van Ban
                permissionNumber = 0;
                if (moduleVanBan != null)
                {
                    foreach (var permission in moduleVanBan)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 3;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module Media
                permissionNumber = 0;
                if (moduleMedia != null)
                {
                    foreach (var permission in moduleMedia)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 4;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module Cuu Sinh Vien
                permissionNumber = 0;
                if (moduleCuuSinhVien != null)
                {
                    foreach (var permission in moduleCuuSinhVien)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 8;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module Nguoi Dung
                permissionNumber = 0;
                if (moduleNguoiDung != null)
                {
                    foreach (var permission in moduleNguoiDung)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 6;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module He thong
                permissionNumber = 0;
                if (moduleHeThong != null)
                {
                    foreach (var permission in moduleHeThong)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 7;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }

                //Them moi quyen cho module Diem Thi
                permissionNumber = 0;
                if (moduleDiemThi != null)
                {
                    foreach (var permission in moduleDiemThi)
                    {
                        permissionNumber += permission;
                    }
                }
                if (permissionNumber > 0)
                {
                    gov_group_permission groupPermission = new gov_group_permission();
                    groupPermission.module_id = 9;
                    groupPermission.group_id = groupInfo.id;
                    groupPermission.permission_number = permissionNumber;
                    groupPermission.update_datetime = DateTime.Now;
                    groupPermission.update_username = Session.getCurrentUser().username;
                    _cnttDB.gov_group_permission.Add(groupPermission);
                    _cnttDB.SaveChanges();
                }
                if (rs > 0)
                {
                    TempData["message"] = "Cập nhật thông tin thành công!";
                    insertHistory(AccessType.chinhSuaGroup, Constant.CHINHSUA(Constant.ITEM_GROUP, Constant.ID, groupInfo.id.ToString()));
                }
                else
                {
                    TempData["err"] = "Cập nhật thông tin thất bại!";
                }
                
            }
            return Redirect("Index");
        }