Example #1
0
        protected void RadGridSiteLocationUser_OnRowDrop(object sender, GridDragDropEventArgs e)
        {
            //if (e.DraggedItems.Count != 0 && RadComboBoxMenu.CheckedItems.Count > 0 && e.DestinationGrid == RadGridSiteLocation)
            if (e.DraggedItems.Count != 0 && RadComboBoxMenu.CheckedItems.Count > 0)
            {
                bool isSuccess = true;

                foreach (var dataItem in e.DraggedItems)
                {
                    if (RadComboBoxMenu.CheckedItems.Count == 1)
                    {
                        var cUserPermission = new CUserPermission();
                        var userPermission  = cUserPermission.Get(Convert.ToInt32(dataItem.GetDataKeyValue("UserPermissionId").ToString()));
                        if (userPermission != null)
                        {
                            if (cUserPermission.Delete(userPermission) == false)
                            {
                                isSuccess = false;
                            }
                        }
                    }
                    else
                    {
                        foreach (var checkedItem in RadComboBoxMenu.CheckedItems)
                        {
                            var cUserPermission = new CUserPermission();
                            // Search Type for siteLocation = 2
                            var userPermission = cUserPermission.Get(Id, Convert.ToInt32(checkedItem.Value), 2, Convert.ToInt32(dataItem.GetDataKeyValue("SiteLocationId").ToString()));
                            if (userPermission != null)
                            {
                                if (cUserPermission.Delete(userPermission) == false)
                                {
                                    isSuccess = false;
                                }
                            }
                        }
                    }
                }

                if (isSuccess)
                {
                    ShowMessage("Move Success");
                }
                else
                {
                    ShowMessage("Move Error");
                }
            }
            else
            {
                ShowMessage("Move Failed");
            }
        }
Example #2
0
        private void SetSave(RadCheckBox checkBox)
        {
            var cUserPermission = new CUserPermission();

            bool isSuccess = true;

            foreach (var checkItem in RadComboBoxMenu.CheckedItems)
            {
                UserPermission userPermissionAccess = cUserPermission.Get(Id, Convert.ToInt32(checkItem.Value), Convert.ToInt32(RadCheckBoxAccess.Value));
                UserPermission userPermissionModify = cUserPermission.Get(Id, Convert.ToInt32(checkItem.Value), Convert.ToInt32(RadCheckBoxModify.Value));

                // Access
                if (checkBox == RadCheckBoxAccess)
                {
                    if (RadCheckBoxAccess.Checked == true)
                    {
                        if (userPermissionAccess == null)
                        {
                            int result = cUserPermission.Add(new UserPermission()
                            {
                                PermissionType = Convert.ToInt32(RadCheckBoxAccess.Value),
                                CreatedDate    = DateTime.Now,
                                CreatedId      = CurrentUserId,
                                UserId         = Id,
                                MenuId         = Convert.ToInt32(checkItem.Value)
                            });
                            if (result < 0)
                            {
                                isSuccess = false;
                            }
                        }
                    }
                    else
                    {
                        if (userPermissionAccess != null)
                        {
                            bool result = cUserPermission.Delete(userPermissionAccess);
                            if (result == false)
                            {
                                isSuccess = false;
                            }
                        }
                    }
                }

                // Modify
                if (checkBox == RadCheckBoxModify)
                {
                    if (RadCheckBoxModify.Checked == true)
                    {
                        if (userPermissionModify == null)
                        {
                            int result = cUserPermission.Add(new UserPermission()
                            {
                                PermissionType = Convert.ToInt32(RadCheckBoxModify.Value),
                                CreatedDate    = DateTime.Now,
                                CreatedId      = CurrentUserId,
                                UserId         = Id,
                                MenuId         = Convert.ToInt32(checkItem.Value)
                            });
                            if (result < 0)
                            {
                                isSuccess = false;
                            }
                        }
                    }
                    else
                    {
                        if (userPermissionModify != null)
                        {
                            bool result = cUserPermission.Delete(userPermissionModify);
                            if (result == false)
                            {
                                isSuccess = false;
                            }
                        }
                    }
                }
            }

            if (isSuccess)
            {
                ShowMessage("It has been updated.");
            }
            else
            {
                ShowMessage("Failed.");
            }
        }