public static PhotoComment ToPhotoComment(this PhotoCommentPO po) { PhotoComment result = new PhotoComment(); result.Id = po.Id; result.PhotoId = po.PhotoId; result.AlbumId = po.AlbumId; result.Contents = po.Contents; result.CreatedBy = po.CreatedBy; result.CreatedOn = po.CreatedOn; return result; }
void PostComment(string contents) { if (IsLoadingComments) return; CanPostComment = false; PhotoComment comment = new PhotoComment(); comment.Contents = contents; comment.CreatedBy = SecurityContext.Current.User.Name; comment.PhotoId = Id; comment.AlbumId = AlbumId; PhotoServiceClient svc = new PhotoServiceClient(); try { svc.CreateCommentCompleted += (sender, e) => { if (e.Error != null) { e.Error.Handle(); } else { if (_comments != null) { _comments.Insert(0, MapToPhotoCommentViewModel(e.Result)); } } CanPostComment = true; CommentContents = string.Empty; NotifyOfPropertyChange(() => HasComment); }; svc.CreateCommentAsync(comment); } catch { CanPostComment = true; } }
PhotoCommentViewModel MapToPhotoCommentViewModel(PhotoComment photoComment) { return new PhotoCommentViewModel() { Id = photoComment.Id, CreatedBy = photoComment.CreatedBy, CreatedOn = photoComment.CreatedOn, Contents = photoComment.Contents }; }
public PhotoComment CreateComment(PhotoComment comment) { PhotoComment result = null; ServiceSupport.AuthorizeAndExecute(() => { result = PhotoRepository.CreateComment(comment); }); return result; }