/// <summary>
        /// Gets the documents for the matter.
        /// </summary>
        public DocumentSearchItem[] GetSearchForMatterDocuments(int startRow, int pageSize, string searchText,
                                                                Int32 fileType, Boolean deepSearch, Boolean matchCase, Boolean searchSubFolders)
        {
            DocumentServiceClient documentService = new DocumentServiceClient();

            DocumentSearchItem[] matterDocs = null;

            try
            {
                Guid logonId = ((LogonReturnValue)HttpContext.Current.Session[SessionName.LogonSettings]).LogonId;
                DocumentSearchCriteria criteria = new DocumentSearchCriteria();
                criteria.DocumentType      = fileType;
                criteria.IsDeepSearch      = deepSearch;
                criteria.IsMatchCase       = matchCase;
                criteria.IsSubFolderSearch = searchSubFolders;
                criteria.SearchString      = searchText;

                if (HttpContext.Current.Session[SessionName.ProjectId] != null)
                {
                    DocumentSearchReturnValue returnValue = documentService.GetMatterDocumentForDeepSearch(logonId, (Guid)HttpContext.Current.Session[SessionName.ProjectId], criteria);
                    if (returnValue != null)
                    {
                        if (returnValue.Success)
                        {
                            if (returnValue.Document != null)
                            {
                                matterDocs = returnValue.Document.Rows;
                                _matterDocumentRowCount = returnValue.Document.Rows.Length;
                            }
                        }
                        else
                        {
                            throw new Exception(returnValue.Message);
                        }
                    }
                }
                else
                {
                    throw new Exception("No Project Id found.");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (documentService != null)
                {
                    if (documentService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        documentService.Close();
                    }
                }
            }

            return(matterDocs);
        }
        /// <summary>
        /// Gets the documents for the matter.
        /// </summary>
        public DocumentSearchItem[] GetSearchForMatterDocuments(int startRow, int pageSize, string searchText, 
                Int32 fileType, Boolean deepSearch, Boolean matchCase, Boolean searchSubFolders)
        {
            DocumentServiceClient documentService = new DocumentServiceClient();
            DocumentSearchItem[] matterDocs = null;

            try
            {
                Guid logonId = ((LogonReturnValue)HttpContext.Current.Session[SessionName.LogonSettings]).LogonId;
                DocumentSearchCriteria criteria = new DocumentSearchCriteria();
                criteria.DocumentType = fileType;
                criteria.IsDeepSearch = deepSearch;
                criteria.IsMatchCase = matchCase;
                criteria.IsSubFolderSearch = searchSubFolders;
                criteria.SearchString = searchText;

                if (HttpContext.Current.Session[SessionName.ProjectId] != null)
                {
                    DocumentSearchReturnValue returnValue = documentService.GetMatterDocumentForDeepSearch(logonId, (Guid)HttpContext.Current.Session[SessionName.ProjectId], criteria);
                    if (returnValue != null)
                    {
                        if (returnValue.Success)
                        {
                            if (returnValue.Document != null)
                            {
                                matterDocs = returnValue.Document.Rows;
                                _matterDocumentRowCount = returnValue.Document.Rows.Length;
                            }
                        }
                        else
                        {
                            throw new Exception(returnValue.Message);
                        }
                    }
                }
                else
                {
                    throw new Exception("No Project Id found.");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (documentService != null)
                {
                    if (documentService.State != System.ServiceModel.CommunicationState.Faulted)
                        documentService.Close();
                }
            }

            return matterDocs;
        }
Exemple #3
0
        public ActionResult Search(DocumentSearchCriteria criteria, string sortBy, string direction, int?page)
        {
            int pageSize  = AppSettingHelper.PageSize;
            var documents = GenericFactory.Business.GetDocumentsListBySearch(criteria)
                            .OrderByDescending(i => i.CreatedDate)
                            .ToList();
            int totalCount = documents.Count;
            var result     = new List <DocumentListItemViewModel>();

            foreach (var d in documents)
            {
                var documentStatus    = (WorkflowStatus)d.DocumentStatusId;
                var statusName        = documentStatus.ToWorkFlowStatusName();
                var biddingStatus     = (d.BiddingStatusId.HasValue) ? (BiddingStatus)d.BiddingStatusId : BiddingStatus.undefined;
                var biddingStatusName = biddingStatus.ToBiddingStatusName();
                var document          = new DocumentListItemViewModel
                {
                    Id                 = d.Id.ToString(),
                    CustomerType       = d.Customer.CustomerType.CustomerTypeName,
                    CustomerName       = d.Customer.Name,
                    DocumentCode       = d.FileNumber,
                    SaleUserName       = d.AspNetUser.DisplayName,
                    WorkflowStatus     = (int)d.DocumentStatusId,
                    WorkflowStatusName = statusName,
                    BiddingStatus      = (d.BiddingStatusId.HasValue) ? (int)d.BiddingStatusId : 0,
                    BiddingStatusName  = biddingStatusName,
                    WeightPoint        = d.WeightPoint ?? 0
                };
                result.Add(document);
            }


            RouteValueDictionary routeValues = new RouteValueDictionary();

            routeValues.Add("sortBy", sortBy ?? "");
            routeValues.Add("direction", direction);
            var list = new PaginatedList <DocumentListItemViewModel>(
                result.OrderByDescending(d => d.WeightPoint).ThenByDescending(o => o.WorkflowStatus).ToList(),
                page ?? 0,
                pageSize,
                totalCount,
                true,
                routeValues);
            var viewModel = new ListViewModel <DocumentListItemViewModel>()
            {
                Direction = direction,
                SortBy    = sortBy,
                Data      = list
            };

            return(new JsonCamelCaseResult(viewModel, JsonRequestBehavior.AllowGet));
        }
Exemple #4
0
        public IList <Document> GetDocumentsListBySearch(DocumentSearchCriteria criteria, string userId = null)
        {
            using (var uow = UnitOfWork.Create())
            {
                var documents = uow.DocumentRepository.All().AsEnumerable();
                if (userId != null)
                {
                    documents = documents.Where(i => i.UserId.ToLower() == userId.ToLower());
                }
                if (!string.IsNullOrWhiteSpace(criteria.CustomerName))
                {
                    documents = documents.Where(i => i.Customer.Name.ToLower().Contains(criteria.CustomerName.ToLower()));
                }
                if (!string.IsNullOrWhiteSpace(criteria.DocumentCode))
                {
                    documents = documents.Where(i => i.FileNumber.ToLower().Contains(criteria.DocumentCode.ToLower()));
                }

                if (criteria.CustomerType != 0)
                {
                    documents = documents.Where(i => i.Customer.CustomerTypeId == criteria.CustomerType);
                }
                if (criteria.DocumentYear != 0)
                {
                    documents = documents.Where(i => i.IssueDate.Value.Year == criteria.DocumentYear);
                }
                if (!string.IsNullOrWhiteSpace(criteria.ContactName))
                {
                    documents = documents.Where(i => i.CustomerContact.Name.ToLower().Contains(criteria.ContactName.ToLower()));
                }
                if (!string.IsNullOrWhiteSpace(criteria.ProductCategoryId))
                {
                    documents = documents.Where(doc => doc.DocumentProductItems.Any(i => i.Product.ProductCategoryId.ToString().Contains(criteria.ProductCategoryId)));
                }
                if (criteria.QuotedPrice != 0)
                {
                    documents = documents.Where(doc => doc.DocumentProductItems.Any(i => (i.Amount * i.PricePerUnit) == criteria.QuotedPrice));
                }
                var d = documents.ToList();
                return(d.Where(i => !i.IsDelete).ToList());
            }
        }
        /// <summary>
        /// Get documents for deep search
        /// </summary>
        /// <param name="logonId"></param>
        /// <param name="fileListToSearch"></param>
        /// <returns></returns>
        public DocumentSearchReturnValue GetMatterDocumentForDeepSearch(Guid logonId, Guid projectId, DocumentSearchCriteria criteria)
        {
            DocumentSearchReturnValue returnValue = new DocumentSearchReturnValue();
            SrvFileSearcher srvFileSearcher = new SrvFileSearcher();

            try
            {
                // Get the logged on user from the current logons and add their
                // ApplicationSettings the list of concurrent sessions.
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    Functions.RestrictRekoopIntegrationUser(UserInformation.Instance.DbUid);
                    switch (UserInformation.Instance.UserType)
                    {
                        case DataConstants.UserType.Staff:
                            // Can do everything
                            break;
                        case DataConstants.UserType.Client:
                        case DataConstants.UserType.ThirdParty:
                            //Can search for documents
                            if (!SrvMatterCommon.WebAllowedToAccessMatter(projectId))
                                throw new Exception("Access denied");

                            break;
                        default:
                            throw new Exception("Access denied");
                    }

                    DataList<DocumentSearchItem> docs = this.MatterDocumentSearchInternal(projectId);

                    string[] listOfDocuments = null;
                    string fileInfo;
                    string searchFilePath;

                    listOfDocuments = new string[docs.Rows.Count];
                    for (int i = 0; i < docs.Rows.Count; i++)
                    {
                        fileInfo = string.Empty;
                        fileInfo = docs.Rows[i].FilePath;
                        if (fileInfo != string.Empty)
                        {
                            fileInfo += "^" + docs.Rows[i].FileDescription + "^" +
                                docs.Rows[i].Id + "^" +
                                Convert.ToString(docs.Rows[i].CreatedDate.ToString("dd/MM/yyyy")) +
                                "^" + Convert.ToString(docs.Rows[i].FeeEarnerRef);
                            listOfDocuments[i] = fileInfo;
                        }
                    }

                    srvFileSearcher.IgnoreCase = !criteria.IsMatchCase;
                    srvFileSearcher.SearchSubFolders = criteria.IsSubFolderSearch;
                    srvFileSearcher.SearchInFiles = criteria.IsDeepSearch;
                    srvFileSearcher.SearchFilesOfType = (SrvFileSearcher.AvailableFileTypes)criteria.DocumentType;

                    if (string.IsNullOrEmpty(criteria.SearchString))
                    {
                        criteria.SearchString = string.Empty;
                    }

                    srvFileSearcher.SearchSetPaths(listOfDocuments, criteria.SearchString);

                    List<FileInfo> filesFound = srvFileSearcher.FilesFound;
                    DataList<DocumentSearchItem> listDocuments = new DataList<DocumentSearchItem>();
                    foreach (FileInfo info in filesFound)
                    {
                        searchFilePath = string.Empty;

                        DocumentSearchItem item = new DocumentSearchItem();
                        item.FileName = info.Name;

                        string fileDescription = SrvDocumentCommon.GetDocumentDescription(info.Name);

                        item.FileDescription = fileDescription;
                        item.FilePath = info.FullName;

                        foreach (string element in listOfDocuments)
                        {
                            searchFilePath = string.Empty;
                            if (element.Contains("^"))
                            {
                                searchFilePath = element.Split('^')[0];
                                if (info.FullName == searchFilePath)
                                {
                                    item.Id = Convert.ToInt32(element.Split('^')[2]);
                                    item.CreatedDate = Convert.ToDateTime(Convert.ToString(element.Split('^')[3]));
                                    item.FeeEarnerRef = Convert.ToString(Convert.ToString(element.Split('^')[4]));
                                }
                            }
                        }

                        listDocuments.Rows.Add(item);
                    }
                    returnValue.Document = listDocuments;
                    returnValue.Message = srvFileSearcher.ErrorMessage;
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                returnValue.Success = false;
                returnValue.Message = Functions.SQLErrorMessage;
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Message = srvFileSearcher.ErrorMessage + "<br />" + ex.Message;
            }

            return returnValue;
        }
        /// <summary>
        /// Get documents for deep search
        /// </summary>
        /// <param name="oHostSecurityToken"></param>
        /// <param name="fileListToSearch"></param>
        /// <returns></returns>
        public DocumentSearchReturnValue GetMatterDocumentForDeepSearch(HostSecurityToken oHostSecurityToken, Guid projectId, DocumentSearchCriteria criteria)
        {
            DocumentSearchReturnValue ReturnValue = new DocumentSearchReturnValue();

            if (Functions.ValidateIWSToken(oHostSecurityToken))
            {
                oDocumentService = new DocumentService();
                ReturnValue      = oDocumentService.GetMatterDocumentForDeepSearch(Functions.GetLogonIdFromToken(oHostSecurityToken), projectId, criteria);
            }
            else
            {
                ReturnValue         = new DocumentSearchReturnValue();
                ReturnValue.Success = false;
                ReturnValue.Message = "Invalid Token";
            }
            return(ReturnValue);
        }