Пример #1
0
        private Task <int> RemoveTagRangeFromArticle(List <ArticleTag> tagsToRemove, int articleId)
        {
            var listOfaATags = _context.ArticleArticleTags
                               .Join(tagsToRemove, a => a.ArticleTagId, t => t.ArticleTagId, (a, t) => a)
                               .Where(c => c.ArticleId == articleId)
                               .ToList();

            _context.ArticleArticleTags.RemoveRange(listOfaATags);

            return(_context.SaveChangesAsync());
        }
        protected override Task Handle(CreateArticleTagsCommand request, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(request.ArticleTags))
            {
                return(Task.FromResult(0));
            }

            var newTags      = request.ArticleTags.Split(',').Select(t => t.Trim()).ToList();
            var existingTags = _context.ArticleTags.ToList().Select(t => t.ArticleTagName.Trim());
            var tagsToAdd    = newTags.Except(existingTags);

            var articleTags = tagsToAdd.Select(t => new ArticleTag {
                ArticleTagName = t
            }).ToList();

            _context.ArticleTags.AddRange(articleTags);

            var articleArticleTags = articleTags.Select(a => new ArticleArticleTag {
                Article = request.Article, ArticleTag = a
            });

            _context.ArticleArticleTags.AddRange(articleArticleTags);

            return(_context.SaveChangesAsync(cancellationToken));
        }
Пример #3
0
        public async Task <int> UpdateUserProfileAsync(ApplicationUser user)
        {
            var model = await _context.Users.SingleAsync(u => u.Id.Equals(user.Id));

            model.UserAddress         = user.UserAddress;
            model.UserProfileEmail    = user.UserProfileEmail;
            model.UserPhoneNumber     = user.UserPhoneNumber;
            model.UserAvatar          = user.UserAvatar ?? model.UserAvatar;
            model.UserBio             = user.UserBio;
            model.UserDateOfBirth     = user.UserDateOfBirth;
            model.UserFacebookProfile = user.UserFacebookProfile;
            model.UserFavourites      = user.UserFavourites;
            model.UserFullName        = user.UserFullName;
            model.UserGender          = user.UserGender;
            model.UserGoogleProfile   = user.UserGoogleProfile;
            model.UserHowFindUs       = user.UserHowFindUs;
            model.UserLinkedInProfile = user.UserLinkedInProfile;
            model.UserOccupation      = user.UserOccupation;
            model.UserSpeciality      = user.UserSpeciality;
            model.UserTwitterProfile  = user.UserTwitterProfile;
            model.UserWebSite         = user.UserWebSite;


            return(await _context.SaveChangesAsync());
        }
        protected override async Task Handle(IncreaseArticleViewCountCommand request, CancellationToken cancellationToken)
        {
            var article = await _context.Articles.SingleAsync(a => a.ArticleId == request.ArticleId);

            article.ArticleViewCount += 1;

            await _context.SaveChangesAsync(cancellationToken);
        }
Пример #5
0
        protected override Task Handle(UpdateUserProfileCommand request, CancellationToken cancellationToken)
        {
            var model = _context.Users.AsNoTracking().Single(u => u.Id == request.ApplicationUser.Id);

            request.ApplicationUser.ConcurrencyStamp      = model.ConcurrencyStamp;
            _context.Entry(request.ApplicationUser).State = EntityState.Modified;
            return(_context.SaveChangesAsync(cancellationToken));
        }
        protected override Task Handle(UpdateArticleRatingCommand request, CancellationToken cancellationToken)
        {
            var articleRating = _context.ArticleRatings.Single(a =>
                                                               a.ArticleIDfk == request.ArticleId &&
                                                               a.UserIDfk == _userManager.GetUserId(request.User));

            articleRating.ArticleRatingScore = request.ArticleRating;

            return(_context.SaveChangesAsync(cancellationToken));
        }
        protected override Task Handle(CreateArticleCommand message, CancellationToken cancellationToken)
        {
            message.Article.ArticleDateCreated = DateTime.Now;
            message.Article.ArticleViewCount   = 1;
            message.Article.UserIDfk           = _userManager.GetUserId(_contextAccessor.HttpContext.User);

            _context.Articles.Add(message.Article);

            return(_context.SaveChangesAsync(cancellationToken));
        }
        protected override Task Handle(AddRatingToArticleCommand request, CancellationToken cancellationToken)
        {
            var articleRating = new ArticleRating {
                ArticleIDfk = request.ArticleId, ArticleRatingScore = request.ArticleRating, UserIDfk = _userManager.GetUserId(request.User)
            };

            _context.ArticleRatings.Add(articleRating);

            return(_context.SaveChangesAsync(cancellationToken));
        }
        protected override Task Handle(UpdatePortfolioCommand request, CancellationToken cancellationToken)
        {
            _context.Portfolios.Attach(request.Portfolio);

            var entity = _context.Entry(request.Portfolio);

            entity.State = EntityState.Modified;

            entity.Property(e => e.PortfolioDateCreated).IsModified = false;
            entity.Property(e => e.PortfolioThumbnail).IsModified   = request.Portfolio.PortfolioThumbnail != null;

            return(_context.SaveChangesAsync(cancellationToken));
        }
        protected override Task Handle(UpdateSlideShowCommand message, CancellationToken cancellationToken)
        {
            _context.SlideShows.Attach(message.SlideShow);

            var entity = _context.Entry(message.SlideShow);

            entity.State = EntityState.Modified;

            entity.Property(e => e.SlideShowDateCreated).IsModified = false;
            entity.Property(e => e.SlideShowPictrure).IsModified    = message.SlideShow.SlideShowPictrure != null;

            return(_context.SaveChangesAsync(cancellationToken));
        }
Пример #11
0
        protected override Task Handle(UpdateArticleCommand request, CancellationToken cancellationToken)
        {
            _context.Articles.Attach(request.Article);

            request.Article.ArticleDateModified = DateTime.Now;

            var entity = _context.Entry(request.Article);

            entity.State = EntityState.Modified;

            entity.Property(e => e.ArticleDateCreated).IsModified = false;
            entity.Property(e => e.ArticleId).IsModified          = false;
            entity.Property(e => e.ArticleViewCount).IsModified   = false;
            entity.Property(e => e.UserIDfk).IsModified           = false;

            return(_context.SaveChangesAsync(cancellationToken));
        }
        public Task <int> AddNewSlideShow(SlideShow slideShow)
        {
            _context.SlideShows.Add(slideShow);

            return(_context.SaveChangesAsync());
        }
        protected override Task Handle(AddSiteOrderCommand request, CancellationToken cancellationToken)
        {
            _context.SiteOrders.Add(request.SiteOrder);

            return(_context.SaveChangesAsync(cancellationToken));
        }
Пример #14
0
        protected override Task Handle(DeleteSlideShowCommand message, CancellationToken cancellationToken)
        {
            _context.SlideShows.Remove(message.SlideShow);

            return(_context.SaveChangesAsync(cancellationToken));
        }
 protected override async Task Handle(DeleteContactCommand message, CancellationToken cancellationToken)
 {
     _context.Contacts.Remove(message.Contact);
     await _context.SaveChangesAsync(cancellationToken);
 }
        public Task <int> AddSiteOrderAsync(SiteOrder siteOrder)
        {
            _context.SiteOrders.Add(siteOrder);

            return(_context.SaveChangesAsync());
        }
Пример #17
0
        protected override Task Handle(ToggleArticleCommentApprovalCommand request, CancellationToken cancellationToken)
        {
            request.ArticleComment.IsCommentApproved = !request.ArticleComment.IsCommentApproved;

            return(_context.SaveChangesAsync(cancellationToken));
        }
Пример #18
0
 public Task <int> SaveAsync()
 {
     return(_context.SaveChangesAsync());
 }
 protected override Task Handle(EditArticleCommentCommand request, CancellationToken cancellationToken)
 {
     request.ArticleComment.ArticleCommentBody = request.NewCommentBody;
     return(_context.SaveChangesAsync(cancellationToken));
 }
 public Task <int> DeleteArticleAsync(Article article)
 {
     _context.Articles.Remove(article);
     return(_context.SaveChangesAsync());
 }
Пример #21
0
 protected override Task Handle(AddNewPortfolioCommand request, CancellationToken cancellationToken)
 {
     _context.Portfolios.Add(request.Portfolio);
     return(_context.SaveChangesAsync(cancellationToken));
 }
 protected override Task Handle(AddNewSlideShowCommand request, CancellationToken cancellationToken)
 {
     _context.SlideShows.Add(request.SlideShow);
     return(_context.SaveChangesAsync(cancellationToken));
 }
Пример #23
0
 protected override Task Handle(EditArticleTagCommand message, CancellationToken cancellationToken)
 {
     message.ArticleTag.ArticleTagName = message.NewTagName;
     return(_context.SaveChangesAsync(cancellationToken));
 }
Пример #24
0
        protected override Task Handle(AddCommentToArticleCommand request, CancellationToken cancellationToken)
        {
            _context.ArticleComments.Add(request.ArticleComment);

            return(_context.SaveChangesAsync(cancellationToken));
        }
Пример #25
0
 protected override async Task Handle(DeleteArticleCommand request, CancellationToken cancellationToken)
 {
     _context.Articles.Remove(request.Article);
     await _context.SaveChangesAsync(cancellationToken);
 }
 public Task <int> AddNewContactAsync(Contact contact)
 {
     _context.Contacts.Add(contact);
     return(_context.SaveChangesAsync());
 }
 protected override Task Handle(DeleteArticleCommentCommand request, CancellationToken cancellationToken)
 {
     _context.ArticleComments.Remove(request.ArticleComment);
     return(_context.SaveChangesAsync(cancellationToken));
 }
Пример #28
0
 public Task <int> AddNewPortfolio(Portfolio portfolio)
 {
     _context.Portfolios.Add(portfolio);
     return(_context.SaveChangesAsync());
 }