public void DeleteLegalReferenceRecord(string index, string branchId) { try { //Step 1 Code to delete the object from the database if (string.IsNullOrEmpty(index) || string.IsNullOrEmpty(branchId)) { return; } LegalReference n = new LegalReference(); n.branchId = Convert.ToInt32(branchId); n.goId = Convert.ToInt32(index); PostRequest <LegalReference> req = new PostRequest <LegalReference>(); req.entity = n; PostResponse <LegalReference> res = _branchService.ChildDelete <LegalReference>(req); if (!res.Success) { //Show an error saving... X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, res.Summary).Show(); return; } else { //Step 2 : remove the object from the store legalReferenceStore.Reload(); //Step 3 : Showing a notification for the user Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordDeletedSucc }); } } catch (Exception ex) { //In case of error, showing a message box to the user X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorDeletingRecord).Show(); } }
protected void saveLegalRecord(object sender, DirectEventArgs e) { //Getting the id to check if it is an Add or an edit as they are managed within the same form. string id = e.ExtraParams["id"]; string obj = e.ExtraParams["values"]; LegalReference b = JsonConvert.DeserializeObject <LegalReference>(obj); b.branchId = Convert.ToInt32(branchId.Text); b.goId = Convert.ToInt32(goIDDD.Text); // Define the object to add or edit as null if (string.IsNullOrEmpty(id)) { try { //New Mode //Step 1 : Fill The object and insert in the store PostRequest <LegalReference> request = new PostRequest <LegalReference>(); request.entity = b; PostResponse <LegalReference> r = _branchService.ChildAddOrUpdate <LegalReference>(request); //check if the insert failed if (!r.Success)//it maybe be another condition { //Show an error saving... X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(r); return; } else { legalReferenceStore.Reload(); this.EditlegalReferenceWindow.Close(); Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordSavingSucc }); //Add this record to the store //Display successful notification } } catch (Exception ex) { //Error exception displaying a messsage box X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorSavingRecord).Show(); } } else { //Update Mode try { b.goId = Convert.ToInt32(id); PostRequest <LegalReference> request = new PostRequest <LegalReference>(); request.entity = b; PostResponse <LegalReference> r = _branchService.ChildAddOrUpdate <LegalReference>(request); //Step 1 Selecting the object or building up the object for update purpose //Step 2 : saving to store //Step 3 : Check if request fails if (!r.Success)//it maybe another check { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(r); return; } else { legalReferenceStore.Reload(); Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordUpdatedSucc }); this.EditlegalReferenceWindow.Close(); } } catch (Exception ex) { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show(); } } }