/// <summary> /// Loads documents that are matched by criteria from filter. /// </summary> /// <param name="userDto">The user dto.</param> /// <returns></returns> public IEnumerable <DocumentDTO> LoadUserDocuments(DocumentFilterDTO filter) { Expression <Func <tDocument, bool> > restriction = x => x.IsValid; if (filter.LoggedUser.AuthorizationRole == AuthorizationRoleCodes.Operator) { restriction = ExpressionUtils.AndOperation(restriction, u => u.tUserDocuments.Select(x => x.UserId).Contains(filter.LoggedUser.Id)); } if (!String.IsNullOrEmpty(filter.Title)) { restriction = ExpressionUtils.AndOperation(restriction, u => u.Title.Contains(filter.Title)); } if (!String.IsNullOrEmpty(filter.Keywords)) { string[] keywords = filter.Keywords.Split(' ', ','); Expression <Func <tDocument, bool> > wordRestriciton = x => false; // false || kw1 || kw2 foreach (string word in keywords) { wordRestriciton = ExpressionUtils.OrOperation(wordRestriciton, x => x.tKeywords.Select(k => k.Name).Contains(word)); } restriction = ExpressionUtils.AndOperation(restriction, wordRestriciton); } if (!String.IsNullOrEmpty(filter.Extension)) { restriction = ExpressionUtils.AndOperation(restriction, u => u.Extension.Contains(filter.Extension)); } if (filter.DateFrom.HasValue) { DateTime date1 = filter.DateFrom.Value.Date; restriction = ExpressionUtils.AndOperation(restriction, u => u.CreatedAt >= date1); } if (filter.DateTo.HasValue) { DateTime date2 = filter.DateTo.Value.AddDays(1).Date; restriction = ExpressionUtils.AndOperation(restriction, u => u.CreatedAt <= date2); } if (filter.OnlyActive) { restriction = ExpressionUtils.AndOperation(restriction, u => !u.IsArchived); } if (filter.OnlyArchived) { restriction = ExpressionUtils.AndOperation(restriction, u => u.IsArchived); } if (!String.IsNullOrEmpty(filter.UserName)) { restriction = ExpressionUtils.AndOperation(restriction, u => u.tUserDocuments.Select(x => x.tUser.UserName).Contains(filter.UserName)); } using (DMSDataBaseEntities context = new DMSDataBaseEntities()) { return(Mapper.Map <IEnumerable <DocumentDTO> >(context.tDocuments.Where(restriction).OrderBy(u => u.CreatedAt))); } }
private DocumentFilterDTO GreateDocumentFilter() { DocumentFilterDTO filter = new DocumentFilterDTO(); if (chkBoxSearchTitleActive.Checked) { filter.Title = this.txtBoxSearchTitle.Text; } if (chkBoxSearchKeywordsActive.Checked) { filter.Keywords = this.txtBoxSearchKeywords.Text; } if (chkBoxSearchExtensionActive.Checked) { filter.Extension = this.txtBoxSearchExtension.Text; } if (panelSearchByUsers.Visible && chkBoxSearchUserNameActive.Checked) { filter.UserName = this.txtBoxSearchDocumentByUserName.Text; } filter.DateFrom = this.datePickerFrom.Value; filter.DateTo = this.datePickerTo.Value; if (this.selectDocumentsFilter.SelectedIndex == (int)DocumentFilterTypeCodes.Active) { filter.OnlyActive = true; } if (this.selectDocumentsFilter.SelectedIndex == (int)DocumentFilterTypeCodes.Arhived) { filter.OnlyArchived = true; } filter.LoggedUser = loggedUser; return(filter); }