public ActionResult AddOrUpdate(int id = 0)
        {
            Category category = null;

            if (id == 0)
            {
                category = new Category();
            }
            else
            {
                category = _categoryRepository.Get(id);
            }


            ViewBag.CategoriesSelectListItem = CategoryRepository.GetAllWithoutCategoryId(id).Select(item => new SelectListItem
            {
                Text  = item.Title,
                Value = item.Id.ToString()
            });
            var routeItem = _routeItemRepository.Get((string)ControllerContext.RequestContext.RouteData.Values["controller"],
                                                     "Index",
                                                     category.Id);

            ViewBag.CurrentFriendlyUrl = routeItem != null ? routeItem.FriendlyUrl : null;

            return(View(category));
        }
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            if (requestContext.HttpContext.Request.Url != null)
            {
                HostName = requestContext.HttpContext.Request.Url.Authority;
            }
            if (requestContext.RouteData.Values["controller"] != null)
            {
                ViewBag.Path      += requestContext.RouteData.Values["controller"] + "/";
                ViewBag.Controller = requestContext.RouteData.Values["controller"];
            }
            if (requestContext.RouteData.Values["action"] != null)
            {
                ViewBag.Path  += requestContext.RouteData.Values["action"].ToString();
                ViewBag.Action = requestContext.RouteData.Values["action"];
            }
            var rootCategories = _categoryRepository.GetRootCategoriesWithSubs();

            var modelRootCategories = rootCategories.Select(s => new Models.AllCategoriesViewModel()
            {
                Category      = s.Category,
                SubCategories = s.SubCategories
            });
            var modelBaseFriendlyUrl = new FriendlyUrlBaseModel();

            modelBaseFriendlyUrl.ColoringFriendlyUrl           = _routeItemRepository.GetFriendlyUrl(2, Common.TypeEntityFromRouteEnum.PageType);
            modelBaseFriendlyUrl.CompanyFriendlyUrl            = _routeItemRepository.GetFriendlyUrl(4, Common.TypeEntityFromRouteEnum.PageType);
            modelBaseFriendlyUrl.ContactsFriendlyUrl           = _routeItemRepository.GetFriendlyUrl(8, Common.TypeEntityFromRouteEnum.PageType);
            modelBaseFriendlyUrl.CooperationFriendlyUrl        = _routeItemRepository.GetFriendlyUrl(6, Common.TypeEntityFromRouteEnum.PageType);
            modelBaseFriendlyUrl.EventBaseFriendlyUrl          = _routeItemRepository.Get("Event", "Index", null).FriendlyUrl;
            modelBaseFriendlyUrl.FaqBaseFriendlyUrl            = _routeItemRepository.Get("Faq", "Index", null).FriendlyUrl;
            modelBaseFriendlyUrl.JobsFriendlyUrl               = _routeItemRepository.GetFriendlyUrl(7, Common.TypeEntityFromRouteEnum.PageType);
            modelBaseFriendlyUrl.MarksFriendlyUrl              = _routeItemRepository.GetFriendlyUrl(5, Common.TypeEntityFromRouteEnum.PageType);
            modelBaseFriendlyUrl.ShippingFriendlyUrl           = _routeItemRepository.GetFriendlyUrl(3, Common.TypeEntityFromRouteEnum.PageType);
            modelBaseFriendlyUrl.RecommendationBaseFriendlyUrl = _routeItemRepository.Get("Recommendation", "Index", null).FriendlyUrl;
            ViewBag.FriendlyUrlBase = modelBaseFriendlyUrl;

            ViewBag.FooterCategories = modelRootCategories;
            base.Initialize(requestContext);
            Cart cart = GetCart();

            ViewBag.Cart = cart;
        }
Beispiel #3
0
        public ActionResult AddOrUpdate(int id = 0)
        {
            var model = _productRepository.Get(id);

            var categoriesViewModel = _categoryRepository.GetAll().Select(i => new Models.CategoryAdminViewModel {
                Checked = false,
                Id      = i.Id,
                Title   = i.Title
            }).ToList();



            if (model != null && model.Categories != null)
            {
                foreach (var item in model.Categories)
                {
                    categoriesViewModel.FirstOrDefault(i => i.Id == item.Id).Checked = true;
                }
            }
            else
            {
                model = new Product();
            }

            ViewBag.FiltersSelectList = _filterRepository.GetAll().ToList().Select(item => new SelectListItem
            {
                Text  = item.Title,
                Value = item.Id.ToString()
            });

            ViewBag.EnumValuesSelectList = _enumRepositopy.GetAll().ToList().Select(item => new SelectListItem
            {
                Text  = item.Key,
                Value = item.Id.ToString()
            });

            ViewBag.AllCategories      = categoriesViewModel;
            ViewBag.AllRecommendations = _recommendationRepository.GetAll().Select(item => new SelectListItem
            {
                Text  = item.Title,
                Value = item.Id.ToString()
            });
            var routeItem = _routeItemRepository.Get((string)ControllerContext.RequestContext.RouteData.Values["controller"],
                                                     "Index",
                                                     id);

            ViewBag.CurrentFriendlyUrl = routeItem != null ? routeItem.FriendlyUrl : null;
            return(View(model));
        }
Beispiel #4
0
        protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            // Path для www.site.com/helloworld?id=1 будет равняться /helloworld
            // поэтому мы убираем начальный слэш

            var url = requestContext.HttpContext.Request.Path;

            /*
             * if (!string.IsNullOrEmpty(url)&&TypicalLink.IsMatch(url))
             * {
             * var controller = (string)requestContext.RouteData.Values["controller"];
             * var action = (string)requestContext.RouteData.Values["action"];
             * var strId = (string)requestContext.RouteData.Values["id"];
             * int id = -1;
             * int.TryParse(strId, out id);
             * if (id!=-1)
             * {
             *     RouteItem page = _routeItemRepository.Get(controller,action,id);
             *     if (page != null&&!string.IsNullOrEmpty(page.FriendlyUrl))
             *     {
             *         requestContext.HttpContext.Response.RedirectPermanent(page.FriendlyUrl);
             *
             *     }
             * }
             *
             * }*/
            if (!string.IsNullOrEmpty(url) && !AdminTypicalLink.IsMatch(url))
            {
                RouteItem page = _routeItemRepository.Get(url);
                if (page != null)
                {
                    FillRequest(page.ControllerName,
                                page.ActionName ?? "Index",
                                page.ContentId.ToString(),
                                requestContext);
                }
            }

            return(base.GetHttpHandler(requestContext));
        }