public async Task <bool> DeleteAllAsyc(List <int> ids)
 {
     try
     {
         return(await _dataService.DeleteAllById <TEntity>(ids));
     }
     catch (Exception ex)
     {
         LogOrThrow(ex);
     }
     return(false);
 }
Example #2
0
        public static async Task SaveArticleLeadImage(ArticleModel model, ISqliteService service, bool skipCleaning = false)
        {
            var imageContentGenericRepository  = new GenericRepository <ImageContentModel, ImageContentEntity>(service);
            List <ContentEntity> oldLeadImages = null;
            var articleId = model.GetId();

            if (!skipCleaning)
            {
                oldLeadImages = (await service.GetByCondition <ContentEntity>(e => e.ParentId == articleId && e.ContentType == (int)ContentType.LeadImage, null, false, 0, 0)).ToList();
            }

            if (model.LeadImage != null)
            {
                if (model.LeadImage.GetId() != 0)
                {
                    var leadImageId  = model.LeadImage.GetId();
                    var oldLeadImage = oldLeadImages?.FirstOrDefault(o => o.ContentId == leadImageId);
                    if (oldLeadImage != null)
                    {
                        oldLeadImages?.Remove(oldLeadImage);
                    }

                    await imageContentGenericRepository.SaveAsyc(model.LeadImage);
                }
                else
                {
                    await imageContentGenericRepository.SaveAsyc(model.LeadImage);

                    var entity = new ContentEntity
                    {
                        ContentId   = model.LeadImage.GetId(),
                        ParentId    = model.GetId(),
                        Index       = 0,
                        ContentType = (int)ContentType.LeadImage
                    };
                    await service.Add(entity);
                }
            }

            if (!skipCleaning)
            {
                await service.DeleteAllById <ContentEntity>(oldLeadImages.Select(d => d.Id));
            }
        }
Example #3
0
        public static async Task SaveArticleLeadImage(ArticleModel model, ISqliteService service, bool skipCleaning = false)
        {
            var imageContentGenericRepository = new GenericRepository<ImageContentModel, ImageContentEntity>(service);
            List<ContentEntity> oldLeadImages = null;
            var articleId = model.GetId();
            if (!skipCleaning)
                oldLeadImages = (await service.GetByCondition<ContentEntity>(e => e.ParentId == articleId && e.ContentType == (int)ContentType.LeadImage, null, false, 0, 0)).ToList();

            if (model.LeadImage != null)
            {
                if (model.LeadImage.GetId() != 0)
                {
                    var leadImageId = model.LeadImage.GetId();
                    var oldLeadImage = oldLeadImages?.FirstOrDefault(o => o.ContentId == leadImageId);
                    if (oldLeadImage != null)
                        oldLeadImages?.Remove(oldLeadImage);

                    await imageContentGenericRepository.SaveAsyc(model.LeadImage);
                }
                else
                {
                    await imageContentGenericRepository.SaveAsyc(model.LeadImage);

                    var entity = new ContentEntity
                    {
                        ContentId = model.LeadImage.GetId(),
                        ParentId = model.GetId(),
                        Index = 0,
                        ContentType = (int)ContentType.LeadImage
                    };
                    await service.Add(entity);
                }
            }

            if (!skipCleaning)
                await service.DeleteAllById<ContentEntity>(oldLeadImages.Select(d => d.Id));
        }
Example #4
0
        public static async Task SaveFeed(FeedModel model, List<ArticleModel> newArticles, ISqliteService service, IImageDownloadService imageDownloadService)
        {
            var stringGuid = model.Guid.ToString();
            var feedEntries = await service.GetByCondition<FeedArticleRelationEntity>(d => d.FeedGuid == stringGuid, null, false, 0, 0);
            var oldArticles = new List<ArticleModel>(model.AllArticles);


            for (int index = 0; index < newArticles.Count; index++)
            {
                var articleModel = newArticles[index];
                articleModel.Feed = model;

                var oldOne = oldArticles.FirstOrDefault(s => s.PublicUri == articleModel.PublicUri);
                if (oldOne == null)
                {
                    var oldFromDatabase = feedEntries.FirstOrDefault(s => articleModel.PublicUri == s.Url);
                    if (oldFromDatabase != null)
                    {
                        var article = await LoadHelper.LoadForFeed(oldFromDatabase.ArticleId, model, service, imageDownloadService);
                        feedEntries.Remove(oldFromDatabase);
                        oldFromDatabase.Index = index;
                        await service.Update(oldFromDatabase);

                        if (model.AllArticles.Count > index)
                            model.AllArticles[index] = article;
                        else
                            model.AllArticles.Add(article);
                    }
                    else
                    {
                        await SaveArticle(articleModel, service);
                        await SaveArticleLeadImage(articleModel, service, true);
                        await SaveArticleContent(articleModel, service, true);

                        var fe = new FeedArticleRelationEntity()
                        {
                            ArticleId = articleModel.GetId(),
                            Url = articleModel.PublicUri,
                            FeedGuid = model.Guid.ToString(),
                            Index = index
                        };
                        await service.Add(fe);

                        if (model.AllArticles.Count > index)
                            model.AllArticles[index] = articleModel;
                        else
                            model.AllArticles.Add(articleModel);
                    }
                }
                else
                {
                    if (model.AllArticles.Count > index)
                        model.AllArticles[index] = oldOne;
                    else
                        model.AllArticles.Add(oldOne);

                    var oldFromDatabase = feedEntries.FirstOrDefault(s => articleModel.PublicUri == s.Url);
                    if (oldFromDatabase != null)
                    {
                        oldFromDatabase.Index = index;
                        await service.Update(oldFromDatabase);
                    }
                    else
                    {
                        var fe = new FeedArticleRelationEntity()
                        {
                            ArticleId = oldOne.GetId(),
                            Url = oldOne.PublicUri,
                            FeedGuid = model.Guid.ToString(),
                            Index = index
                        };
                        await service.Add(fe);
                    }
                }
            }

            await service.DeleteAllById<FeedArticleRelationEntity>(feedEntries.Select(s => s.Id));
        }
Example #5
0
        public static async Task SaveFeed(FeedModel model, List <ArticleModel> newArticles, ISqliteService service, IImageDownloadService imageDownloadService)
        {
            var stringGuid  = model.Guid.ToString();
            var feedEntries = await service.GetByCondition <FeedArticleRelationEntity>(d => d.FeedGuid == stringGuid, null, false, 0, 0);

            var oldArticles = new List <ArticleModel>(model.AllArticles);


            for (int index = 0; index < newArticles.Count; index++)
            {
                var articleModel = newArticles[index];
                articleModel.Feed = model;

                var oldOne = oldArticles.FirstOrDefault(s => s.PublicUri == articleModel.PublicUri);
                if (oldOne == null)
                {
                    var oldFromDatabase = feedEntries.FirstOrDefault(s => articleModel.PublicUri == s.Url);
                    if (oldFromDatabase != null)
                    {
                        var article = await LoadHelper.LoadForFeed(oldFromDatabase.ArticleId, model, service, imageDownloadService);

                        feedEntries.Remove(oldFromDatabase);
                        oldFromDatabase.Index = index;
                        await service.Update(oldFromDatabase);

                        if (model.AllArticles.Count > index)
                        {
                            model.AllArticles[index] = article;
                        }
                        else
                        {
                            model.AllArticles.Add(article);
                        }
                    }
                    else
                    {
                        await SaveArticle(articleModel, service);
                        await SaveArticleLeadImage(articleModel, service, true);
                        await SaveArticleContent(articleModel, service, true);

                        var fe = new FeedArticleRelationEntity()
                        {
                            ArticleId = articleModel.GetId(),
                            Url       = articleModel.PublicUri,
                            FeedGuid  = model.Guid.ToString(),
                            Index     = index
                        };
                        await service.Add(fe);

                        if (model.AllArticles.Count > index)
                        {
                            model.AllArticles[index] = articleModel;
                        }
                        else
                        {
                            model.AllArticles.Add(articleModel);
                        }
                    }
                }
                else
                {
                    if (model.AllArticles.Count > index)
                    {
                        model.AllArticles[index] = oldOne;
                    }
                    else
                    {
                        model.AllArticles.Add(oldOne);
                    }

                    var oldFromDatabase = feedEntries.FirstOrDefault(s => articleModel.PublicUri == s.Url);
                    if (oldFromDatabase != null)
                    {
                        oldFromDatabase.Index = index;
                        await service.Update(oldFromDatabase);
                    }
                    else
                    {
                        var fe = new FeedArticleRelationEntity()
                        {
                            ArticleId = oldOne.GetId(),
                            Url       = oldOne.PublicUri,
                            FeedGuid  = model.Guid.ToString(),
                            Index     = index
                        };
                        await service.Add(fe);
                    }
                }
            }

            await service.DeleteAllById <FeedArticleRelationEntity>(feedEntries.Select(s => s.Id));
        }