Exemplo n.º 1
0
        public async Task <FeaturedChallengeGroup> EditFeaturedGroupAsync(
            FeaturedChallengeGroup group,
            FeaturedChallengeGroupText text)
        {
            VerifyPermission(Permission.ManageFeaturedChallengeGroups);

            var featuredGroup = await _featuredChallengeGroupRepository.GetByIdAsync(group.Id);

            featuredGroup.ChallengeGroupId = group.ChallengeGroupId;
            featuredGroup.EndDate          = group.EndDate;
            featuredGroup.Name             = group.Name?.Trim();
            featuredGroup.StartDate        = group.StartDate;

            var defaultLanguageId = await _languageService.GetDefaultLanguageIdAsync();

            var groupText = await _featuredChallengeGroupRepository
                            .GetTextByFeaturedGroupAndLanguageAsync(featuredGroup.Id, defaultLanguageId);

            groupText.AltText = text.AltText?.Trim();

            await _featuredChallengeGroupRepository.UpdateAsync(GetClaimId(ClaimType.UserId),
                                                                featuredGroup);

            await _featuredChallengeGroupRepository.UpdateTextAsync(groupText,
                                                                    featuredGroup.Id,
                                                                    defaultLanguageId);

            await _featuredChallengeGroupRepository.SaveAsync();

            await ClearFeaturedChallengeGroupsCacheAsync();

            return(featuredGroup);
        }
        public async Task AddTextAsync(FeaturedChallengeGroupText text,
                                       int featuredGroupId,
                                       int languageId)
        {
            var textEntity = _mapper
                             .Map <FeaturedChallengeGroupText, Model.FeaturedChallengeGroupText>(text);

            textEntity.FeaturedChallengeGroupId = featuredGroupId;
            textEntity.LanguageId = languageId;

            await _context.FeaturedChallengeGroupTexts.AddAsync(textEntity);
        }
        public async Task UpdateTextAsync(FeaturedChallengeGroupText text,
                                          int featuredGroupId,
                                          int languageId)
        {
            var textEntity = await _context.FeaturedChallengeGroupTexts
                             .AsNoTracking()
                             .Where(_ => _.FeaturedChallengeGroupId == featuredGroupId &&
                                    _.LanguageId == languageId)
                             .SingleOrDefaultAsync();

            textEntity.AltText  = text.AltText;
            textEntity.Filename = text.Filename;

            _context.FeaturedChallengeGroupTexts.Update(textEntity);
        }
Exemplo n.º 4
0
        public async Task <FeaturedChallengeGroup> AddFeaturedGroupAsync(
            FeaturedChallengeGroup featuredGroup,
            FeaturedChallengeGroupText featuredGroupText,
            string filename,
            byte[] imageBytes)
        {
            VerifyPermission(Permission.ManageFeaturedChallengeGroups);

            var siteId = GetCurrentSiteId();

            featuredGroup.Name   = featuredGroup.Name?.Trim();
            featuredGroup.SiteId = siteId;

            var maxSortOrder = await _featuredChallengeGroupRepository.GetMaxSortOrderAsync(siteId);

            if (maxSortOrder.HasValue)
            {
                featuredGroup.SortOrder = maxSortOrder.Value + 1;
            }

            var addedFeaturedGroup = await _featuredChallengeGroupRepository.AddSaveAsync(
                GetClaimId(ClaimType.UserId),
                featuredGroup);

            featuredGroupText.AltText  = featuredGroupText.AltText?.Trim();
            featuredGroupText.Filename = (await HandleFeaturedImage(filename, imageBytes))?.Trim();

            await _featuredChallengeGroupRepository.AddTextAsync(featuredGroupText,
                                                                 addedFeaturedGroup.Id,
                                                                 await _languageService.GetDefaultLanguageIdAsync());

            await _featuredChallengeGroupRepository.SaveAsync();

            await ClearFeaturedChallengeGroupsCacheAsync();

            return(addedFeaturedGroup);
        }