public PaginatedList <AttachmentInfo> GetAttachmentsInfo(string filter, AttachmentSortTypeEnum?sortType, int start = 0, int count = Int32.MaxValue) { Trace.Assert(Context.PersonId.HasValue); string orderByColumn = null; Orm.OrderType orderType = Orm.OrderType.Desc; sortType = sortType ?? AttachmentSortTypeEnum.RecentlySent; switch (sortType) { case AttachmentSortTypeEnum.RecentlySent: orderByColumn = Attachment.LAST_ATTACHED_DATE_FIELD; break; case AttachmentSortTypeEnum.NewestUploaded: orderByColumn = Attachment.UPLOADED_DATE_FIELD; break; case AttachmentSortTypeEnum.OldestUploaded: orderByColumn = Attachment.UPLOADED_DATE_FIELD; orderType = Orm.OrderType.Asc; break; } var res = DoRead(u => new AttachmentDataAccess(u).GetPaginatedAttachments(Context.PersonId.Value, filter, orderByColumn, orderType, start, count)); var teacherIds = new List <int> { Context.PersonId.Value }; return(res.Transform(x => TransformToAttachmentInfo(x, teacherIds))); }
public PaginatedList <Attachment> GetPaginatedAttachments(int personId, string filter, string orderByColumn, Orm.OrderType orderType, int start, int count) { var conds = new AndQueryCondition { { Attachment.PERSON_REF_FIELD, personId } }; var dbQuery = new DbQuery(); var attachmentTName = typeof(Attachment).Name; dbQuery.Sql.AppendFormat(Orm.SELECT_FORMAT, "*", attachmentTName); conds.BuildSqlWhere(dbQuery, attachmentTName); if (!string.IsNullOrEmpty(filter)) { dbQuery.Parameters.Add("@filter", string.Format(FILTER_FORMAT, filter)); dbQuery.Sql.AppendFormat(" and {0} like @{1} ", Attachment.NAME_FIELD, "filter"); } return(PaginatedSelect <Attachment>(dbQuery, orderByColumn, start, count, orderType)); }