/// <summary> /// Adding new record /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ADDNewRecord(object sender, DirectEventArgs e) { //Reset all values of the relative object //BasicInfoTab.Reset(); CurrentRuleId.Text = "0"; EditRecordWindow.Show(); accessType.Reset(); this.EditRecordWindow.Title = Resources.Common.AddNewRecord; this.EditRecordWindow.Show(); }
protected void SaveNewRecord(object sender, DirectEventArgs e) { string obj = e.ExtraParams["values"]; JsonSerializerSettings settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; SelfServiceResetPassword h = JsonConvert.DeserializeObject <SelfServiceResetPassword>(obj, settings); RecordRequest r = new RecordRequest(); r.RecordID = _systemService.SessionHelper.GetCurrentUserId(); RecordResponse <UserInfoSelfService> response = _selfServiceService.ChildGetRecord <UserInfoSelfService>(r); if (!response.Success) { X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", response.ErrorCode) != null ? GetGlobalResourceObject("Errors", response.ErrorCode).ToString() + "<br>" + GetGlobalResourceObject("Errors", "ErrorLogId") + response.LogId : response.Summary, "closeCurrentTab()").Show(); return; } if (EncryptionHelper.encrypt(h.oldPassword) != response.result.password) { X.Msg.Alert(Resources.Common.Error, GetLocalResourceObject("incorrectPassword").ToString()).Show(); return; } PostRequest <UserInfoSelfService> req = new PostRequest <UserInfoSelfService>(); req.entity = response.result; req.entity.password = EncryptionHelper.encrypt(h.Password); PostResponse <UserInfoSelfService> resp = _selfServiceService.ChildAddOrUpdate <UserInfoSelfService>(req); if (!resp.Success) { Common.errorMessage(resp); return; } Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordUpdatedSucc }); EditRecordWindow.Close(); }
protected void SaveNewRecord(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"]; string addr = e.ExtraParams["address"]; BusinessPartner b = JsonConvert.DeserializeObject <BusinessPartner>(obj); b.recordId = id; // Define the object to add or edit as null // Define the object to add or edit as null CustomResolver res = new CustomResolver(); res.AddRule("naId", "countryId"); res.AddRule("stId", "stateId"); JsonSerializerSettings settings = new JsonSerializerSettings(); settings.ContractResolver = res; AddressBook add = JsonConvert.DeserializeObject <AddressBook>(addr, settings); if (string.IsNullOrEmpty(add.city) && string.IsNullOrEmpty(add.countryId) && string.IsNullOrEmpty(add.street1) && string.IsNullOrEmpty(add.stateId) && string.IsNullOrEmpty(add.phone)) { b.address = null; } else { if (string.IsNullOrEmpty(add.city) || string.IsNullOrEmpty(add.countryId) || string.IsNullOrEmpty(add.street1) || string.IsNullOrEmpty(add.stateId) || string.IsNullOrEmpty(add.phone)) { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, GetLocalResourceObject("ErrorAddressMissing")).Show(); return; } b.address = JsonConvert.DeserializeObject <AddressBook>(addr, settings); b.address.recordId = address.Text; if (string.IsNullOrEmpty(id)) { try { //New Mode //Step 1 : Fill The object and insert in the store PostRequest <BusinessPartner> request = new PostRequest <BusinessPartner>(); request.entity = b; PostResponse <BusinessPartner> r = _administrationService.ChildAddOrUpdate <BusinessPartner>(request); b.recordId = r.recordId; //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 { Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordSavingSucc }); //Add this record to the store //Display successful notification Store1.Reload(); EditRecordWindow.Close(); } } 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 { PostRequest <BusinessPartner> request = new PostRequest <BusinessPartner>(); request.entity = b; PostResponse <BusinessPartner> r = _administrationService.ChildAddOrUpdate <BusinessPartner>(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 { ModelProxy record = this.Store1.GetById(id); BasicInfoTab.UpdateRecord(record); record.Commit(); Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordUpdatedSucc }); // this.EditRecordWindow.Close(); } } catch (Exception ex) { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show(); } } } }