Пример #1
0
    protected void btn_add_Click(object sender, EventArgs e)
    {
        Admin admin = ReceiveHtml();

        try
        {
            AdminBSO adminBSO = new AdminBSO();
            if (adminBSO.CheckExist(admin.AdminName))
            {
                error.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Tài khoản đã được đăng ký. Vui lòng đăng ký lại !</div>";
            }
            else
            if (adminBSO.CheckExistEmail(admin.AdminEmail))
            {
                error.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Địa chỉ Email đã được đăng ký. Vui lòng đăng ký lại !</div>";
            }
            else
            {
                if (CheckedList().Equals(""))
                {
                    error.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Lỗi: Phải lựa chọn ít nhất 1 quyền !</div>";
                }
                else
                {
                    int id = adminBSO.CreateAdmin(admin);

                    RolesBSO      rolesBSO      = new RolesBSO();
                    IRoles        roles         = rolesBSO.GetRolesByName("Guest");
                    AdminRolesBSO adminRolesBSO = new AdminRolesBSO();
                    AdminRoles    adminRoles    = new AdminRoles();

                    adminRoles.AdminUserName = admin.AdminName;
                    adminRoles.RolesID       = roles.RolesID;
                    adminRoles.UserName      = Session["Admin_UserName"].ToString();
                    adminRoles.Permission    = "";
                    adminRoles.Created       = DateTime.Now;
                    adminRolesBSO.CreateAdminRoles(adminRoles);

                    error.Text = "<div class='alert alert-sm alert-danger bg-gradient'>Thêm mới thành công !</div>";
                    initControl(id);
                }
            }
        }
        catch (Exception ex)
        {
            error.Text = ex.Message.ToString();
        }
    }
    protected void btnCreateUser_Click(object sender, EventArgs e)
    {
        OrganizationService  comBSO = new OrganizationService();
        IList <Organization> list   = new List <Organization>();

        list = comBSO.FindAll();
        SecurityBSO   securityBSO   = new SecurityBSO();
        AdminRolesBSO adminRolesBSO = new AdminRolesBSO();
        AdminBSO      adminBSO      = new AdminBSO();
        Utils         objUtil       = new Utils();

        foreach (Organization org in list)
        {
            Admin admin = new Admin();

            admin.AdminLoginType = false;
            admin.AdminPass      = securityBSO.EncPwd("123456");
            admin.AdminName      = "SCT." + Utils.UCS2Convert(org.Title).Replace(" ", "").Replace("-", "").ToUpper();;
            admin.AdminEmail     = org.Email;

            //}


            // admin.RolesID = (ddlRoles.SelectedValue != "") ? Convert.ToInt32(ddlRoles.SelectedValue) : 0;
            admin.RolesID       = 1;
            admin.AdminActive   = true;
            admin.AdminFullName = "Sở công thương" + org.Title;

            admin.AdminCreated = DateTime.Now;
            admin.AdminLog     = DateTime.Now;
            //admin.AdminPermission = "";
            admin.AdminPermission = "Read,";

            admin.AdminAddress   = "";
            admin.AdminPhone     = org.Phone;
            admin.AdminNickYahoo = "";
            admin.AdminNickSkype = "";
            admin.AdminAvatar    = "";
            admin.AdminSex       = true;
            IFormatProvider culture = new System.Globalization.CultureInfo("en-US", true);
            admin.AdminBirth = DateTime.Now;
            if (org.Email != null && org.Email != "")
            {
                admin.AdminEmail = org.Email;
            }
            else
            {
                admin.AdminEmail = "sct" + "@" + admin.AdminName.ToLower() + ".gov.vn";
            }

            admin.AdminOrganizationId = org.Id;
            int id = adminBSO.CreateAdmin(admin);

            AdminRoles adminRoles = new AdminRoles();
            adminRoles.RolesID       = 14;
            adminRoles.AdminUserName = admin.AdminName;
            adminRoles.UserName      = Session["Admin_UserName"].ToString();
            //adminRoles.Permission = subrow["Permission"].ToString();
            adminRoles.Permission = "";
            adminRoles.Created    = DateTime.Now;

            adminRolesBSO.CreateAdminRoles(adminRoles);
        }
    }