Пример #1
0
        void btnSave_Click(object sender, RoutedEventArgs e)
        {
            List <AspRole> saveList = (List <AspRole>)gvwRole.ItemsSource;

            //Check valid data : Name should not be duplicated
            if (saveList != null && saveList.Count > 0)
            {
                for (int i = 0; i < saveList.Count - 1; i++)
                {
                    AspRole firstItem = saveList[i];
                    for (int j = i + 1; j < saveList.Count; j++)
                    {
                        AspRole secondItem = saveList[j];
                        if (firstItem.RoleName == secondItem.RoleName)
                        {
                            MessageBox.Show(ResourceHelper.GetReourceValue("RoleAdminPage_DuplicatedName"), ResourceHelper.GetReourceValue("Common_ValidationError"), MessageBoxButton.OK);
                            return;
                        }
                    }
                }
            }

            //Get delete items :
            foreach (AspRole oldItem in _originalItemSource)
            {
                bool isDeleted = true;
                foreach (AspRole saveItem in saveList)
                {
                    if (saveItem.RoleId == oldItem.RoleId)
                    {
                        isDeleted = false;
                        break;
                    }
                }
                if (isDeleted)
                {
                    oldItem.IsDeleted = true;
                    saveList.Add(oldItem);
                }
            }
            Globals.IsBusy = true;
            DataServiceHelper.SaveAspRoleAsync(saveList, Globals.UserLogin.UserName, SaveRoleCompleted);
        }