public async Task <List <UserMessage> > SearchUserMessage(MessageSearchOptions options, PageOptions page) { var serviceId = options?.serviceId; var typeId = options?.typeId; var topicId = options?.topicId; var receiverId = options?.reveiverId; var statusId = options?.statusId; var senderIds = options?.senderIds; var query = DB.Queryable <Message, UserMessage>((m, um) => new object[] { JoinType.Left, m.Id == um.MessageId && um.ReceiverId == receiverId }); if (!senderIds.IsNull() && senderIds.Length > 0) { query.In((m, um) => m.SenderId, senderIds); } if (statusId == StaticKeys.UserMessageStatusId_Waiting) { query.Where((m, um) => string.IsNullOrEmpty(um.ReceiverId)); } if (!serviceId.IsNullOrEmpty()) { query.Where((m, um) => m.ServiceId == serviceId || um.ServiceId == serviceId); } if (!typeId.IsNullOrEmpty()) { query.Where((m, um) => m.TypeId == typeId); } if (!topicId.IsNullOrEmpty()) { query.Where((m, um) => m.TopicId == topicId); } if (!page.IsNull()) { page.TotalCount = query.Count(); } var result = query.Select((m, um) => new UserMessage { Id = um.Id, ReceiverId = um.ReceiverId, MessageId = um.MessageId, ServiceId = um.ServiceId, Message = m, }); return(page.IsNull() || !page.IsValidate ? await result.ToListAsync() : await result.ToPageListAsync(page.PageIndex, page.PageSize)); }
public async Task <List <Subscribe> > Search(SubscribeSearchOptions options, PageOptions page) { var query = DB.Queryable <Subscribe>(); if (!options.IsNull()) { var SubscriberId = options?.SubscriberId; var TargetId = options?.TargetId; var ServiceId = options?.ServiceId; var TopicId = options?.TopicId; var code = options?.Code; if (!SubscriberId.IsNullOrEmpty()) { query.Where(s => s.SubscriberId == SubscriberId); } if (!TargetId.IsNullOrEmpty()) { query.Where(s => s.TargetId == TargetId); } if (!ServiceId.IsNullOrEmpty()) { query.Where(s => s.ServiceId == ServiceId); } if (!TopicId.IsNullOrEmpty()) { query.Where(s => s.TopicId == TopicId); } } var targets = new List <Subscribe>(); if (!page.IsNull() && page.IsValidate) { targets = await query.ToPageListAsync(page.PageIndex, page.PageSize); } else { targets = await query.ToListAsync(); } return(targets); }