/// <summary> /// Executes the save command. /// </summary> /// <param name="dto">The dto to save.</param> protected virtual void ExecuteSaveCommand(KeyedDataTransferObject dto) { _editingPart = dto; if (dto != null) { if (!dto.HasErrors || (dto.HasErrors && dto.DataErrorInfoCollection.Where(p => p.DataErrorInfoType == DataErrorInfoType.PropertyLevel).Count() == 0)) { var dtoType = dto.GetType(); var openSaveRequestType = typeof(SaveDtoRequest <>); var closedSaveRequestType = openSaveRequestType.MakeGenericType(dtoType); var saveRequest = Activator.CreateInstance(closedSaveRequestType, dto); var requestDispatcher = _asyncRequestDispatcherFactory.CreateAsyncRequestDispatcher(); requestDispatcher.Add(saveRequest as Request); _editingPart.IsLoading = true; requestDispatcher.ProcessRequests(RequestCompleted, HandleRequestDispatcherException); } else { var errors = dto.DataErrorInfoCollection.Where(p => p.ErrorLevel == ErrorLevel.Error).Select(p => p.ToString()).Aggregate((i, j) => i + Environment.NewLine + j); _userDialogService.ShowDialog(string.Format("Please fix the following errors before trying to save:{0}{1}", Environment.NewLine, errors), "Errors", UserDialogServiceOptions.Ok); } } }
/// <summary> /// Executes the cancel command. /// </summary> /// <param name="dto">The dto to check.</param> protected virtual void ExecuteCancelCommand(KeyedDataTransferObject dto) { if (dto.Key > 0) { _editingPart = dto; var dtoType = dto.GetType(); var openCancelRequestType = typeof(GetDtoRequest <>); var closedCancelRequestType = openCancelRequestType.MakeGenericType(dtoType); var cancelRequest = Activator.CreateInstance(closedCancelRequestType, dto.Key); var requestDispatcher = _asyncRequestDispatcherFactory.CreateAsyncRequestDispatcher(); requestDispatcher.Add(cancelRequest as Request); _editingPart.IsLoading = true; requestDispatcher.ProcessRequests(RequestCompleted, HandleRequestDispatcherException); } else { ExecuteCancelCommandWhenAdding(dto); } }