private static bool ResolveName(string query, out CannedText result) { result = null; CannedTextSummary cannedText = null; Platform.GetService <ICannedTextService>( service => { // Ask for maximum of 2 rows var request = new ListCannedTextForUserRequest { Name = query, Page = new SearchResultPage(-1, 2) }; var response = service.ListCannedTextForUser(request); // the name is resolved only if there is one match if (response.CannedTexts.Count == 1) { cannedText = CollectionUtils.FirstElement(response.CannedTexts); } }); if (cannedText != null) { result = new CannedText(cannedText); } return(result != null); }
public CannedText(CannedTextSummary summary) : this(summary.Name, summary.Category, summary.Staff == null ? null : summary.Staff.StaffId, summary.StaffGroup == null ? null : summary.StaffGroup.Name, summary.TextSnippet) { }
public void Accept() { if (this.HasValidationErrors) { this.ShowValidation(true); return; } try { // Depends on the editing mode, remove the unnecessary information if (this.IsEditingPersonal) { _cannedTextDetail.StaffGroup = null; } // Warn user about possible name conflicts if (!WarnAboutNameConflicts()) { return; } // Commit the changes Platform.GetService <ICannedTextService>( service => { if (_isNew) { var response = service.AddCannedText(new AddCannedTextRequest(_cannedTextDetail)); _cannedTextSummary = response.CannedTextSummary; } else { var response = service.UpdateCannedText(new UpdateCannedTextRequest(_cannedTextRef, _cannedTextDetail)); _cannedTextSummary = response.CannedTextSummary; } }); this.Exit(ApplicationComponentExitCode.Accepted); } catch (Exception e) { ExceptionHandler.Report(e, SR.ExceptionSaveCannedText, this.Host.DesktopWindow, delegate { this.ExitCode = ApplicationComponentExitCode.Error; this.Host.Exit(); }); } }
private static string FormatCannedText(CannedTextSummary cannedText) { return(string.Format("{0}, Category: {1}, Owner: {2}", cannedText.Name, cannedText.Category, cannedText.IsPersonal ? SR.ColumnPersonal : cannedText.StaffGroup.Name)); }