Ejemplo n.º 1
0
		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);
		}
Ejemplo n.º 2
0
        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);
        }