@@ -14,6 +14,12 @@ namespace CodeHubDesktop.ViewModels
1414{
1515 public class CreateSnippetViewModel : BindableBase
1616 {
17+ private string _Error ;
18+ public string Error
19+ {
20+ get => _Error ;
21+ set => SetProperty ( ref _Error , value ) ;
22+ }
1723 private string _SnippetUrl ;
1824 public string SnippetUrl
1925 {
@@ -83,20 +89,20 @@ private async void OnCreateSnippet()
8389 title = Subject ,
8490 detail = Detail ,
8591 language = SelectedCode . ToLower ( ) ,
86- script = Snippet
92+ script = Snippet ,
93+ error = Error
8794 } ;
8895
8996 string json = JsonConvert . SerializeObject ( snippet ) ;
9097 StringContent data = new StringContent ( json , Encoding . UTF8 , "application/json" ) ;
91- string url = "http://codehub.pythonanywhere.com/api/v1/snippet/" ;
98+ string url = GlobalData . Config . APIBaseAddress ;
9299
93100 using HttpClient client = new HttpClient ( ) ;
94101 HttpResponseMessage response = await client . PostAsync ( url , data ) ;
95102
96103 string result = response . Content . ReadAsStringAsync ( ) . Result ;
97104 GetSnippetModel parse = JsonConvert . DeserializeObject < GetSnippetModel > ( result ) ;
98105 SnippetUrl = parse . link ;
99- IsEnabled = true ;
100106 if ( GlobalData . Config . StoreSnippet )
101107 {
102108 SnippetsModel entity = new SnippetsModel
@@ -107,22 +113,27 @@ private async void OnCreateSnippet()
107113 Link = parse . link ,
108114 PubDate = parse . pub_date ,
109115 Script = parse . script ,
110- SId = parse . SID
116+ SId = parse . SID ,
117+ Error = parse . error
111118 } ;
112119 IDataService < SnippetsModel > dataService = new GenericDataService < SnippetsModel > ( ) ;
113120 await dataService . CreateSnippet ( entity ) ;
114121 }
122+ IsEnabled = true ;
115123 }
116124 catch ( Exception ex )
117125 {
118-
119126 Growl . Error ( ex . Message ) ;
120127 }
128+ finally
129+ {
130+ IsEnabled = true ;
131+ }
121132 }
122133
123134 private void OnClear ( )
124135 {
125- Snippet = Subject = Detail = string . Empty ;
136+ Error = Snippet = Subject = Detail = string . Empty ;
126137 }
127138
128139 internal void FillComboBox ( )
0 commit comments