Example #1
0
        public ActionResult CourtAct(int id, int?siteSearchId)
        {
            CourtAct courtAct = null;

            if (this.CheckRights)
            {
                int[]             productIds = Doc.GetDocProducts(id);
                IEnumerable <int> prod       = this.UserData.Products.Select(p => p.ProductId).ToArray().Intersect(productIds);
                if (prod.Count() == 0)
                {
                    string[] products = ((List <Product>) this.Session["ProductsList"]).Where(p => productIds.Contains(p.ProductId) == true).Select(p => p.ProductName).ToArray();
                    string   errorMsg = "To open this document you need valid license for '" + String.Join("' or '", products) + "'";

                    this.ViewBag.DocError = errorMsg;
                    return(this.View(new CourtAct()));
                }
            }

            bool showFreeDocs = this.UserData.ShowFreeDocuments;

            #region Search and stats creatings
            if (siteSearchId.HasValue)
            {
                ViewBag.SiteSearchId = siteSearchId.Value;
                //int searchId = int.Parse(siteSearchId.Substring(siteSearchId.LastIndexOf('-') + 1));

                SearchResult sr = SearchResult.FindSearchResult(siteSearchId.Value, this.Session["SearchResults"]);

                if (sr != null)
                {
                    // if text is searched - add to statistic
                    if (sr.StatSearchId.HasValue)
                    {
                        Stat.SetStatSearchDoc(sr.StatSearchId.Value, id);
                    }

                    if (sr.SearchSource == SearchSources.Search)
                    {
                        if (this.Session["local-search-" + id + "-" + siteSearchId] != null && this.Session["local-search-" + id + "-" + siteSearchId].ToString() != "")
                        {
                            var highLightParams = new DocHighlightSearchParams(
                                this.Session["local-search-" + id + "-" + siteSearchId].ToString(),
                                null,
                                Convert.ToBoolean(this.Session["local-search-exactmatch-" + id + "-" + siteSearchId]),
                                null,
                                null);

                            courtAct = CourtActBL.GetCourtAct(
                                id,
                                this.Language.Id,
                                this.UserData.UserId,
                                highLightParams,
                                this.ProductId,
                                showFreeDocs);
                        }
                        else
                        {
                            var complexSearchText = sr.SearchBoxFilters.SearchText;
                            if (sr.SearchBoxFilters.Cases != null && !String.IsNullOrEmpty(sr.SearchBoxFilters.Cases.MultiDict.Text))
                            {
                                if (!String.IsNullOrEmpty(sr.SearchBoxFilters.SearchText))
                                {
                                    complexSearchText = complexSearchText + " AND (";
                                }
                                else
                                {
                                    complexSearchText = "(";
                                }

                                complexSearchText = complexSearchText + sr.SearchBoxFilters.Cases.MultiDict.Text;    // combining search text with multilingial dictionary if present
                                complexSearchText = complexSearchText.Replace("OR", "[OR]").Replace("AND", "[AND]"); // trimming logical operators
                                complexSearchText = complexSearchText + ")";
                            }
                            else if (sr.SearchBoxFilters.Law != null && !String.IsNullOrEmpty(sr.SearchBoxFilters.Law.MultiDict.Text))
                            {
                                if (!String.IsNullOrEmpty(sr.SearchBoxFilters.SearchText))
                                {
                                    complexSearchText = complexSearchText + " AND (";
                                }
                                else
                                {
                                    complexSearchText = "(";
                                }

                                complexSearchText = complexSearchText + sr.SearchBoxFilters.Law.MultiDict.Text;      // combining search text with multilingial dictionary if present
                                complexSearchText = complexSearchText.Replace("OR", "[OR]").Replace("AND", "[AND]"); // trimming logical operators
                                complexSearchText = complexSearchText + ")";
                            }
                            else if (sr.SearchBoxFilters.MultiDict != null && !String.IsNullOrEmpty(sr.SearchBoxFilters.MultiDict.Text))
                            {
                                if (!String.IsNullOrEmpty(sr.SearchBoxFilters.SearchText))
                                {
                                    complexSearchText = complexSearchText + " AND (";
                                }
                                else
                                {
                                    complexSearchText = "(";
                                }

                                complexSearchText = complexSearchText + sr.SearchBoxFilters.MultiDict.Text;          // combining search text with multilingial dictionary if present
                                complexSearchText = complexSearchText.Replace("OR", "[OR]").Replace("AND", "[AND]"); // trimming logical operators
                                complexSearchText = complexSearchText + ")";
                            }

                            var highLightParams = new DocHighlightSearchParams();

                            if (!String.IsNullOrEmpty(sr.SearchBoxFilters.SearchTextMultiLingual))
                            {
                                highLightParams.SearchText = complexSearchText;
                                highLightParams.MultilingualSearchedText = sr.SearchBoxFilters.SearchTextMultiLingual;
                                highLightParams.ExactMatch = sr.SearchBoxFilters.ExactMatch;

                                if (sr.SearchBoxFilters.Cases != null && !String.IsNullOrEmpty(sr.SearchBoxFilters.Cases.NatID_ECLI))
                                {
                                    highLightParams.SearchedCelex = sr.SearchBoxFilters.Cases.NatID_ECLI;
                                }
                                else
                                {
                                    courtAct = CourtActBL.GetCourtAct(
                                        id,
                                        this.Language.Id,
                                        this.UserData.UserId,
                                        highLightParams,
                                        this.ProductId,
                                        showFreeDocs);
                                }
                            }
                            else
                            {
                                highLightParams.SearchText = complexSearchText;
                                highLightParams.ExactMatch = sr.SearchBoxFilters.ExactMatch;

                                if (sr.SearchBoxFilters.Cases != null)
                                {
                                    if (!String.IsNullOrEmpty(sr.SearchBoxFilters.Cases.EnactmentCelex))
                                    {
                                        highLightParams.SearchedCelex = sr.SearchBoxFilters.Cases.EnactmentCelex;
                                    }

                                    if (!String.IsNullOrEmpty(sr.SearchBoxFilters.Cases.ProvisionParOriginal))
                                    {
                                        var searchedPars = new List <string>();
                                        searchedPars.Add(sr.SearchBoxFilters.Cases.ProvisionParOriginal);
                                        highLightParams.SearchedPars = searchedPars;
                                    }
                                }

                                courtAct = CourtActBL.GetCourtAct(
                                    id,
                                    this.Language.Id,
                                    this.UserData.UserId,
                                    highLightParams,
                                    this.ProductId,
                                    showFreeDocs);
                            }
                        }
                    }
                    else if (sr.SearchSource == SearchSources.InLinks)
                    {
                        var highlightParams = new DocHighlightSearchParams();
                        if (!String.IsNullOrEmpty(sr.SearchBoxFilters.DocInLinks.ToDocNumber))
                        {
                            highlightParams.SearchedCelex = sr.SearchBoxFilters.DocInLinks.ToDocNumber;
                        }

                        if (sr.SearchBoxFilters.DocInLinks.ToPars != null && sr.SearchBoxFilters.DocInLinks.ToPars.Count > 0)
                        {
                            highlightParams.SearchedPars = sr.SearchBoxFilters.DocInLinks.ToPars;
                        }

                        /* Highlight for inlinks should go here */

                        courtAct = CourtActBL.GetCourtAct(
                            id,
                            this.Language.Id,
                            this.UserData.UserId,
                            highlightParams,
                            this.ProductId,
                            showFreeDocs);
                    }
                }
            }
            else if (this.Session["local-search-" + id + "-" + siteSearchId] != null && this.Session["local-search-" + id + "-" + siteSearchId].ToString() != "")
            {
                var highLightParams = new DocHighlightSearchParams();
                highLightParams.SearchText = this.Session["local-search-" + id + "-" + siteSearchId].ToString();
                highLightParams.ExactMatch = Convert.ToBoolean(this.Session["local-search-exactmatch-" + id + "-" + siteSearchId]);

                courtAct = CourtActBL.GetCourtAct(
                    id,
                    this.Language.Id,
                    this.UserData.UserId,
                    highLightParams,
                    this.ProductId,
                    showFreeDocs);
            }
            else if (this.Session["local-search-" + id] != null && this.Session["local-search-exactmatch-" + id] != null)
            {
                var highLightParams = new DocHighlightSearchParams();
                highLightParams.SearchText = this.Session["local-search-" + id].ToString();
                highLightParams.ExactMatch = Convert.ToBoolean(this.Session["local-search-exactmatch-" + id + "-" + siteSearchId]);

                courtAct = CourtActBL.GetCourtAct(
                    id,
                    this.Language.Id,
                    this.UserData.UserId,
                    highLightParams,
                    this.ProductId,
                    showFreeDocs);
            }

            if (courtAct == null)
            {
                var highLightParams = new DocHighlightSearchParams(null, null, false, null, null);

                courtAct = CourtActBL.GetCourtAct(
                    id,
                    this.Language.Id,
                    this.UserData.UserId,
                    highLightParams,
                    this.ProductId,
                    showFreeDocs);
            }

            #endregion

            if (courtAct != null)
            {
                // Rewriting inline links before visualization
                var linkRewriter = new DocLinksRewriter(courtAct.LangId, WebAppHelper.AppRootFolder, this.UserData.OpenDocumentsInNewTab, this.NationalLegislationMapPath);
                courtAct.RewriteInLineLinks(linkRewriter);

                this.ViewBag.Title = courtAct.HtmlModel.Title.Value.ToString();
                //only limited number of docs are avaiable in sysdemo
                //List<string> avaiableDocsCelexes = ConfigurationManager.AppSettings["SysDemoDocumentsCelex"].ToString().Split(',').ToList();
                //if (this.UserData.Username.ToLower() == "sysdemo")
                //{
                //    Regex reglamentsAndDirectivesRegex = new Regex("3.{4}[RrLl](.*)");

                //    if (!((courtAct.DocType == 2 && !courtAct.DocNumber.StartsWith("7")) ||
                //        avaiableDocsCelexes.Any(c => c == courtAct.DocNumber) ||
                //        (courtAct.DocType == 1 && courtAct.DocNumber.Substring(0, 1) == "6" && courtAct.Country.ToLower() == "eu") ||
                //        reglamentsAndDirectivesRegex.IsMatch(courtAct.DocNumber) ||
                //        Doc.IsInternationalStandartDoc(courtAct.DocLangId) ||
                //        Doc.IsDemoDoc(courtAct.DocLangId)))
                //    {
                //        if (Common.CheckRequestOriginIsBotSoft(this.Request.UserAgent) || this.DemoBonusDocumentsCheck(courtAct.DocNumber) == false)
                //        {
                //            var productFeaturesInfo = new ProductFeaturesInfo(FunctionalityTypes.DocumentOpen, courtAct);
                //            string viewName = this.ProductId == 1 ? "~/Views/Shared/_ProductFeaturesInfo_Wrapper.cshtml" : "~/Views/Shared/_ProductFeaturesInfo_Finances.cshtml";
                //            this.ViewBag.UseLayout = true;
                //            return this.View(viewName, productFeaturesInfo);
                //        }
                //        else
                //        {
                //            // refresh bonus docs cookie
                //            var currentBonusDocsCookie = this.Request.Cookies["dmbnsdcs"];
                //            var newCookie = this.ComputeDemoBonusDocsCookie(currentBonusDocsCookie, courtAct.DocNumber);
                //            this.Response.Cookies.Set(newCookie);
                //        }
                //    }
                //}

                // add ro recent documents
                int maxCount     = Convert.ToInt32(ConfigurationManager.AppSettings["RecentDocumentsCount"]);
                int curProductId = 1;
                if (this.Session["SelectedProductId"] != null)
                {
                    curProductId = int.Parse(this.Session["SelectedProductId"].ToString());
                }

                if (this.UserData.Username.ToLower() != "sysdemo" ||
                    (this.UserData.Username.ToLower() == "sysdemo" && !Common.CheckRequestOriginIsBotSoft(this.Request.UserAgent)))
                {
                    Doc.AddRecentDoc(this.UserData.UserId, id, maxCount, curProductId); // add to recent documents
                    Doc.AddOpenedDoc(this.UserData.UserId, id, curProductId);           // add to stat
                }

                if (courtAct.BloblInfo.IsBlob)
                {
                    var contentType = MimeMapping.GetMimeMapping(courtAct.BloblInfo.Path);

                    return(this.File(fileName: courtAct.BloblInfo.Path, contentType: contentType));
                }
                else
                {
                    return(this.View(courtAct));
                }
            }
            else
            {
                return(this.RedirectToAction("Index", "Home"));
            }
        }