Exemplo n.º 1
0
        public async Task UpdateImageAsync(DailyLiteracyTipImage image)
        {
            VerifyManagementPermission();
            var authId       = GetClaimId(ClaimType.UserId);
            var siteId       = GetCurrentSiteId();
            var currentImage = await _dailyLiteracyTipImageRepository.GetByIdAsync(image.Id);

            if (currentImage.DailyLiteracyTip.SiteId != siteId)
            {
                _logger.LogError($"User {authId} cannot update daily image {currentImage.Id} for site {currentImage.DailyLiteracyTip.SiteId}.");
                throw new GraException($"Permission denied - daily literacy tip image belongs to site id {currentImage.DailyLiteracyTip.SiteId}");
            }

            currentImage.Name      = image.Name;
            currentImage.Extension = image.Extension;

            if (image.Day != currentImage.Day)
            {
                await _dailyLiteracyTipImageRepository.UpdateSaveAsync(authId, currentImage,
                                                                       image.Day);
            }
            else
            {
                await _dailyLiteracyTipImageRepository.UpdateSaveAsync(authId, currentImage);
            }
        }
Exemplo n.º 2
0
        public async Task <DailyLiteracyTipImage> AddImageAsync(DailyLiteracyTipImage image)
        {
            VerifyManagementPermission();
            var filter = new DailyImageFilter()
            {
                DailyLiteracyTipId = image.DailyLiteracyTipId
            };

            image.Day = await _dailyLiteracyTipImageRepository.CountAsync(filter);

            return(await _dailyLiteracyTipImageRepository.AddSaveAsync(GetClaimId(ClaimType.UserId),
                                                                       image));
        }
Exemplo n.º 3
0
        public async Task <DailyLiteracyTipImage> AddImageAsync(DailyLiteracyTipImage image)
        {
            VerifyManagementPermission();
            if (image == null)
            {
                throw new GraException("Unable to add empty image.");
            }
            var filter = new DailyImageFilter()
            {
                DailyLiteracyTipId = image.DailyLiteracyTipId
            };

            image.Day = await _dailyLiteracyTipImageRepository.CountAsync(filter);

            return(await _dailyLiteracyTipImageRepository.AddSaveAsync(GetClaimId(ClaimType.UserId),
                                                                       image));
        }