private void CurrentItemChanged(Requirement requirement)
 {
   if (requirement != null)
   {
     requirement.AddCommentCommand = new DelegateCommand<Requirement>(AddComment);
     requirement.UpdateCommentCommand = new DelegateCommand<Requirement>(UpdateComment);
     requirement.DeleteCommentCommand = new DelegateCommand<Requirement>(DeleteComment);
     if (Cache.ContainsKey(requirement.Id))
       requirement.Comments = Cache[requirement.Id];
     else
       LoadComment();
   }
   command = new RequirementCrud(requirement, Load);
   NotifyOfPropertyChange(() => Command);
   NotifyOfPropertyChange(() => Visibility);
 }
 private void UpdateComment(Requirement requirement)
 {
   var comment = requirement.Comments.CurrentItem;
   if (comment == null || requirements.CurrentItem == null)
     return;
   if (!comment.CreateUserID.Equals(HomeViewModel.Instance.CurrentUserID))
   {
     MessageBox.Show("不是你的评论不能修改及删除!");
     return;
   }
   var c = comment.ToString().Load<Comment>();
   var viewModel = new CommentEditWindow(c);
   DialogWindowHelper.ShowDialogWindow(viewModel, result =>
   {
     if (result)
     {
       IWriteService service = new WcfClientAddressBase<WriteServiceClient>("../WriteService.svc").GetService();
       service.BeginUpdateComment(viewModel.Data.ToString(), requirements.CurrentItem.Id,
         ThreadHelper.SyncContextCallback(ar => Globals.ProcessAsyncServiceData(() =>
         {
           string message = service.EndUpdateComment(ar);
           if (string.IsNullOrEmpty(message))
             LoadComment();
           else
             MessageBox.Show(message);
         })), null);
     }
   });
 }
 private void DeleteComment(Requirement requirement)
 {
   var comment = requirement.Comments.CurrentItem;
   if (comment == null || requirements.CurrentItem == null)
     return;
   if (!comment.CreateUserID.Equals(HomeViewModel.Instance.CurrentUserID))
   {
     MessageBox.Show("不是你的评论不能修改及删除!");
     return;
   }
   if (Utils.DeleteMessage("评论及意见"))
   {
     IWriteService service = new WcfClientAddressBase<WriteServiceClient>("../WriteService.svc").GetService();
     service.BeginDeleteComment(comment.ToString(), requirements.CurrentItem.Id,
       ThreadHelper.SyncContextCallback(ar => Globals.ProcessAsyncServiceData(() =>
       {
         string message = service.EndDeleteComment(ar);
         if (string.IsNullOrEmpty(message))
           LoadComment();
         else
           MessageBox.Show(message);
       })), null);
   }
 }
 private void AddComment(Requirement requirement)
 {
   if (requirement == null)
     return;
   var c = new Comment
   {
     CreateUserID = HomeViewModel.Instance.CurrentUserID,
     CreateUserName = HomeViewModel.Instance.CurrentUser.Name
   };
   var viewModel = new CommentEditWindow(c);
   DialogWindowHelper.ShowDialogWindow(viewModel, result =>
   {
     if (result)
     {
       #region save to service
       IWriteService service = new WcfClientAddressBase<WriteServiceClient>("../WriteService.svc").GetService();
       service.BeginInsertComment(viewModel.Data.ToString(), requirement.Id,
         ThreadHelper.SyncContextCallback(ar => Globals.ProcessAsyncServiceData(() =>
         {
           string message = service.EndInsertComment(ar);
           if (string.IsNullOrEmpty(message))
             LoadComment();
           else
             MessageBox.Show(message);
         })), null);
       #endregion
     }
   });
 }