Пример #1
0
        public bool Exists(ISavedSearchSaveable input)
        {
            if (!IsAuthenticated)
            {
                return(false);
            }

            var entity = new SavedSearchEntity
            {
                SearchString = ExtractQueryString(input.Url),
                HasAlert     = input.AlertEnabled
            };

            var results = GetContentFromSessionOrRepo();

            var entities = results.Where(s => SavedSearchComparer.Equals(s, entity));

            return(entities != null && entities.Any() && entity.HasAlert ? entities.Any(a => a.HasAlert) : entities != null && entities.Any());
        }
Пример #2
0
        public virtual IContentResponse SaveContent(ISavedSearchSaveable input)
        {
            if (!IsAuthenticated)
            {
                return(new ContentResponse
                {
                    Success = false,
                    Message = "User is not authenticated"
                });
            }

            var id = new SavedSearchEntity
            {
                Username = _dependencies.UserContext.User.Username,
                Name     = input.Title
            };

            var entity = _dependencies.Repository.GetById(id);

            if (entity != null)
            {
                entity.HasAlert     = input.AlertEnabled;
                entity.SearchString = ExtractQueryString(input.Url);
                var updateResponse = _dependencies.Repository.Update(entity);
                Clear();

                return(updateResponse);
            }

            entity = id;
            entity.SearchString     = ExtractQueryString(input.Url);
            entity.UnsubscribeToken = GetUnsubscribeToken(entity);
            entity.Publication      = _dependencies.SiteSettings.GetCurrentSiteInfo()?.HostName;
            entity.HasAlert         = input.AlertEnabled;

            var addResponse = _dependencies.Repository.Add(entity);

            Clear();

            return(addResponse);
        }
Пример #3
0
        public virtual IContentResponse DeleteContent(ISavedSearchSaveable input)
        {
            if (!IsAuthenticated)
            {
                return(new ContentResponse
                {
                    Success = false,
                    Message = "User is not authenticated"
                });
            }

            ISavedSearchEntity entity = new SavedSearchEntity
            {
                Username     = _dependencies.UserContext.User.Username,
                Name         = input.Title,
                SearchString = ExtractQueryString(input.Url)
            };

            IContentResponse response = null;

            if (string.IsNullOrWhiteSpace(entity.Name))
            {
                var results  = GetContentFromSessionOrRepo();
                var entities = results.Where(e => SavedSearchComparer.Equals(e, entity));
                foreach (ISavedSearchEntity en in entities)
                {
                    response = _dependencies.Repository.Delete(en);
                }
            }
            else
            {
                response = _dependencies.Repository.Delete(entity);
            }

            Clear();

            return(response);
        }