/// <summary> /// Searches the publication. /// </summary> /// <param name="siteId">The site id.</param> /// <param name="contactId">The contact id.</param> /// <param name="publicationKind">Kind of the publication.</param> /// <param name="text">The text.</param> /// <param name="pageIndex">Index of the page.</param> /// <param name="totalCount">The total count.</param> /// <param name="portalSettingsId">The portal settings id.</param> /// <param name="publicationType">Type of the publication.</param> /// <param name="initUrls">if set to <c>true</c> [init urls].</param> /// <param name="isPortal">if set to <c>true</c> [is portal].</param> /// <returns></returns> public List <ActivityPublicationMap> SearchPublication(Guid siteId, Guid?contactId, int?publicationKind, string text, int pageIndex, out int totalCount, Guid?portalSettingsId = null, Guid?publicationType = null, bool initUrls = true, bool isPortal = false) { var publicationMaps = new List <ActivityPublicationMap>(); totalCount = 0; using (var connection = new SqlConnection(Settings.ADONetConnectionString)) { connection.Open(); var command = new SqlCommand("SearchPublication", connection) { CommandType = CommandType.StoredProcedure }; command.Parameters.AddWithValue("@SiteID", siteId); command.Parameters.AddWithValue("@ContactID", contactId); command.Parameters.AddWithValue("@Word", string.IsNullOrEmpty(text) ? "*" : text); command.Parameters.AddWithValue("@PageIndex", pageIndex); command.Parameters.AddWithValue("@PageSize", 5); command.Parameters.AddWithValue("@IsPortal", portalSettingsId.HasValue || isPortal); if (publicationKind != -1) { command.Parameters.AddWithValue("@PublicationKindID", publicationKind); } command.Parameters.AddWithValue("@PublicationTypeID", publicationType); var reader = command.ExecuteReader(); while (reader.HasRows) { while (reader.Read()) { var publicationMap = new ActivityPublicationMap { ID = (Guid)reader["ID"], Date = (DateTime)reader["Date"], Title = (string)reader["Title"], Text = reader["Text"] != DBNull.Value ? (string)reader["Text"] : null, Noun = reader["Noun"] != DBNull.Value ? (string)reader["Noun"] : null, PublicationKindID = reader["PublicationKindID"] != DBNull.Value ? (int?)reader["PublicationKindID"] : null }; totalCount = (int)reader["TotalCount"]; publicationMaps.Add(publicationMap); } reader.NextResult(); } } var dataManager = new DataManager(); PortalSettingsMap portalSettings = null; if (!portalSettingsId.HasValue) { portalSettings = dataManager.PortalSettings.SelectMapBySiteId(siteId, true); } foreach (var publicationMap in publicationMaps) { if (string.IsNullOrEmpty(publicationMap.Noun)) { publicationMap.Noun = publicationMap.Text; publicationMap.Text = string.Empty; } publicationMap.Noun = publicationMap.Noun.Truncate(300, true, true); if (initUrls) { if (portalSettingsId.HasValue) { if (publicationMap.PublicationKindID == (int)PublicationKind.Discussion) { publicationMap.PublicationUrl = UrlsData.LFP_Discussion((Guid)portalSettingsId, publicationMap.ID); } else { publicationMap.PublicationUrl = UrlsData.LFP_Article((Guid)portalSettingsId, publicationMap.ID); } } else { publicationMap.PublicationUrl = UrlsData.AP_PublicationEdit(publicationMap.ID, "Materials"); } if (portalSettings != null) { publicationMap.PortalUrl = string.Concat(Settings.LabitecLeadForcePortalUrl, string.Format("/{0}/KnowledgeBase/Article/{1}", portalSettings.ID, publicationMap.ID)); } } } return(publicationMaps); }
/// <summary> /// Selects the activity ribbon. /// </summary> /// <param name="siteId">The site id.</param> /// <param name="contactId">The contact id.</param> /// <param name="publicationTypeId">The publication type id.</param> /// <param name="publicationCategoryId">The publication category id.</param> /// <param name="filter">The filter.</param> /// <param name="pageIndex">Index of the page.</param> /// <param name="portalSettingsId">The portal settings id.</param> /// <returns></returns> public List <ActivityPublicationMap> SelectActivityRibbon(Guid siteId, Guid?contactId, Guid publicationTypeId, Guid publicationCategoryId, string filter, int pageIndex, Guid?portalSettingsId = null) { var dataManager = new DataManager(); var publications = _dataContext.tbl_Publication.Where(c => c.SiteID == siteId && c.tbl_PublicationType.PublicationKindID == (int)PublicationKind.Discussion); if (portalSettingsId.HasValue) { publications = publications.Where(p => p.tbl_PublicationStatus.isActive == true); } if (publicationTypeId != Guid.Empty) { publications = publications.Where(p => p.tbl_PublicationType.ID == publicationTypeId); } if (publicationCategoryId != Guid.Empty) { var categoryIds = dataManager.PublicationCategory.SelectChilds(siteId, publicationCategoryId).Select(pc => pc.ID).ToList(); publications = publications.Where(p => categoryIds.Contains(p.PublicationCategoryID) || p.PublicationCategoryID == publicationCategoryId); } var publicationsMap = new List <ActivityPublicationMap>(); const int pageSize = 15; var publicationsMapQuerable = publications.Select( p => new ActivityPublicationMap() { ID = p.ID, AuthorID = p.AuthorID, Date = p.Date, Title = p.Title, Text = p.Text, FileName = p.FileName, PublicationTypeLogo = p.tbl_PublicationType.Logo, Category = p.tbl_PublicationCategory.Title, Status = p.tbl_PublicationStatus.Title, SumLike = (int?)p.tbl_PublicationMark.Where(pm => pm.Rank == 1 && pm.PublicationCommentID == null).Sum(pm => pm.Rank) ?? 0, ContactLike = p.tbl_PublicationMark.Where(pm => contactId.HasValue && pm.UserID == contactId).Select(pm => pm.Rank).FirstOrDefault(), OfficialComment = p.tbl_PublicationComment.Where(pc => pc.isOfficialAnswer).Select(pc => pc.Comment).FirstOrDefault(), CommentsCount = p.tbl_PublicationComment.Count, AccessRecord = p.AccessRecord, AccessComment = p.AccessComment, AccessCompanyID = p.AccessCompanyID }); if (portalSettingsId.HasValue) { if (!contactId.HasValue || contactId == Guid.Empty) { publicationsMapQuerable = publicationsMapQuerable.Where(p => p.AccessRecord == (int)PublicationAccessRecord.Anonymous); } else { var contact = dataManager.Contact.SelectById(siteId, (Guid)contactId); if (contact != null) { var contactCompanyId = contact.CompanyID; publicationsMapQuerable = publicationsMapQuerable.Where(p => p.AccessRecord == (int)PublicationAccessRecord.Public || p.AccessRecord == (int)PublicationAccessRecord.Anonymous || (p.AccessRecord == (int)PublicationAccessRecord.Personal && p.AuthorID == contactId) || (p.AccessRecord == (int)PublicationAccessRecord.Company && p.AccessCompanyID == contactCompanyId)); } else { publicationsMapQuerable = publicationsMapQuerable.Where(p => p.AccessRecord == (int)PublicationAccessRecord.Anonymous); } } } if (!string.IsNullOrEmpty(filter)) { switch (filter.ToLower()) { case "top": publicationsMap = publicationsMapQuerable.OrderByDescending(p => p.SumLike).Skip(pageIndex * pageSize).Take(pageSize).ToList(); break; case "new": publicationsMap = publicationsMapQuerable.OrderByDescending(p => p.Date).Skip(pageIndex * pageSize).Take(pageSize).ToList(); break; case "mypublication": publicationsMap = publicationsMapQuerable.Where(p => p.AuthorID == contactId).OrderByDescending(p => p.Date).Skip(pageIndex * pageSize).Take(pageSize).ToList(); break; } } else { publicationsMap = publicationsMapQuerable.OrderByDescending(p => p.Date).Skip(pageIndex * pageSize).Take(pageSize).ToList(); } var fsp = new FileSystemProvider(); foreach (var publicationMap in publicationsMap) { publicationMap.ContactLikeUserText = GetLikeCountWithCase(publicationMap.SumLike ?? 0); publicationMap.OfficialComment = publicationMap.OfficialComment.ToHtml(); publicationMap.PublicationTypeLogo = Settings.DictionaryLogoPath(siteId, "tbl_PublicationType") + publicationMap.PublicationTypeLogo; if (publicationMap.Date.HasValue) { publicationMap.FormattedDate = ((DateTime)publicationMap.Date).ToString("d MMMM в HH:mm"); } if (!string.IsNullOrEmpty(publicationMap.FileName)) { publicationMap.FileName = fsp.GetLink(siteId, "Publications", publicationMap.FileName, FileType.Attachment); } if (portalSettingsId.HasValue) { publicationMap.PublicationUrl = UrlsData.LFP_Discussion((Guid)portalSettingsId, publicationMap.ID); } else { publicationMap.PublicationUrl = UrlsData.AP_PublicationEdit(publicationMap.ID, "Materials"); } } return(publicationsMap); }