public bool IsExistRoutingFriendlyUrl(Common.RoutingType routingType, string friendlyUrl)
 {
     if (_database.DefineRouting.FirstOrDefault(n => n.FriendlyUrlLv1.Equals(routingType.ToString(), StringComparison.CurrentCultureIgnoreCase) && n.FriendlyUrlLv2.Equals(friendlyUrl, StringComparison.CurrentCultureIgnoreCase)) != null)
     {
         return(true);
     }
     return(false);
 }
        public string GetUrl(Common.RoutingType routingType, int entityId)
        {
            var routing = _routingRepository.GetDefineRouting(routingType.ToString(), entityId);

            if (routing != null)
            {
                var url = string.Format(@"/{0}/{1}", routing.FriendlyUrlLv1, routing.FriendlyUrlLv2);
                return(url);
            }
            return(null);
        }
        public bool Insert(Common.RoutingType routingType, int userId, Category category = null, Content content = null, Author author = null, Tag tag = null)
        {
            try
            {
                var defineRouting = new DefineRouting();
                switch (routingType)
                {
                case Common.RoutingType.Category:
                {
                    defineRouting.Controller     = Constants.CategoryController;
                    defineRouting.Action         = Constants.CategoryAction;
                    defineRouting.FriendlyUrlLv2 = NormalizeFriendlyUrl(routingType, ExtensionMethod.GenerateSlug(category.Title));
                    defineRouting.EntityId       = category.CategoryId;
                    break;
                }

                case Common.RoutingType.Content:
                {
                    defineRouting.Controller     = Constants.ContentController;
                    defineRouting.Action         = Constants.ContentAction;
                    defineRouting.FriendlyUrlLv2 = NormalizeFriendlyUrl(routingType, ExtensionMethod.GenerateSlug(content.Title));
                    defineRouting.EntityId       = content.ContentId;
                    break;
                }

                case Common.RoutingType.Author:
                {
                    defineRouting.Controller     = Constants.AuthorController;
                    defineRouting.Action         = Constants.AuthorAction;
                    defineRouting.FriendlyUrlLv2 = NormalizeFriendlyUrl(routingType, ExtensionMethod.GenerateSlug(string.Format("{0} {1}", author.FirstName.Trim(), author.LastName.Trim())));
                    defineRouting.EntityId       = author.AuthorId;
                    break;
                }

                case Common.RoutingType.Tag:
                {
                    defineRouting.Controller     = Constants.TagController;
                    defineRouting.Action         = Constants.TagAction;
                    defineRouting.FriendlyUrlLv2 = NormalizeFriendlyUrl(routingType, ExtensionMethod.GenerateSlug(tag.TagName));
                    defineRouting.EntityId       = tag.TagId;
                    break;
                }
                }
                defineRouting.FriendlyUrlLv1 = routingType.ToString().ToLower();
                defineRouting.CreatedUserId  = defineRouting.UpdatedUserId = userId;
                _routingRepository.Create(defineRouting);
                return(true);
            }
            catch
            {
                return(false);
            }
        }