protected override void PersistNewItem(IRedirectUrl entity)
        {
            RedirectUrlDto dto = Map(entity);

            Database.Insert(dto);
            entity.Id = entity.Key.GetHashCode();
        }
示例#2
0
        private static IRedirectUrl Map(RedirectUrlDto dto)
        {
            if (dto == null)
            {
                return(null);
            }

            var url = new RedirectUrl();

            try
            {
                url.DisableChangeTracking();
                url.Key           = dto.Id;
                url.Id            = dto.Id.GetHashCode();
                url.ContentId     = dto.ContentId;
                url.ContentKey    = dto.ContentKey;
                url.CreateDateUtc = dto.CreateDateUtc;
                url.Culture       = dto.Culture;
                url.Url           = dto.Url;
                return(url);
            }
            finally
            {
                url.EnableChangeTracking();
            }
        }
        protected override IRedirectUrl PerformGet(Guid id)
        {
            Sql <ISqlContext> sql = GetBaseQuery(false).Where <RedirectUrlDto>(x => x.Id == id);
            RedirectUrlDto    dto = Database.Fetch <RedirectUrlDto>(sql.SelectTop(1)).FirstOrDefault();

            return(dto == null ? null : Map(dto));
        }
        public IRedirectUrl Get(string url, Guid contentKey, string culture)
        {
            var urlHash           = url.GenerateHash <SHA1>();
            Sql <ISqlContext> sql = GetBaseQuery(false).Where <RedirectUrlDto>(x =>
                                                                               x.Url == url && x.UrlHash == urlHash && x.ContentKey == contentKey && x.Culture == culture);
            RedirectUrlDto dto = Database.Fetch <RedirectUrlDto>(sql).FirstOrDefault();

            return(dto == null ? null : Map(dto));
        }
        public IRedirectUrl GetMostRecentUrl(string url)
        {
            var urlHash           = url.GenerateHash <SHA1>();
            Sql <ISqlContext> sql = GetBaseQuery(false)
                                    .Where <RedirectUrlDto>(x => x.Url == url && x.UrlHash == urlHash)
                                    .OrderByDescending <RedirectUrlDto>(x => x.CreateDateUtc);
            List <RedirectUrlDto> dtos = Database.Fetch <RedirectUrlDto>(sql);
            RedirectUrlDto        dto  = dtos.FirstOrDefault();

            return(dto == null ? null : Map(dto));
        }
        public IRedirectUrl GetMostRecentUrl(string url, string culture)
        {
            if (string.IsNullOrWhiteSpace(culture))
            {
                return(GetMostRecentUrl(url));
            }

            var urlHash           = url.GenerateHash <SHA1>();
            Sql <ISqlContext> sql = GetBaseQuery(false)
                                    .Where <RedirectUrlDto>(x => x.Url == url && x.UrlHash == urlHash &&
                                                            (x.Culture == culture.ToLower() || x.Culture == string.Empty))
                                    .OrderByDescending <RedirectUrlDto>(x => x.CreateDateUtc);
            List <RedirectUrlDto> dtos = Database.Fetch <RedirectUrlDto>(sql);
            RedirectUrlDto        dto  = dtos.FirstOrDefault(f => f.Culture == culture.ToLower());

            if (dto == null)
            {
                dto = dtos.FirstOrDefault(f => f.Culture == string.Empty);
            }

            return(dto == null ? null : Map(dto));
        }
        protected override void PersistUpdatedItem(IRedirectUrl entity)
        {
            RedirectUrlDto dto = Map(entity);

            Database.Update(dto);
        }