1010using CodeFramework . Core . ViewModels ;
1111using CodeHub . Core . Messages ;
1212
13- namespace CodeHub . Core . ViewModels . PullRequests
13+ namespace CodeHub . Core . ViewModels . PullRequests
1414{
15- public class PullRequestViewModel : LoadableViewModel
15+ public class PullRequestViewModel : LoadableViewModel
1616 {
1717 private MvxSubscriptionToken _issueEditSubscription ;
1818 private MvxSubscriptionToken _pullRequestEditSubscription ;
1919
20- public long Id
20+ public long Id
2121 {
2222 get ;
2323 private set ;
2424 }
2525
26- public string Username
26+ public string Username
2727 {
2828 get ;
2929 private set ;
3030 }
3131
32- public string Repository
32+ public string Repository
3333 {
3434 get ;
3535 private set ;
@@ -41,37 +41,58 @@ public string MarkdownDescription
4141 }
4242
4343 private bool _merged ;
44+
4445 public bool Merged
4546 {
4647 get { return _merged ; }
47- set { _merged = value ; RaisePropertyChanged ( ( ) => Merged ) ; }
48+ set
49+ {
50+ _merged = value ;
51+ RaisePropertyChanged ( ( ) => Merged ) ;
52+ }
4853 }
4954
5055 private IssueModel _issueModel ;
56+
5157 public IssueModel Issue
5258 {
5359 get { return _issueModel ; }
54- set { _issueModel = value ; RaisePropertyChanged ( ( ) => Issue ) ; }
60+ set
61+ {
62+ _issueModel = value ;
63+ RaisePropertyChanged ( ( ) => Issue ) ;
64+ }
5565 }
5666
5767 private PullRequestModel _model ;
58- public PullRequestModel PullRequest
68+
69+ public PullRequestModel PullRequest
5970 {
6071 get { return _model ; }
61- set { _model = value ; RaisePropertyChanged ( ( ) => PullRequest ) ; }
72+ set
73+ {
74+ _model = value ;
75+ RaisePropertyChanged ( ( ) => PullRequest ) ;
76+ }
6277 }
6378
6479 private bool _isModifying ;
80+
6581 public bool IsModifying
6682 {
6783 get { return _isModifying ; }
68- set { _isModifying = value ; RaisePropertyChanged ( ( ) => IsModifying ) ; }
84+ set
85+ {
86+ _isModifying = value ;
87+ RaisePropertyChanged ( ( ) => IsModifying ) ;
88+ }
6989 }
7090
7191 private ICommand _goToAssigneeCommand ;
92+
7293 public ICommand GoToAssigneeCommand
7394 {
74- get
95+ get
7596 {
7697 if ( _goToAssigneeCommand == null )
7798 {
@@ -90,9 +111,10 @@ public ICommand GoToAssigneeCommand
90111 }
91112
92113 private ICommand _goToMilestoneCommand ;
114+
93115 public ICommand GoToMilestoneCommand
94116 {
95- get
117+ get
96118 {
97119 if ( _goToMilestoneCommand == null )
98120 {
@@ -111,9 +133,10 @@ public ICommand GoToMilestoneCommand
111133 }
112134
113135 private ICommand _goToLabelsCommand ;
136+
114137 public ICommand GoToLabelsCommand
115138 {
116- get
139+ get
117140 {
118141 if ( _goToLabelsCommand == null )
119142 {
@@ -133,16 +156,18 @@ public ICommand GoToLabelsCommand
133156
134157 public ICommand GoToEditCommand
135158 {
136- get
159+ get
137160 {
138- return new MvxCommand ( ( ) => {
161+ return new MvxCommand ( ( ) =>
162+ {
139163 GetService < IViewModelTxService > ( ) . Add ( Issue ) ;
140164 ShowViewModel < IssueEditViewModel > ( new IssueEditViewModel . NavObject { Username = Username , Repository = Repository , Id = Id } ) ;
141165 } , ( ) => Issue != null ) ;
142166 }
143167 }
144168
145169 private ICommand _shareCommmand ;
170+
146171 public new ICommand ShareCommand
147172 {
148173 get
@@ -162,7 +187,7 @@ public ICommand ToggleStateCommand
162187 {
163188 get { return new MvxCommand ( ( ) => ToggleState ( PullRequest . State == "open" ) ) ; }
164189 }
165-
190+
166191 public ICommand GoToCommitsCommand
167192 {
168193 get { return new MvxCommand ( ( ) => ShowViewModel < PullRequestCommitsViewModel > ( new PullRequestCommitsViewModel . NavObject { Username = Username , Repository = Repository , PullRequestId = Id } ) ) ; }
@@ -174,17 +199,19 @@ public ICommand GoToFilesCommand
174199 }
175200
176201 private readonly CollectionViewModel < IssueCommentModel > _comments = new CollectionViewModel < IssueCommentModel > ( ) ;
202+
177203 public CollectionViewModel < IssueCommentModel > Comments
178204 {
179205 get { return _comments ; }
180206 }
181207
182208 private readonly CollectionViewModel < IssueEventModel > _events = new CollectionViewModel < IssueEventModel > ( ) ;
209+
183210 public CollectionViewModel < IssueEventModel > Events
184211 {
185212 get { return _events ; }
186213 }
187-
214+
188215 public string ConvertToMarkdown ( string str )
189216 {
190217 return ( GetService < IMarkdownService > ( ) . Convert ( str ) ) ;
@@ -211,10 +238,19 @@ public void Init(NavObject navObject)
211238 } ) ;
212239 }
213240
214- public async Task AddComment ( string text )
241+ public async Task < bool > AddComment ( string text )
215242 {
216- var comment = await this . GetApplication ( ) . Client . ExecuteAsync ( this . GetApplication ( ) . Client . Users [ Username ] . Repositories [ Repository ] . Issues [ Id ] . CreateComment ( text ) ) ;
217- Comments . Items . Add ( comment . Data ) ;
243+ try
244+ {
245+ var comment = await this . GetApplication ( ) . Client . ExecuteAsync ( this . GetApplication ( ) . Client . Users [ Username ] . Repositories [ Repository ] . Issues [ Id ] . CreateComment ( text ) ) ;
246+ Comments . Items . Add ( comment . Data ) ;
247+ return true ;
248+ }
249+ catch ( Exception e )
250+ {
251+ DisplayAlert ( e . Message ) ;
252+ return false ;
253+ }
218254 }
219255
220256 private async Task ToggleState ( bool closed )
@@ -235,20 +271,20 @@ private async Task ToggleState(bool closed)
235271 }
236272 }
237273
238- protected override Task Load ( bool forceCacheInvalidation )
274+ protected override Task Load ( bool forceCacheInvalidation )
239275 {
240276 var pullRequest = this . GetApplication ( ) . Client . Users [ Username ] . Repositories [ Repository ] . PullRequests [ Id ] . Get ( ) ;
241- var t1 = this . RequestModel ( pullRequest , forceCacheInvalidation , response => PullRequest = response . Data ) ;
277+ var t1 = this . RequestModel ( pullRequest , forceCacheInvalidation , response => PullRequest = response . Data ) ;
242278 Events . SimpleCollectionLoad ( this . GetApplication ( ) . Client . Users [ Username ] . Repositories [ Repository ] . Issues [ Id ] . GetEvents ( ) , forceCacheInvalidation ) . FireAndForget ( ) ;
243279 Comments . SimpleCollectionLoad ( this . GetApplication ( ) . Client . Users [ Username ] . Repositories [ Repository ] . Issues [ Id ] . GetComments ( ) , forceCacheInvalidation ) . FireAndForget ( ) ;
244280 this . RequestModel ( this . GetApplication ( ) . Client . Users [ Username ] . Repositories [ Repository ] . Issues [ Id ] . Get ( ) , forceCacheInvalidation , response => Issue = response . Data ) . FireAndForget ( ) ;
245281 return t1 ;
246282 }
247283
248- public async Task Merge ( )
284+ public async Task Merge ( )
249285 {
250286 var response = await this . GetApplication ( ) . Client . ExecuteAsync ( this . GetApplication ( ) . Client . Users [ Username ] . Repositories [ Repository ] . PullRequests [ Id ] . Merge ( ) ) ;
251- if ( ! response . Data . Merged )
287+ if ( ! response . Data . Merged )
252288 throw new Exception ( response . Data . Message ) ;
253289
254290 var pullRequest = this . GetApplication ( ) . Client . Users [ Username ] . Repositories [ Repository ] . PullRequests [ Id ] . Get ( ) ;
@@ -270,7 +306,9 @@ private bool CanMerge()
270306 public class NavObject
271307 {
272308 public string Username { get ; set ; }
309+
273310 public string Repository { get ; set ; }
311+
274312 public long Id { get ; set ; }
275313 }
276314 }
0 commit comments