public void DeleteBC(string index, string path) { try { //Step 1 Code to delete the object from the database EmployeeBackgroundCheck n = new EmployeeBackgroundCheck(); n.recordId = index; n.employeeId = 0; n.date = DateTime.Now; n.expiryDate = DateTime.Now; n.remarks = ""; n.fileUrl = path; PostRequest <EmployeeBackgroundCheck> req = new PostRequest <EmployeeBackgroundCheck>(); req.entity = n; PostResponse <EmployeeBackgroundCheck> res = _employeeService.ChildDelete <EmployeeBackgroundCheck>(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 BCStore.Remove(index); //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 SaveBC(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 bcFileURl = e.ExtraParams["BcFile"]; EmployeeBackgroundCheck b = JsonConvert.DeserializeObject <EmployeeBackgroundCheck>(obj); b.fileUrl = bcFileURl; if (!string.IsNullOrEmpty(b.fileUrl)) { b.fileUrl = Regex.Replace(b.fileUrl, @"[^0-9a-zA-Z.]+", ""); } b.employeeId = Convert.ToInt32(CurrentEmployee.Text); b.recordId = id; b.date = new DateTime(b.date.Year, b.date.Month, b.date.Day, 14, 0, 0); b.expiryDate = new DateTime(b.expiryDate.Year, b.expiryDate.Month, b.expiryDate.Day, 14, 0, 0); if (ctId.SelectedItem != null) { b.ctName = ctId.SelectedItem.Text; } if (string.IsNullOrEmpty(id)) { try { //New Mode //Step 1 : Fill The object and insert in the store PostRequest <EmployeeBackgroundCheck> request = new PostRequest <EmployeeBackgroundCheck>(); request.entity = b; byte[] fileData = null; if (bcFile.PostedFile != null && bcFile.PostedFile.ContentLength > 0) { //using (var binaryReader = new BinaryReader(picturePath.PostedFile.InputStream)) //{ // fileData = binaryReader.ReadBytes(picturePath.PostedFile.ContentLength); //} fileData = new byte[bcFile.PostedFile.ContentLength]; fileData = bcFile.FileBytes; } else { fileData = null; } PostResponse <EmployeeBackgroundCheck> r = _employeeService.ChildAddOrUpdate <EmployeeBackgroundCheck>(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 { //Add this record to the store if (fileData != null) { SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest(); req.entity = new Model.System.Attachement() { date = DateTime.Now, classId = ClassId.EPBC, recordId = Convert.ToInt32(b.recordId), fileName = bcFile.PostedFile.FileName, seqNo = 0 }; req.FileNames.Add(bcFile.PostedFile.FileName); req.FilesData.Add(fileData); PostResponse <Attachement> resp = _systemService.UploadMultipleAttachments(req); if (!resp.Success)//it maybe be another condition { //Show an error saving... X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(r); return; } } EmployeeBackgroundCheck bc = GetBCById(r.recordId); this.BCStore.Insert(0, bc); //Display successful notification Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordSavingSucc }); this.EditBCWindow.Close(); RowSelectionModel sm = this.BackgroundCheckGrid.GetSelectionModel() as RowSelectionModel; sm.DeselectAll(); sm.Select(b.recordId.ToString()); } } 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 { int index = Convert.ToInt32(id);//getting the id of the record PostRequest <EmployeeBackgroundCheck> request = new PostRequest <EmployeeBackgroundCheck>(); request.entity = b; byte[] fileData = null; if (bcFile.PostedFile != null && bcFile.PostedFile.ContentLength > 0) { //using (var binaryReader = new BinaryReader(picturePath.PostedFile.InputStream)) //{ // fileData = binaryReader.ReadBytes(picturePath.PostedFile.ContentLength); //} fileData = new byte[bcFile.PostedFile.ContentLength]; fileData = bcFile.FileBytes; } PostResponse <EmployeeBackgroundCheck> r = _employeeService.ChildAddOrUpdate <EmployeeBackgroundCheck>(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 { if (fileData != null) { SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest(); req.entity = new Model.System.Attachement() { date = DateTime.Now, classId = ClassId.EPBC, recordId = Convert.ToInt32(b.recordId), fileName = bcFile.PostedFile.FileName, seqNo = 0 }; req.FileNames.Add(Regex.Replace(bcFile.PostedFile.FileName, @"[^0-9a-zA-Z.]+", "")); req.FilesData.Add(fileData); PostResponse <Attachement> resp = _systemService.UploadMultipleAttachments(req); if (!resp.Success)//it maybe be another condition { //Show an error saving... X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(r); return; } } EmployeeBackgroundCheck BC = GetBCById(b.recordId); ModelProxy record = this.BCStore.GetById(id); record.Set("expiryDate", BC.expiryDate); record.Set("fileUrl", BC.fileUrl); record.Set("ctId", BC.ctId); record.Set("ctName", BC.ctName); record.Set("remarks", BC.remarks); record.Commit(); Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordUpdatedSucc }); this.EditBCWindow.Close(); } } catch (Exception ex) { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show(); } } //if (b.Date.Date == DateTime.Today) //{ // X.Call("parent.FillLeftPanel", b.departmentName + "<br/>", b.branchName + "<br/>", b.positionName + "<br/>"); // X.Call("parent.SelectJICombos", b.departmentId, b.branchId, b.positionId, b.divisionId); //} }