Ejemplo n.º 1
0
        public void UpdateNewsItem(NewsItem news)
        {
            var originHeart = _heartService.GetHeart(news.HeartId);

            if (news.RelativeUrl != originHeart.RelativeUrl)
            {
                bool relativeUrlExists = _heartService.CheckIfUrlExists(news.RelativeUrl);
                if (relativeUrlExists)
                {
                    throw new ArgumentException("Этот адрес уже занят");
                }
            }

            var dataRec          = Mapper.Map <Data.Models.NewsItem>(news);
            var tags             = !string.IsNullOrEmpty(news.Tags) ? news.Tags.Split(',').Select(x => x.Trim().ToLower()).ToList() : new List <string>();
            var originalTags     = _tagGateway.SelectByNews(news.HeartId);
            var existingTags     = _tagGateway.Select();
            var existingTagNames = existingTags.Select(x => x.Name).ToArray();

            var existingCatIds = _newsItemCategoryGateway.SelectCategoryIdsByNews(news.HeartId);
            var catIds         = news.Categories.Select(x => x.ID).ToArray();

            using (var ts = new TransactionScope())
            {
                _heartService.UpdateHeart(news);

                _newsItemGateway.Update(dataRec);

                foreach (var tag in tags.Except(existingTagNames))
                {
                    int tagId = _tagGateway.Insert(tag);
                    _newsItemTagGateway.Insert(news.HeartId, tagId);
                }
                foreach (var tag in existingTags.Where(x => tags.Contains(x.Name) && originalTags.All(y => y.TagId != x.TagId)))
                {
                    _newsItemTagGateway.Insert(news.HeartId, tag.TagId);
                }

                if (originalTags.Any(x => !tags.Contains(x.Name)))
                {
                    foreach (var tag in originalTags.Where(x => !tags.Contains(x.Name)))
                    {
                        _newsItemTagGateway.Delete(news.HeartId, tag.TagId);
                    }
                    _tagGateway.DeleteUnassociated();
                }

                foreach (var catId in catIds.Except(existingCatIds))
                {
                    _newsItemCategoryGateway.Insert(news.HeartId, catId);
                }
                foreach (var catId in existingCatIds.Except(catIds))
                {
                    _newsItemCategoryGateway.Delete(news.HeartId, catId);
                }
                _searchService.UpdateIndex(news);
                ts.Complete();
            }
        }
Ejemplo n.º 2
0
        public ActionResult CategorySEF(string relativeUrl, int?country, int?manufacturerId, int?packId, object specs, SortCriterion?sort,
                                        List <List <int> > catFilter = null, int?minPrice = null, int?maxPrice = null, string query = null)
        {
            string pageUrl = relativeUrl.Split('/').Last();
            bool   exists  = _heartService.CheckIfUrlExists(pageUrl);

            if (!exists)
            {
                throw new HttpException(404, "Not found");
            }
            var routeValues = Request.RequestContext.RouteData.Values;

            if (catFilter != null && (catFilter.Count() > 1 || catFilter.Any(x => x.Count() > 1)))
            {
                routeValues["relativeUrl"] = _shopUrl;
                return(RedirectPermanent(Url.RouteUrl(typeof(Page).FullName, routeValues)));
            }


            var cat = _heartService.GetHeart(pageUrl);

            if (catFilter != null && catFilter.Count() == 1 && catFilter.First().Count() == 1)
            {
                int catFilterId = catFilter.First().First();
                if (cat.HeartId != catFilterId)
                {
                    var filterCat = _heartService.GetHeart(catFilterId);
                    routeValues["relativeUrl"] = filterCat.RelativeUrl;
                    routeValues.Remove("cats");
                    return(RedirectPermanent(Url.RouteUrl(typeof(Category).FullName, routeValues)));
                }
            }


            var requestPath = Request.Path.Substring(1);

            if (!cat.CanonicalUrl.Equals(requestPath, StringComparison.InvariantCultureIgnoreCase))
            {
                //routeValues["relativeUrl"] = cat.CanonicalUrl;

                return(RedirectPermanent(Url.RouteUrl(typeof(Category).FullName, routeValues)));
            }

            int id = cat.HeartId;

            int page   = ViewBag.Page;
            int pgsize = ViewBag.PageSize;

            var filter = new GoodsFilter()
            {
                CategoryIds   = new[] { new[] { id } },
                ClientMode    = true,
                MinPrice      = minPrice,
                MaxPrice      = maxPrice,
                SearchPattern = query
            };
            var goods = GetGoodsPage(filter, sort, (Dictionary <int, string>)specs, packId, country, manufacturerId, page, pgsize);

            ViewBag.PagingRoute = typeof(Category).FullName;
            ViewBag.CategoryId  = id;

            TempData["MetaKeywords"]      = cat.MetaKeywords;
            TempData["MetaDescription"]   = cat.MetaDescription;
            TempData["AdditionalHeaders"] = cat.AdditionalHeaders;

            return(PartialView("GoodsPage", goods));
        }