// For DeleteCommand
        public override void Delete()
        {
            if (CurrentCourseViewModel == null)
            {
                ModernDialog.ShowMessage("请选择一个课程。", "操作警告", MessageBoxButton.OK);
                return;
            }

            if (ModernDialog.ShowMessage("确定删除当前课程?", "删除警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                if (_courseDataAccessor.Delete(Mapper.Map <Course>(CurrentCourseViewModel)))
                {
                    var currentIndex = CourseViewModels.IndexOf(CurrentCourseViewModel);
                    CourseViewModels.Remove(CurrentCourseViewModel);

                    if (currentIndex > 0)
                    {
                        CurrentCourseViewModel = CourseViewModels[currentIndex - 1];
                    }
                    else if (CourseViewModels.Count > 0)
                    {
                        CurrentCourseViewModel = CourseViewModels[0];
                    }

                    Message = "删除课程成功";
                }
            }
        }
Ejemplo n.º 2
0
 private void Rollback()
 {
     if (Action == ViewModelAction.Add)
     {
         CourseViewModels.Remove(CourseViewModel);
     }
     else if (Action == ViewModelAction.Edit)
     {
         var course = _courseDataAccessor.GetByKey(CourseViewModel.ModelId);
         Mapper.Map(course, CourseViewModel);
     }
 }