public ListCannedTextForUserResponse ListCannedTextForUser(ListCannedTextForUserRequest request) { var assembler = new CannedTextAssembler(); var criterias = new List <CannedTextSearchCriteria>(); var personalCannedTextCriteria = new CannedTextSearchCriteria(); personalCannedTextCriteria.Staff.EqualTo(this.CurrentUserStaff); if (!string.IsNullOrEmpty(request.Name)) { personalCannedTextCriteria.Name.EqualTo(request.Name); } criterias.Add(personalCannedTextCriteria); if (this.CurrentUserStaff.Groups != null && this.CurrentUserStaff.Groups.Count > 0) { var groupCannedTextCriteria = new CannedTextSearchCriteria(); groupCannedTextCriteria.StaffGroup.In(this.CurrentUserStaff.Groups); if (!string.IsNullOrEmpty(request.Name)) { groupCannedTextCriteria.Name.EqualTo(request.Name); } criterias.Add(groupCannedTextCriteria); } var results = PersistenceContext.GetBroker <ICannedTextBroker>().Find(criterias.ToArray(), request.Page); var staffCannedText = CollectionUtils.Map <CannedText, CannedTextSummary>(results, cannedText => assembler.GetCannedTextSummary(cannedText, this.PersistenceContext)); return(new ListCannedTextForUserResponse(staffCannedText)); }
protected override IList <CannedText> GetItemsForExport(IReadContext context, int firstRow, int maxRows) { CannedTextSearchCriteria where = new CannedTextSearchCriteria(); where.Name.SortAsc(0); return(context.GetBroker <ICannedTextBroker>().Find(where, new SearchResultPage(firstRow, maxRows))); }
public ListCannedTextForUserResponse ListCannedTextForUser(ListCannedTextForUserRequest request) { var assembler = new CannedTextAssembler(); var criterias = new List<CannedTextSearchCriteria>(); var personalCannedTextCriteria = new CannedTextSearchCriteria(); personalCannedTextCriteria.Staff.EqualTo(this.CurrentUserStaff); if (!string.IsNullOrEmpty(request.Name)) personalCannedTextCriteria.Name.EqualTo(request.Name); criterias.Add(personalCannedTextCriteria); if (this.CurrentUserStaff.Groups != null && this.CurrentUserStaff.Groups.Count > 0) { var groupCannedTextCriteria = new CannedTextSearchCriteria(); groupCannedTextCriteria.StaffGroup.In(this.CurrentUserStaff.Groups); if (!string.IsNullOrEmpty(request.Name)) groupCannedTextCriteria.Name.EqualTo(request.Name); criterias.Add(groupCannedTextCriteria); } var results = PersistenceContext.GetBroker<ICannedTextBroker>().Find(criterias.ToArray(), request.Page); var staffCannedText = CollectionUtils.Map<CannedText, CannedTextSummary>(results, cannedText => assembler.GetCannedTextSummary(cannedText, this.PersistenceContext)); return new ListCannedTextForUserResponse(staffCannedText); }
public LoadCannedTextForEditResponse LoadCannedTextForEdit(LoadCannedTextForEditRequest request) { var broker = PersistenceContext.GetBroker<ICannedTextBroker>(); CannedText cannedText; if (request.CannedTextRef != null) { cannedText = broker.Load(request.CannedTextRef); } else { var criteria = new CannedTextSearchCriteria(); if (!string.IsNullOrEmpty(request.Name)) criteria.Name.EqualTo(request.Name); if (!string.IsNullOrEmpty(request.Category)) criteria.Category.EqualTo(request.Category); if (!string.IsNullOrEmpty(request.StaffId)) criteria.Staff.Id.EqualTo(request.StaffId); if (!string.IsNullOrEmpty(request.StaffGroupName)) criteria.StaffGroup.Name.EqualTo(request.StaffGroupName); cannedText = broker.FindOne(criteria); } var assembler = new CannedTextAssembler(); return new LoadCannedTextForEditResponse(assembler.GetCannedTextDetail(cannedText, this.PersistenceContext)); }
public LoadCannedTextForEditResponse LoadCannedTextForEdit(LoadCannedTextForEditRequest request) { var broker = PersistenceContext.GetBroker <ICannedTextBroker>(); CannedText cannedText; if (request.CannedTextRef != null) { cannedText = broker.Load(request.CannedTextRef); } else { var criteria = new CannedTextSearchCriteria(); if (!string.IsNullOrEmpty(request.Name)) { criteria.Name.EqualTo(request.Name); } if (!string.IsNullOrEmpty(request.Category)) { criteria.Category.EqualTo(request.Category); } if (!string.IsNullOrEmpty(request.StaffId)) { criteria.Staff.Id.EqualTo(request.StaffId); } if (!string.IsNullOrEmpty(request.StaffGroupName)) { criteria.StaffGroup.Name.EqualTo(request.StaffGroupName); } cannedText = broker.FindOne(criteria); } var assembler = new CannedTextAssembler(); return(new LoadCannedTextForEditResponse(assembler.GetCannedTextDetail(cannedText, this.PersistenceContext))); }
private static void CreateOrUpdateCannedText( string name, string category, string staffId, string staffGroupName, string text, IPersistenceContext context) { try { // At least one of these should be populated if (staffId == null && staffGroupName == null) { throw new Exception("A canned text has a staff or a staff group. They cannot both be empty"); } if (staffId != null && staffGroupName != null) { throw new Exception("A canned text has a staff or a staff group. They cannot both exist"); } CannedTextSearchCriteria criteria = new CannedTextSearchCriteria(); // We must search all these criteria because the combination of them form a unique key criteria.Name.EqualTo(name); criteria.Category.EqualTo(category); if (!string.IsNullOrEmpty(staffId)) { criteria.Staff.Id.EqualTo(staffId); } if (!string.IsNullOrEmpty(staffGroupName)) { criteria.StaffGroup.Name.EqualTo(staffGroupName); } ICannedTextBroker broker = context.GetBroker <ICannedTextBroker>(); CannedText cannedText = broker.FindOne(criteria); cannedText.Text = text; } catch (EntityNotFoundException) { Staff staff = FindStaff(staffId, context); StaffGroup staffGroup = FindStaffGroup(staffGroupName, context); if (!string.IsNullOrEmpty(staffId) && staff == null) { throw new Exception("The requested staff does not exist."); } if (!string.IsNullOrEmpty(staffGroupName) && staffGroup == null) { throw new Exception("The requested staff group does not exist."); } CannedText cannedText = new CannedText(); cannedText.Name = name; cannedText.Category = category; cannedText.Staff = staff; cannedText.StaffGroup = staffGroup; cannedText.Text = text; context.Lock(cannedText, DirtyState.New); } }